forked from SteamWar/SteamWar
Initial copy from other repository (nothing is fixed here)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.hamcrest)
|
||||
|
||||
testImplementation(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar;
|
||||
|
||||
import de.steamwar.command.CommandFrameworkException;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestCommand;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@UtilityClass
|
||||
public class AssertionUtils {
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class SimpleAssertion<T extends TestCommand> {
|
||||
|
||||
private T value;
|
||||
|
||||
public SimpleAssertion<T> assertNoInitialize(String message) {
|
||||
try {
|
||||
value.initialize();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
if (e.getCause() == null) {
|
||||
assertThat(e.getMessage(), is(message));
|
||||
} else {
|
||||
assertThat(e.getCause(), instanceOf(UnsupportedOperationException.class));
|
||||
assertThat(e.getCause().getMessage(), is(message));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
error(value.getClass().getSimpleName() + " had an unexpected error while initializing");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleAssertion<T> assertExecute(String message, String... arguments) {
|
||||
try {
|
||||
value.execute("", "", arguments);
|
||||
error(value.getClass().getSimpleName() + " was not parsed.");
|
||||
} catch (Exception e) {
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleAssertion<T> assertNoExecute(String... arguments) {
|
||||
try {
|
||||
value.execute("", "", arguments);
|
||||
} catch (Exception e) {
|
||||
error(value.getClass().getSimpleName() + " was parsed. It should not have been.", e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleAssertion<T> assertTabCompletion(String[] expectedTabCompletions, String... arguments) {
|
||||
return assertTabCompletion("", expectedTabCompletions, arguments);
|
||||
}
|
||||
|
||||
public SimpleAssertion<T> assertTabCompletion(String sender, String[] expectedTabCompletions, String... arguments) {
|
||||
try {
|
||||
List<String> tabCompletions = value.tabComplete(sender, "", arguments);
|
||||
assertTabCompletes(tabCompletions, expectedTabCompletions);
|
||||
} catch (Exception e) {
|
||||
error(value.getClass().getSimpleName() + " tab-completion failed.", e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleAssertion<TestCommand> with(Object... commandObjects) {
|
||||
return new SimpleAssertion<>(new TestCommand(stringCommandLoader -> {
|
||||
for (Object commandObject : commandObjects) {
|
||||
stringCommandLoader.add(commandObject);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
throw new AssertionError(message);
|
||||
}
|
||||
|
||||
public static void error(String message, Throwable cause) {
|
||||
throw new AssertionError(message, cause);
|
||||
}
|
||||
|
||||
public static void assertCMDFramework(Exception e, Class<?> clazz, String message) {
|
||||
if (clazz.isInstance(e)) {
|
||||
assertThat(e.getMessage(), is(message));
|
||||
} else {
|
||||
assertThat(e, is(instanceOf(CommandFrameworkException.class)));
|
||||
assertThat(e.getCause().getCause(), is(instanceOf(clazz)));
|
||||
assertThat(e.getCause().getCause().getMessage(), is(message));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void assertTabCompletes(List<T> list, T... elements) {
|
||||
assertThat(Arrays.asList(elements) + " -> " + list, list.size(), is(elements.length));
|
||||
if (elements.length > 0) {
|
||||
assertThat(list, containsInAnyOrder(elements));
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.impl;
|
||||
|
||||
public class ExecutionIdentifier extends RuntimeException {
|
||||
public ExecutionIdentifier(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.impl;
|
||||
|
||||
import de.steamwar.command.AbstractCommand;
|
||||
import de.steamwar.command.CommandFrameworkException;
|
||||
import de.steamwar.command.CommandLoader;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TestCommand extends AbstractCommand<String> {
|
||||
|
||||
static {
|
||||
addExecutorMapper(TestCommand.class, String.class, Function.identity());
|
||||
}
|
||||
|
||||
public TestCommand(Consumer<CommandLoader<String>> initializer) {
|
||||
super("", initializer);
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
try {
|
||||
Method method = AbstractCommand.class.getDeclaredMethod("initialize");
|
||||
method.setAccessible(true);
|
||||
method.invoke(this);
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
throw new SecurityException(e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable throwable = e.getTargetException();
|
||||
if (throwable instanceof RuntimeException) {
|
||||
throw (RuntimeException) throwable;
|
||||
} else {
|
||||
throw new SecurityException(throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String sender, String message, Object[] args) {
|
||||
throw new ExecutionIdentifier(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void commandSystemError(String sender, CommandFrameworkException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.impl;
|
||||
|
||||
import de.steamwar.command.AbstractTypeMapper;
|
||||
|
||||
public interface TestTypeMapper<T> extends AbstractTypeMapper<String, T> {
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.impl;
|
||||
|
||||
import de.steamwar.command.AbstractTypeSupplier;
|
||||
|
||||
public interface TestTypeSupplier<T> extends AbstractTypeSupplier<String, T> {
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.impl;
|
||||
|
||||
import de.steamwar.command.AbstractTypeValidator;
|
||||
|
||||
public interface TestTypeValidator<T> extends AbstractTypeValidator<String, T> {
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.allownull;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.AllowNull;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AllowNullTest {
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @AllowNull Integer value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @AllowNull int value) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("null", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoInitialize("AllowNull annotation cannot be used on primitive types");
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3) int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3, error = "Specify at most 3 argument") int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "b");
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMinMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3) int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3, error = "Specify at least 1 argument") int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("0", "a")
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("0", "b")
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "b");
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMinTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1) int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, error = "Specify at least 1 argument") int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("0", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("0", "b");
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3) int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3, error = "Specify at most 3 argument") int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "b");
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMinMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3) int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3, error = "Specify at least 1 argument") int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("0", "a")
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("0", "b")
|
||||
.assertNoExecute("0", "1", "2", "3")
|
||||
.assertNoExecute("0", "1", "2", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "0", "1")
|
||||
.assertTabCompletion(new String[]{"2", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"}, "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "3")
|
||||
.assertTabCompletion(new String[]{}, "0", "1", "2", "b");
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.number;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMinTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1) int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, error = "Specify at least 1 argument") int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("0", "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("0", "b");
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3) String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3, error = "Specify at most 3 argument") String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMinMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3) String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3, error = "Specify at least 1 argument") String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyMinTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1) String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, error = "Specify at least 1 argument") String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument");
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3) String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(max = 3, error = "Specify at most 3 argument") String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[]")
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMinMaxTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3) String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, max = 3, error = "Specify at least 1 argument") String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument")
|
||||
.assertNoExecute("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{})
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"b"}, "a", "b")
|
||||
.assertTabCompletion(new String[]{"c"}, "a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{}, "a", "b", "c", "d");
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.arraylength.string;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyMinTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1) String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ArrayLength(min = 1, error = "Specify at least 1 argument") String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("[a]", "a")
|
||||
.assertExecute("[a, b]", "a", "b")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Specify at least 1 argument");
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.cached;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Cached;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class CacheKeyTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("cacheKey") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper("cacheKey")
|
||||
@Cached(global = true)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Arrays.asList("Hello", "Hallo", "Hugo", "Help", "World", "Welt", "Welp", s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String normalize(String sender, String s) {
|
||||
if (s.isEmpty()) return null;
|
||||
return s.substring(0, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheKey() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"Hello", "Hallo", "Hugo", "Help", "H"}, "H")
|
||||
.assertTabCompletion(new String[]{"Hello", "Help", "H"}, "He")
|
||||
.assertTabCompletion(new String[]{"World", "Welt", "Welp", "W"}, "W")
|
||||
.assertTabCompletion(new String[]{"Welt", "Welp", "W"}, "We")
|
||||
.assertTabCompletion(new String[]{"Hello", "Hallo", "Hugo", "Help", "World", "Welt", "Welp"}, "");
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.cached;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Cached;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DurationTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("cachedDuration") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper("cachedDuration")
|
||||
@Cached(cacheDuration = 100, timeUnit = TimeUnit.MILLISECONDS)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("java:S2925")
|
||||
public void testDuration() {
|
||||
AssertionUtils.with(new SenderSpecificTest.Command())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hel");
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
AssertionUtils.with(new SenderSpecificTest.Command())
|
||||
.assertTabCompletion(new String[]{"World"}, "World")
|
||||
.assertTabCompletion(new String[]{"World"}, "Wor");
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.cached;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Cached;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GlobalTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("cachedGlobal") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper("cachedGlobal")
|
||||
@Cached(global = true)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCached() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hel");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentSenders() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion("a", new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion("a", new String[]{"Hello"}, "Hel")
|
||||
.assertTabCompletion("b", new String[]{"Hello"}, "Hel")
|
||||
.assertTabCompletion("b", new String[]{"Hello"}, "H");
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.cached;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Cached;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class SenderSpecificTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("cachedSenderSpecific") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper("cachedSenderSpecific")
|
||||
@Cached
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCached() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hel");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentSenders() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion("a", new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion("a", new String[]{"Hello"}, "Hel")
|
||||
.assertTabCompletion("b", new String[]{"Hel"}, "Hel")
|
||||
.assertTabCompletion("b", new String[]{"Hel"}, "H");
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.classmapper;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.ClassMapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@Deprecated
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@ClassMapper(value = BigInteger.class, local = false)
|
||||
public TestTypeMapper<BigInteger> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigInteger map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigInteger(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalMapper() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("0", "0");
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.classmapper;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.ClassMapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@Deprecated
|
||||
public class LocalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@ClassMapper(String.class)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigDecimal b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
|
||||
@ClassMapper(value = BigDecimal.class)
|
||||
public TestTypeMapper<BigDecimal> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigDecimal map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigDecimal(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class ThirdCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigDecimal b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapper() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertExecute("#Hello", "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapperOutside() {
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("0", "0");
|
||||
AssertionUtils.with(new ThirdCommand())
|
||||
.assertNoInitialize("Register method parameter arg1 must be annotated or have a type mapper");
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.classmapper;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.ClassMapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@Deprecated
|
||||
public class OverrideTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@ClassMapper(value = String.class, local = false)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideMapper() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello", "Hello");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.classvalidator;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ClassValidator;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@Deprecated
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@ClassValidator(value = BigInteger.class, local = false)
|
||||
public TestTypeValidator<BigInteger> globalValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoExecute("0");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.classvalidator;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ClassValidator;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@Deprecated
|
||||
public class LocalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@ClassValidator(BigInteger.class)
|
||||
public TestTypeValidator<BigInteger> localValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoInitialize("Validator '' not found");
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.endswith;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.EndsWith;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EndsWithTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @EndsWith("Hello") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @EndsWith(value = "Hello", error = "Hello must be the suffix") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("TestHello", "TestHello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("Test")
|
||||
.assertNoExecute("Hugo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"TestHello"}, "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("TestHello", "TestHello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Hello must be the suffix", "Test")
|
||||
.assertExecute("Hello must be the suffix", "Hugo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"TestHello"}, "Test");
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.errormessage;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ErrorMessage;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Deprecated
|
||||
public class AllowEASTest {
|
||||
|
||||
public static class GreedyCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ErrorMessage(value = "Empty array", allowEAs = false) String... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonGreedyCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ErrorMessage(value = "Empty array", allowEAs = false) String[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteGreedy() {
|
||||
AssertionUtils.with(new GreedyCommand())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("Empty array");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteNonGreedy() {
|
||||
AssertionUtils.with(new NonGreedyCommand())
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("Empty array");
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.errormessage;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ErrorMessage;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ErrorMessageTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @ErrorMessage("No Number") int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("No Number", "a");
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.greedy;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Greedy;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BackTrackingDepthTest {
|
||||
|
||||
public static class CommandDepth1 {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Greedy(backTrackingDepth = 1) int[] args_1, @ArrayLength(min = 2) int[] args_2) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args_1) + " " + Arrays.toString(args_2));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandDepth2 {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Greedy(backTrackingDepth = 2) int[] args_1, @ArrayLength(min = 2) int[] args_2) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args_1) + " " + Arrays.toString(args_2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDepth1NoExecute() {
|
||||
AssertionUtils.with(new CommandDepth1())
|
||||
.assertNoExecute("0")
|
||||
.assertNoExecute()
|
||||
.assertNoExecute("0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDepth2Execute() {
|
||||
AssertionUtils.with(new CommandDepth2())
|
||||
.assertExecute("[0, 1] [2, 3]", "0", "1", "2", "3")
|
||||
.assertExecute("[0, 1, 2] [3, 4]", "0", "1", "2", "3", "4")
|
||||
.assertExecute("[] [0, 1]", "0", "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDepth2NoExecute() {
|
||||
AssertionUtils.with(new CommandDepth2())
|
||||
.assertNoExecute("0")
|
||||
.assertNoExecute();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.greedy;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.ArrayLength;
|
||||
import de.steamwar.command.annotations.Greedy;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BackTrackingTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Greedy int[] args_1, @ArrayLength(min = 2) int[] args_2) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args_1) + " " + Arrays.toString(args_2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1] [2, 3]", "0", "1", "2", "3")
|
||||
.assertExecute("[0, 1, 2] [3, 4]", "0", "1", "2", "3", "4")
|
||||
.assertExecute("[] [0, 1]", "0", "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0")
|
||||
.assertNoExecute();
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.greedy;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Greedy;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Greedy int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0", "1", "b")
|
||||
.assertNoExecute("0", "b")
|
||||
.assertNoExecute("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "0", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "0", "b")
|
||||
.assertTabCompletion(new String[]{}, "b", "0", "");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.length;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Length;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MaxTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Length(max = 3) String string) {
|
||||
throw new ExecutionIdentifier(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("He", "He")
|
||||
.assertExecute("H", "H")
|
||||
.assertExecute("", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("Hello")
|
||||
.assertNoExecute("World")
|
||||
.assertNoExecute("This")
|
||||
.assertNoExecute("Works");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "")
|
||||
.assertTabCompletion(new String[]{"Hel"}, "Hello");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.length;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Length;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MinMaxTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Length(min = 3, max = 5) String string) {
|
||||
throw new ExecutionIdentifier(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hel", "Hel")
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("Hugo", "Hugo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("He")
|
||||
.assertNoExecute("HelloWorld")
|
||||
.assertNoExecute("ThisWorks");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "HelloWorld");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.length;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Length;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MinTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Length(min = 3) String string) {
|
||||
throw new ExecutionIdentifier(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("World", "World")
|
||||
.assertExecute("This", "This")
|
||||
.assertExecute("Works", "Works");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("He")
|
||||
.assertNoExecute("H")
|
||||
.assertNoExecute("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello");
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.type;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Mapper(type = BigInteger.class, local = false)
|
||||
public TestTypeMapper<BigInteger> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigInteger map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigInteger(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalMapper() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("0", "0");
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.type;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class LocalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper(type = String.class)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigDecimal b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
|
||||
@Mapper(type = BigDecimal.class)
|
||||
public TestTypeMapper<BigDecimal> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigDecimal map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigDecimal(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class ThirdCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, BigDecimal b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapper() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertExecute("#Hello", "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapperOutside() {
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("0", "0");
|
||||
AssertionUtils.with(new ThirdCommand())
|
||||
.assertNoInitialize("Register method parameter arg1 must be annotated or have a type mapper");
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.type;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class OverrideTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper(type = String.class, local = false)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideMapper() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello", "Hello");
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Mapper(value = "globalMapper", local = false)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("globalMapper") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalMapper() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("#Test", "Test");
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class LocalTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("localMapper") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper("localMapper")
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("bigInteger") BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
|
||||
@Mapper("bigInteger")
|
||||
public TestTypeMapper<BigInteger> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigInteger map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigInteger(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class ThirdCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Mapper("bigInteger") BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapper() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("#Hello", "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalMapperOutside() {
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertExecute("0", "0");
|
||||
AssertionUtils.with(new ThirdCommand())
|
||||
.assertNoInitialize("Mapper 'bigInteger' not found");
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.mapper.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class OverrideTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
|
||||
@Mapper(value = "java.lang.String", local = false)
|
||||
public TestTypeMapper<String> typeMapper() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public String map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return "#" + s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideMapper() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello", "Hello");
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.max.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(doubleValue = 10.2) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(doubleValue = 10.2, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(doubleValue = 10.2, error = "Bigger than Max") double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.0", "10")
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("9.0", "9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("10.3")
|
||||
.assertNoExecute("100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("9.0", "9")
|
||||
.assertExecute("10.1", "10.1")
|
||||
.assertExecute("-1.0", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("10.0", "10")
|
||||
.assertExecute("9.0", "9")
|
||||
.assertExecute("-1.0", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Bigger than Max", "10.3")
|
||||
.assertExecute("Bigger than Max", "11")
|
||||
.assertExecute("Bigger than Max", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.max.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FloatTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(floatValue = 10.2f) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(floatValue = 10.2f, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(floatValue = 10.2f, error = "Bigger than Max") float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.0", "10")
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("9.0", "9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("10.3")
|
||||
.assertNoExecute("100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("9.0", "9")
|
||||
.assertExecute("10.1", "10.1")
|
||||
.assertExecute("-1.0", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("10.0", "10")
|
||||
.assertExecute("9.0", "9")
|
||||
.assertExecute("-1.0", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Bigger than Max", "10.3")
|
||||
.assertExecute("Bigger than Max", "11")
|
||||
.assertExecute("Bigger than Max", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.max.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(intValue = 10) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(intValue = 10, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(intValue = 10, error = "Bigger than Max") int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("9", "9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("9", "9")
|
||||
.assertExecute("-1", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("9", "9")
|
||||
.assertExecute("-1", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Bigger than Max", "11")
|
||||
.assertExecute("Bigger than Max", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.max.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(longValue = 10) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(longValue = 10, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Max(longValue = 10, error = "Bigger than Max") long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("9", "9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("9", "9")
|
||||
.assertExecute("-1", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("9", "9")
|
||||
.assertExecute("-1", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Bigger than Max", "11")
|
||||
.assertExecute("Bigger than Max", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "");
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.min.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2, error = "Smaller than Min") double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.min.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FloatTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f, error = "Smaller than Min") float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("19.0", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.min.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, error = "Smaller than Min") int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.min.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, error = "Smaller than Min") long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
}
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 18.8f23 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.minmax;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2) @Max(doubleValue = 18.8) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2, inclusive = false) @Max(doubleValue = 18.8) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2) @Max(doubleValue = 18.8, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2, inclusive = false) @Max(doubleValue = 18.8, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10.2, error = "Smaller than Min") @Max(doubleValue = 18.8, error = "Bigger than Max") double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10) @Max(doubleValue = 10) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive1Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10, inclusive = false) @Max(doubleValue = 10) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive2Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10) @Max(doubleValue = 10, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive3Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(doubleValue = 10, inclusive = false) @Max(doubleValue = 10, inclusive = false) double i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("21")
|
||||
.assertNoExecute("25")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10.2", "18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("21");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("15.2", "15.2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("15.0", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1")
|
||||
.assertExecute("Bigger than Max", "19")
|
||||
.assertExecute("Bigger than Max", "21")
|
||||
.assertExecute("Bigger than Max", "50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10.2", "18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertExecute("10.0", "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidNoExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive1() {
|
||||
AssertionUtils.with(new SameNonInclusive1Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive2() {
|
||||
AssertionUtils.with(new SameNonInclusive2Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive3() {
|
||||
AssertionUtils.with(new SameNonInclusive3Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
}
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 18.8f23 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.minmax;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FloatTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f) @Max(floatValue = 18.8f) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f, inclusive = false) @Max(floatValue = 18.8f) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f) @Max(floatValue = 18.8f, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f, inclusive = false) @Max(floatValue = 18.8f, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10.2f, error = "Smaller than Min") @Max(floatValue = 18.8f, error = "Bigger than Max") float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10) @Max(floatValue = 10) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive1Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10, inclusive = false) @Max(floatValue = 10) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive2Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10) @Max(floatValue = 10, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive3Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(floatValue = 10, inclusive = false) @Max(floatValue = 10, inclusive = false) float i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("21")
|
||||
.assertNoExecute("25")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10.2", "18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("21");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("15.2", "15.2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"10.2"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("15.0", "15");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("10.2")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("19")
|
||||
.assertNoExecute("18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10.2", "10.2")
|
||||
.assertExecute("11.0", "11")
|
||||
.assertExecute("18.8", "18.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1")
|
||||
.assertExecute("Bigger than Max", "19")
|
||||
.assertExecute("Bigger than Max", "21")
|
||||
.assertExecute("Bigger than Max", "50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10.2", "18.8"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertExecute("10.0", "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidNoExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive1() {
|
||||
AssertionUtils.with(new SameNonInclusive1Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive2() {
|
||||
AssertionUtils.with(new SameNonInclusive2Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive3() {
|
||||
AssertionUtils.with(new SameNonInclusive3Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
}
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.minmax;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10) @Max(intValue = 20) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, inclusive = false) @Max(intValue = 20) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10) @Max(intValue = 20, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, inclusive = false) @Max(intValue = 20, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, error = "Smaller than Min") @Max(intValue = 20, error = "Bigger than Max") int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10) @Max(intValue = 10) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive1Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, inclusive = false) @Max(intValue = 10) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive2Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10) @Max(intValue = 10, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive3Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(intValue = 10, inclusive = false) @Max(intValue = 10, inclusive = false) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("21")
|
||||
.assertNoExecute("25")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10", "20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("21");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1")
|
||||
.assertExecute("Bigger than Max", "21")
|
||||
.assertExecute("Bigger than Max", "50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10", "20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertExecute("10", "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidNoExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive1() {
|
||||
AssertionUtils.with(new SameNonInclusive1Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive2() {
|
||||
AssertionUtils.with(new SameNonInclusive2Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive3() {
|
||||
AssertionUtils.with(new SameNonInclusive3Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
}
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.minmax;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Max;
|
||||
import de.steamwar.command.annotations.Min;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongTest {
|
||||
|
||||
public static class BaseCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10) @Max(longValue = 20) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, inclusive = false) @Max(longValue = 20) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10) @Max(longValue = 20, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonInclusiveAndNonInclusiveCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, inclusive = false) @Max(longValue = 20, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorMessageCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, error = "Smaller than Min") @Max(longValue = 20, error = "Bigger than Max") long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameCommand {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10) @Max(longValue = 10) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive1Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, inclusive = false) @Max(longValue = 10) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive2Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10) @Max(longValue = 10, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class SameNonInclusive3Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Min(longValue = 10, inclusive = false) @Max(longValue = 10, inclusive = false) long i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueValidExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueNoExecute() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("21")
|
||||
.assertNoExecute("25")
|
||||
.assertNoExecute("-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValueTabComplete() {
|
||||
AssertionUtils.with(new BaseCommand())
|
||||
.assertTabCompletion(new String[]{"10", "20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("21");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new InclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{"10"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueValidExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueNoExecute() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute("-1")
|
||||
.assertNoExecute("20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInclusiveAndNonInclusiveValueTabComplete() {
|
||||
AssertionUtils.with(new NonInclusiveAndNonInclusiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueValidExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("10", "10")
|
||||
.assertExecute("11", "11")
|
||||
.assertExecute("19", "19")
|
||||
.assertExecute("20", "20");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueNoExecute() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertExecute("Smaller than Min", "9")
|
||||
.assertExecute("Smaller than Min", "-1")
|
||||
.assertExecute("Bigger than Max", "21")
|
||||
.assertExecute("Bigger than Max", "50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessageValueTabComplete() {
|
||||
AssertionUtils.with(new ErrorMessageCommand())
|
||||
.assertTabCompletion(new String[]{"10", "20"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertExecute("10", "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValidNoExecute() {
|
||||
AssertionUtils.with(new SameCommand())
|
||||
.assertNoExecute("9")
|
||||
.assertNoExecute("11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive1() {
|
||||
AssertionUtils.with(new SameNonInclusive1Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive2() {
|
||||
AssertionUtils.with(new SameNonInclusive2Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameNonInclusive3() {
|
||||
AssertionUtils.with(new SameNonInclusive3Command())
|
||||
.assertNoInitialize("Min and Max cannot be equal if not both are inclusive");
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.optionalvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.OptionalValue;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OnlyUseIfNoneIsGivenTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @OptionalValue(value = "0", onlyUINIG = true) int i, @OptionalValue(value = "true") boolean b) {
|
||||
throw new ExecutionIdentifier(i + " " + b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("1 false", "1", "false")
|
||||
.assertExecute("0 true")
|
||||
.assertExecute("10 false", "10", "false")
|
||||
.assertExecute("10 true", "10")
|
||||
.assertExecute("10 true", "10", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"true", "false"}, "0", "");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.optionalvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.OptionalValue;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OptionalValueTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @OptionalValue("0") int i, boolean b) {
|
||||
throw new ExecutionIdentifier(i + " " + b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("1 false", "1", "false")
|
||||
.assertExecute("0 false", "false")
|
||||
.assertExecute("10 false", "10", "false")
|
||||
.assertExecute("10 true", "10", "true")
|
||||
.assertExecute("0 true", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("10")
|
||||
.assertNoExecute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "true", "false"}, "")
|
||||
.assertTabCompletion(new String[]{"true", "false"}, "0", "");
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.partof;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PartOfInitializationTest {
|
||||
|
||||
public static class Command1 {
|
||||
|
||||
@Register
|
||||
public void test(String sender) {
|
||||
throw new ExecutionIdentifier("Running");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Command2 {
|
||||
|
||||
@Register
|
||||
public void test(String sender) {
|
||||
throw new ExecutionIdentifier("Running");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommand() {
|
||||
AssertionUtils.with(new Command1(), new Command2())
|
||||
.assertNoInitialize("Command with parameters String is already defined in de.steamwar.command.tests.annotations.partof.PartOfInitializationTest$Command1");
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.partof;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PartOfTest {
|
||||
|
||||
public static class Command1 {
|
||||
|
||||
@Mapper(type = BigInteger.class)
|
||||
public TestTypeMapper<BigInteger> bigInteger() {
|
||||
return new TestTypeMapper<>() {
|
||||
@Override
|
||||
public BigInteger map(String sender, PreviousArguments previousArguments, String s) {
|
||||
return new BigInteger(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(String sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class Command2 {
|
||||
|
||||
@Register
|
||||
public void test(String sender) {
|
||||
throw new ExecutionIdentifier("Running");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void test2(String sender, BigInteger bigInteger) {
|
||||
throw new ExecutionIdentifier("Running " + bigInteger);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommand() {
|
||||
AssertionUtils.with(new Command1(), new Command2())
|
||||
.assertExecute("Running");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandWithArguments() {
|
||||
AssertionUtils.with(new Command1(), new Command2())
|
||||
.assertExecute("Running 0", "0");
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.regex;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Regex;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RegexTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Regex("H+") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Regex(value = "H+", error = "Any number of H was expected") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("HHH", "HHH")
|
||||
.assertExecute("HHHHHHHHHHHH", "HHHHHHHHHHHH");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("AA")
|
||||
.assertNoExecute("B");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{"H"}, "H");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("HH", "HH")
|
||||
.assertExecute("HHHHH", "HHHHH");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Any number of H was expected", "A")
|
||||
.assertExecute("Any number of H was expected", "BB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{"H"}, "H");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.register;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DescriptionTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register(description = "Hello World")
|
||||
public void genericCommand(String sender, boolean b) {
|
||||
throw new ExecutionIdentifier(b + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteDescription() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteNoDescription() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("true", "true")
|
||||
.assertExecute("false", "false");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.register;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MultiRegisterTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register("value1")
|
||||
@Register("value2")
|
||||
public void genericCommand(String s) {
|
||||
throw new ExecutionIdentifier("");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteFirstRegister() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("", "value1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSecondRegister() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("", "value2");
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.register;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NoTabCompleteTest {
|
||||
|
||||
public static class SubCommand {
|
||||
|
||||
@Register(value = "test", noTabComplete = true)
|
||||
public void genericCommand(String s) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArgumentCommand {
|
||||
|
||||
@Register(noTabComplete = true)
|
||||
public void genericCommand(String sender, boolean b) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionSub() {
|
||||
AssertionUtils.with(new SubCommand())
|
||||
.assertTabCompletion(new String[]{}, "t");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionArgument() {
|
||||
AssertionUtils.with(new ArgumentCommand())
|
||||
.assertTabCompletion(new String[]{}, "");
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.register;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SubCommandTest {
|
||||
|
||||
public static class SingleCommand {
|
||||
|
||||
@Register("test")
|
||||
public void genericCommand(String s) {
|
||||
throw new ExecutionIdentifier("test");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiCommand {
|
||||
|
||||
@Register({"test1", "test2"})
|
||||
public void genericCommand(String s) {
|
||||
throw new ExecutionIdentifier("test1->test2");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSingleValid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertExecute("test", "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSingleInvalid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertNoExecute("t");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsSingleValid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertTabCompletion(new String[]{"test"}, "")
|
||||
.assertTabCompletion(new String[]{"test"}, "t");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsSingleInvalid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertTabCompletion(new String[]{}, "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteMultiValid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertExecute("test1->test2", "test1", "test2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteMultiInvalid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertNoExecute("test")
|
||||
.assertNoExecute("test1", "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsMultiValid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertTabCompletion(new String[]{"test1"}, "")
|
||||
.assertTabCompletion(new String[]{"test1"}, "t")
|
||||
.assertTabCompletion(new String[]{"test1"}, "te")
|
||||
.assertTabCompletion(new String[]{"test1"}, "tes")
|
||||
.assertTabCompletion(new String[]{"test1"}, "test")
|
||||
.assertTabCompletion(new String[]{"test1"}, "test1")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "t")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "te")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "tes")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "test")
|
||||
.assertTabCompletion(new String[]{"test2"}, "test1", "test2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsMultiInvalid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertTabCompletion(new String[]{}, "test2")
|
||||
.assertTabCompletion(new String[]{}, "test1", "test1");
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.startswith;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.StartsWith;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StartsWithTest {
|
||||
|
||||
public static final class CommandWithoutError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StartsWith("Hello") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CommandWithError {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StartsWith(value = "Hello", error = "Hello must be the prefix") String t) {
|
||||
throw new ExecutionIdentifier(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("HelloTest", "HelloTest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertNoExecute("Test")
|
||||
.assertNoExecute("Hugo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithoutError() {
|
||||
AssertionUtils.with(new CommandWithoutError())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("HelloTest", "HelloTest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertExecute("Hello must be the prefix", "Test")
|
||||
.assertExecute("Hello must be the prefix", "Hugo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteWithError() {
|
||||
AssertionUtils.with(new CommandWithError())
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello");
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.staticvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.StaticValue;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
@Deprecated
|
||||
public class BooleanTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) Boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomFalsePrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue(value = {"a", "b", "c"}, falseValues = {1, 2}) boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomFalseObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue(value = {"a", "b", "c"}, falseValues = {1, 2}) Boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("false", "a")
|
||||
.assertExecute("true", "b")
|
||||
.assertExecute("true", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("false", "a")
|
||||
.assertExecute("true", "b")
|
||||
.assertExecute("true", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitiveCustomFalse() {
|
||||
AssertionUtils.with(new CustomFalsePrimitiveCommand())
|
||||
.assertExecute("true", "a")
|
||||
.assertExecute("false", "b")
|
||||
.assertExecute("false", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObjectCustomFalse() {
|
||||
AssertionUtils.with(new CustomFalseObjectCommand())
|
||||
.assertExecute("true", "a")
|
||||
.assertExecute("false", "b")
|
||||
.assertExecute("false", "c");
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.staticvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.StaticValue;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
@Deprecated
|
||||
public class IntTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) int value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) Integer value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.staticvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.StaticValue;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
@Deprecated
|
||||
public class LongTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) Long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.staticvalue;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.StaticValue;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
@Deprecated
|
||||
public class StringTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @StaticValue({"a", "b", "c"}) String value) {
|
||||
throw new ExecutionIdentifier(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("a", "a")
|
||||
.assertExecute("b", "b")
|
||||
.assertExecute("c", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.tabfilter;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.TabFilter;
|
||||
import de.steamwar.command.annotations.TabFilterType;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TabFilterContainsTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @TabFilter(TabFilterType.CONTAINS) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Integer.MIN_VALUE + "", Integer.MIN_VALUE + "")
|
||||
.assertExecute(Integer.MAX_VALUE + "", Integer.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Integer.MIN_VALUE + "0")
|
||||
.assertNoExecute(Integer.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.tabfilter;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.TabFilter;
|
||||
import de.steamwar.command.annotations.TabFilterType;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TabFilterNoneTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @TabFilter(TabFilterType.NONE) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Integer.MIN_VALUE + "", Integer.MIN_VALUE + "")
|
||||
.assertExecute(Integer.MAX_VALUE + "", Integer.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Integer.MIN_VALUE + "0")
|
||||
.assertNoExecute(Integer.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1")
|
||||
.assertTabCompletion(new String[]{"0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "01");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.tabfilter;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.TabFilter;
|
||||
import de.steamwar.command.annotations.TabFilterType;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TabFilterStartsWithTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @TabFilter(TabFilterType.STARTS_WITH) int i) {
|
||||
throw new ExecutionIdentifier(i + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Integer.MIN_VALUE + "", Integer.MIN_VALUE + "")
|
||||
.assertExecute(Integer.MAX_VALUE + "", Integer.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Integer.MIN_VALUE + "0")
|
||||
.assertNoExecute(Integer.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.unique;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Greedy;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Unique;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyUniqueTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Greedy @Unique int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0", "1", "2", "2")
|
||||
.assertNoExecute("0", "1", "1", "2")
|
||||
.assertNoExecute("0", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletion() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "")
|
||||
.assertTabCompletion(new String[]{"2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "1", "")
|
||||
.assertTabCompletion(new String[]{"3", "4", "5", "6", "7", "8", "9", "-"}, "0", "1", "2", "")
|
||||
.assertTabCompletion(new String[]{"4", "5", "6", "7", "8", "9", "-"}, "0", "1", "2", "3", "")
|
||||
.assertTabCompletion(new String[]{"5", "6", "7", "8", "9", "-"}, "0", "1", "2", "3", "4", "")
|
||||
.assertTabCompletion(new String[]{"6", "7", "8", "9", "-"}, "0", "1", "2", "3", "4", "5", "")
|
||||
.assertTabCompletion(new String[]{"7", "8", "9", "-"}, "0", "1", "2", "3", "4", "5", "6", "")
|
||||
.assertTabCompletion(new String[]{"8", "9", "-"}, "0", "1", "2", "3", "4", "5", "6", "7", "")
|
||||
.assertTabCompletion(new String[]{"9", "-"}, "0", "1", "2", "3", "4", "5", "6", "7", "8", "")
|
||||
.assertTabCompletion(new String[]{"-"}, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "");
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.unique;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Unique;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyUniqueTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Unique int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0", "1", "2", "2")
|
||||
.assertNoExecute("0", "1", "1", "2")
|
||||
.assertNoExecute("0", "0", "1", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletion() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "")
|
||||
.assertTabCompletion(new String[]{"2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "1", "")
|
||||
.assertTabCompletion(new String[]{"3", "4", "5", "6", "7", "8", "9", "-"}, "0", "1", "2", "")
|
||||
.assertTabCompletion(new String[]{"4", "5", "6", "7", "8", "9", "-"}, "0", "1", "2", "3", "")
|
||||
.assertTabCompletion(new String[]{"5", "6", "7", "8", "9", "-"}, "0", "1", "2", "3", "4", "")
|
||||
.assertTabCompletion(new String[]{"6", "7", "8", "9", "-"}, "0", "1", "2", "3", "4", "5", "")
|
||||
.assertTabCompletion(new String[]{"7", "8", "9", "-"}, "0", "1", "2", "3", "4", "5", "6", "")
|
||||
.assertTabCompletion(new String[]{"8", "9", "-"}, "0", "1", "2", "3", "4", "5", "6", "7", "")
|
||||
.assertTabCompletion(new String[]{"9", "-"}, "0", "1", "2", "3", "4", "5", "6", "7", "8", "")
|
||||
.assertTabCompletion(new String[]{"-"}, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.validator.type;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Validator(type = BigInteger.class, local = false)
|
||||
public TestTypeValidator<BigInteger> globalValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoExecute("0");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.validator.type;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class LocalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Validator(type = BigInteger.class)
|
||||
public TestTypeValidator<BigInteger> localValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoInitialize("Validator '' not found");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.validator.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class GlobalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Validator(value = "globalValidator", local = false)
|
||||
public TestTypeValidator<BigInteger> globalValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator("globalValidator") BigInteger b) {
|
||||
throw new ExecutionIdentifier(b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoExecute("0");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.validator.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class LocalTest {
|
||||
|
||||
public static class FirstCommand {
|
||||
|
||||
@Validator(value = "localValidator")
|
||||
public TestTypeValidator<BigInteger> localValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecondCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator("localValidator") String b) {
|
||||
throw new ExecutionIdentifier(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalValidator() {
|
||||
AssertionUtils.with(new FirstCommand())
|
||||
.assertNoExecute("");
|
||||
|
||||
AssertionUtils.with(new SecondCommand())
|
||||
.assertNoInitialize("Validator 'localValidator' not found");
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.validator.value;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import de.steamwar.command.impl.TestTypeValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MultiTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
private boolean validator_1;
|
||||
private boolean validator_2;
|
||||
|
||||
public Command(boolean validator_1, boolean validator_2) {
|
||||
this.validator_1 = validator_1;
|
||||
this.validator_2 = validator_2;
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Validator("validator_1") @Validator("validator_2") String s) {
|
||||
throw new ExecutionIdentifier(s);
|
||||
}
|
||||
|
||||
@Validator(value = "validator_1")
|
||||
public TestTypeValidator<String> validator_1() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return validator_1;
|
||||
};
|
||||
}
|
||||
|
||||
@Validator(value = "validator_2")
|
||||
public TestTypeValidator<String> validator_2() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return validator_2;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValidatorTrueTrue() {
|
||||
AssertionUtils.with(new Command(true, true))
|
||||
.assertExecute("Hello", "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValidatorTrueFalse() {
|
||||
AssertionUtils.with(new Command(true, false))
|
||||
.assertNoExecute("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValidatorFalseTrue() {
|
||||
AssertionUtils.with(new Command(false, true))
|
||||
.assertNoExecute("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValidatorFalseFalse() {
|
||||
AssertionUtils.with(new Command(false, false))
|
||||
.assertNoExecute("Hello");
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.values;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Values;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BooleanTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) Boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomFalsePrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values(value = {"a", "b", "c"}, falseValues = {1, 2}) boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomFalseObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values(value = {"a", "b", "c"}, falseValues = {1, 2}) Boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("false", "a")
|
||||
.assertExecute("true", "b")
|
||||
.assertExecute("true", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("false", "a")
|
||||
.assertExecute("true", "b")
|
||||
.assertExecute("true", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitiveCustomFalse() {
|
||||
AssertionUtils.with(new CustomFalsePrimitiveCommand())
|
||||
.assertExecute("true", "a")
|
||||
.assertExecute("false", "b")
|
||||
.assertExecute("false", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObjectCustomFalse() {
|
||||
AssertionUtils.with(new CustomFalseObjectCommand())
|
||||
.assertExecute("true", "a")
|
||||
.assertExecute("false", "b")
|
||||
.assertExecute("false", "c");
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.values;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Values;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) int value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) Integer value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.values;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Values;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) Long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecutePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletePrimitive() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "a")
|
||||
.assertExecute("1", "b")
|
||||
.assertExecute("2", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecuteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompleteObject() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.annotations.values;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Values;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, @Values({"a", "b", "c"}) String value) {
|
||||
throw new ExecutionIdentifier(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("a", "a")
|
||||
.assertExecute("b", "b")
|
||||
.assertExecute("c", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("ab")
|
||||
.assertNoExecute("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"a", "b", "c"}, "");
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.array;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GreedyTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, int... args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0", "1", "b")
|
||||
.assertNoExecute("0", "b")
|
||||
.assertNoExecute("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "0", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "0", "b")
|
||||
.assertTabCompletion(new String[]{}, "b", "0", "");
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.array;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NonGreedyTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, int[] args) {
|
||||
throw new ExecutionIdentifier(Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("[0, 1, 2]", "0", "1", "2")
|
||||
.assertExecute("[0, 1]", "0", "1")
|
||||
.assertExecute("[0]", "0")
|
||||
.assertExecute("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("0", "1", "b")
|
||||
.assertNoExecute("0", "b")
|
||||
.assertNoExecute("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "")
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "0", "0", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "0", "b")
|
||||
.assertTabCompletion(new String[]{}, "b", "0", "");
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.enumeration;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EnumTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, TestEnum value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public enum TestEnum {
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
WEDNESDAY,
|
||||
THURSDAY,
|
||||
FRIDAY,
|
||||
SATURDAY,
|
||||
SUNDAY
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("MONDAY", "MONDAY")
|
||||
.assertExecute("MONDAY", "monday")
|
||||
.assertExecute("TUESDAY", "TUESDAY")
|
||||
.assertExecute("TUESDAY", "tUeSdAY")
|
||||
.assertExecute("WEDNESDAY", "WEDNESDAY")
|
||||
.assertExecute("WEDNESDAY", "wedNesDay")
|
||||
.assertExecute("THURSDAY", "THURSDAY")
|
||||
.assertExecute("THURSDAY", "THURSDAY")
|
||||
.assertExecute("THURSDAY", "THuRSdAY")
|
||||
.assertExecute("FRIDAY", "FRIDAY")
|
||||
.assertExecute("FRIDAY", "FRidAY")
|
||||
.assertExecute("SATURDAY", "SATURDAY")
|
||||
.assertExecute("SATURDAY", "SaTuRDaY")
|
||||
.assertExecute("SUNDAY", "SUNDAY")
|
||||
.assertExecute("SUNDAY", "SUnDAY");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertNoExecute("m")
|
||||
.assertNoExecute("mon")
|
||||
.assertNoExecute("monday2")
|
||||
.assertNoExecute("0Monday");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsValid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"}, "")
|
||||
.assertTabCompletion(new String[]{"MONDAY"}, "m")
|
||||
.assertTabCompletion(new String[]{"TUESDAY", "THURSDAY"}, "t")
|
||||
.assertTabCompletion(new String[]{"TUESDAY"}, "tu")
|
||||
.assertTabCompletion(new String[]{"THURSDAY"}, "th")
|
||||
.assertTabCompletion(new String[]{"WEDNESDAY"}, "w")
|
||||
.assertTabCompletion(new String[]{"FRIDAY"}, "f")
|
||||
.assertTabCompletion(new String[]{"SATURDAY", "SUNDAY"}, "s")
|
||||
.assertTabCompletion(new String[]{"SATURDAY"}, "sa")
|
||||
.assertTabCompletion(new String[]{"SUNDAY"}, "su");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsInvalid() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "mu")
|
||||
.assertTabCompletion(new String[]{}, "m0")
|
||||
.assertTabCompletion(new String[]{}, "tuel")
|
||||
.assertTabCompletion(new String[]{}, "tes");
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.enumeration;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.OptionEnum;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OptionEnumTest {
|
||||
|
||||
public static class SingleCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, TestEnum value1) {
|
||||
throw new ExecutionIdentifier(value1 + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, TestEnum value1, TestEnum value2) {
|
||||
throw new ExecutionIdentifier(value1 + ":" + value2);
|
||||
}
|
||||
}
|
||||
|
||||
public enum TestEnum implements OptionEnum<TestEnum> {
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
WEDNESDAY,
|
||||
THURSDAY,
|
||||
FRIDAY,
|
||||
SATURDAY,
|
||||
SUNDAY;
|
||||
|
||||
|
||||
@Override
|
||||
public TestEnum[] getRemoved() {
|
||||
return new TestEnum[]{
|
||||
MONDAY,
|
||||
TUESDAY
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSingleValid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertExecute("MONDAY", "-monday")
|
||||
.assertExecute("TUESDAY", "-tuesday")
|
||||
.assertExecute("WEDNESDAY", "-wednesday")
|
||||
.assertExecute("THURSDAY", "-thursday")
|
||||
.assertExecute("FRIDAY", "-friday")
|
||||
.assertExecute("SATURDAY", "-saturday")
|
||||
.assertExecute("SUNDAY", "-sunday");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExecuteSingleInvalid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertNoExecute("-m")
|
||||
.assertNoExecute("-mon")
|
||||
.assertNoExecute("-monday2")
|
||||
.assertNoExecute("-0Monday");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsSingleValid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertTabCompletion(new String[]{"-monday", "-tuesday", "-wednesday", "-thursday", "-friday", "-saturday", "-sunday"}, "")
|
||||
.assertTabCompletion(new String[]{"-monday", "-tuesday", "-wednesday", "-thursday", "-friday", "-saturday", "-sunday"}, "-")
|
||||
.assertTabCompletion(new String[]{"-monday"}, "-m")
|
||||
.assertTabCompletion(new String[]{"-tuesday", "-thursday"}, "-t")
|
||||
.assertTabCompletion(new String[]{"-tuesday"}, "-tu")
|
||||
.assertTabCompletion(new String[]{"-thursday"}, "-th")
|
||||
.assertTabCompletion(new String[]{"-wednesday"}, "-w")
|
||||
.assertTabCompletion(new String[]{"-friday"}, "-f")
|
||||
.assertTabCompletion(new String[]{"-saturday", "-sunday"}, "-s")
|
||||
.assertTabCompletion(new String[]{"-saturday"}, "-sa")
|
||||
.assertTabCompletion(new String[]{"-sunday"}, "-su");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsSingleInvalid() {
|
||||
AssertionUtils.with(new SingleCommand())
|
||||
.assertTabCompletion(new String[]{}, "-mu")
|
||||
.assertTabCompletion(new String[]{}, "-m0")
|
||||
.assertTabCompletion(new String[]{}, "-tuel")
|
||||
.assertTabCompletion(new String[]{}, "-tes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteMultiValid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertExecute("MONDAY:WEDNESDAY", "-monday", "-wednesday")
|
||||
.assertExecute("MONDAY:THURSDAY", "-monday", "-thursday")
|
||||
.assertExecute("MONDAY:FRIDAY", "-monday", "-friday")
|
||||
.assertExecute("MONDAY:SATURDAY", "-monday", "-saturday")
|
||||
.assertExecute("MONDAY:SUNDAY", "-monday", "-sunday")
|
||||
.assertExecute("TUESDAY:WEDNESDAY", "-tuesday", "-wednesday")
|
||||
.assertExecute("TUESDAY:THURSDAY", "-tuesday", "-thursday")
|
||||
.assertExecute("TUESDAY:FRIDAY", "-tuesday", "-friday")
|
||||
.assertExecute("TUESDAY:SATURDAY", "-tuesday", "-saturday")
|
||||
.assertExecute("TUESDAY:SUNDAY", "-tuesday", "-sunday")
|
||||
.assertExecute("WEDNESDAY:THURSDAY", "-wednesday", "-thursday")
|
||||
.assertExecute("WEDNESDAY:FRIDAY", "-wednesday", "-friday")
|
||||
.assertExecute("WEDNESDAY:SATURDAY", "-wednesday", "-saturday")
|
||||
.assertExecute("WEDNESDAY:SUNDAY", "-wednesday", "-sunday")
|
||||
.assertExecute("THURSDAY:WEDNESDAY", "-thursday", "-wednesday")
|
||||
.assertExecute("THURSDAY:FRIDAY", "-thursday", "-friday")
|
||||
.assertExecute("THURSDAY:SATURDAY", "-thursday", "-saturday")
|
||||
.assertExecute("THURSDAY:SUNDAY", "-thursday", "-sunday")
|
||||
.assertExecute("FRIDAY:WEDNESDAY", "-friday", "-wednesday")
|
||||
.assertExecute("FRIDAY:THURSDAY", "-friday", "-thursday")
|
||||
.assertExecute("FRIDAY:SATURDAY", "-friday", "-saturday")
|
||||
.assertExecute("FRIDAY:SUNDAY", "-friday", "-sunday")
|
||||
.assertExecute("SATURDAY:WEDNESDAY", "-saturday", "-wednesday")
|
||||
.assertExecute("SATURDAY:THURSDAY", "-saturday", "-thursday")
|
||||
.assertExecute("SATURDAY:FRIDAY", "-saturday", "-friday")
|
||||
.assertExecute("SATURDAY:SUNDAY", "-saturday", "-sunday")
|
||||
.assertExecute("SUNDAY:WEDNESDAY", "-sunday", "-wednesday")
|
||||
.assertExecute("SUNDAY:THURSDAY", "-sunday", "-thursday")
|
||||
.assertExecute("SUNDAY:FRIDAY", "-sunday", "-friday")
|
||||
.assertExecute("SUNDAY:SATURDAY", "-sunday", "-saturday");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteMultiInvalid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertNoExecute("-monday", "-monday")
|
||||
.assertNoExecute("-monday", "-tuesday")
|
||||
.assertNoExecute("-tuesday", "-monday")
|
||||
.assertNoExecute("-tuesday", "-tuesday")
|
||||
.assertNoExecute("-wednesday", "-monday")
|
||||
.assertNoExecute("-wednesday", "-tuesday")
|
||||
.assertNoExecute("-wednesday", "-wednesday")
|
||||
.assertNoExecute("-thursday", "-monday")
|
||||
.assertNoExecute("-thursday", "-tuesday")
|
||||
.assertNoExecute("-thursday", "-thursday")
|
||||
.assertNoExecute("-friday", "-monday")
|
||||
.assertNoExecute("-friday", "-tuesday")
|
||||
.assertNoExecute("-friday", "-friday")
|
||||
.assertNoExecute("-saturday", "-monday")
|
||||
.assertNoExecute("-saturday", "-tuesday")
|
||||
.assertNoExecute("-saturday", "-saturday")
|
||||
.assertNoExecute("-sunday", "-monday")
|
||||
.assertNoExecute("-sunday", "-tuesday")
|
||||
.assertNoExecute("-sunday", "-sunday");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsMultiValid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertTabCompletion(new String[]{"-wednesday", "-thursday", "-friday", "-saturday", "-sunday"}, "-monday", "")
|
||||
.assertTabCompletion(new String[]{"-wednesday", "-thursday", "-friday", "-saturday", "-sunday"}, "-monday", "-")
|
||||
.assertTabCompletion(new String[]{"-wednesday", "-friday", "-saturday", "-sunday"}, "-thursday", "")
|
||||
.assertTabCompletion(new String[]{"-wednesday", "-friday", "-saturday", "-sunday"}, "-thursday", "-")
|
||||
.assertTabCompletion(new String[]{"-wednesday"}, "-thursday", "-w")
|
||||
.assertTabCompletion(new String[]{"-friday"}, "-thursday", "-f")
|
||||
.assertTabCompletion(new String[]{"-saturday", "-sunday"}, "-thursday", "-s")
|
||||
.assertTabCompletion(new String[]{"-saturday"}, "-thursday", "-sa")
|
||||
.assertTabCompletion(new String[]{"-sunday"}, "-thursday", "-su");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletionsMultiInvalid() {
|
||||
AssertionUtils.with(new MultiCommand())
|
||||
.assertTabCompletion(new String[]{}, "-monday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-monday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-tuesday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-tuesday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-wednesday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-wednesday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-wednesday", "-w")
|
||||
.assertTabCompletion(new String[]{}, "-thursday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-thursday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-thursday", "-th")
|
||||
.assertTabCompletion(new String[]{}, "-friday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-friday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-friday", "-f")
|
||||
.assertTabCompletion(new String[]{}, "-saturday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-saturday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-saturday", "-sa")
|
||||
.assertTabCompletion(new String[]{}, "-sunday", "-m")
|
||||
.assertTabCompletion(new String[]{}, "-sunday", "-tu")
|
||||
.assertTabCompletion(new String[]{}, "-sunday", "-su");
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.other;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.annotations.Values;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleSpaceTabCompletionTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void test(String sender, @Values({"Hello", "World"}) String s) {
|
||||
throw new ExecutionIdentifier(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabComplete() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{"Hello", "World"}, "")
|
||||
.assertTabCompletion(new String[]{"Hello", "World"}, "", "")
|
||||
.assertTabCompletion(new String[]{"Hello", "World"}, "", "", "");
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BooleanTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, Boolean value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("true", "true")
|
||||
.assertExecute("false", "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"true", "false"}, "")
|
||||
.assertTabCompletion(new String[]{"true"}, "t")
|
||||
.assertTabCompletion(new String[]{"true"}, "tr")
|
||||
.assertTabCompletion(new String[]{"true"}, "tru")
|
||||
.assertTabCompletion(new String[]{"true"}, "true")
|
||||
.assertTabCompletion(new String[]{"false"}, "f")
|
||||
.assertTabCompletion(new String[]{"false"}, "fa")
|
||||
.assertTabCompletion(new String[]{"false"}, "fal")
|
||||
.assertTabCompletion(new String[]{"false"}, "fals")
|
||||
.assertTabCompletion(new String[]{"false"}, "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "h")
|
||||
.assertTabCompletion(new String[]{}, "u")
|
||||
.assertTabCompletion(new String[]{}, "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("true", "true")
|
||||
.assertExecute("false", "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"true", "false"}, "")
|
||||
.assertTabCompletion(new String[]{"true"}, "t")
|
||||
.assertTabCompletion(new String[]{"true"}, "tr")
|
||||
.assertTabCompletion(new String[]{"true"}, "tru")
|
||||
.assertTabCompletion(new String[]{"true"}, "true")
|
||||
.assertTabCompletion(new String[]{"false"}, "f")
|
||||
.assertTabCompletion(new String[]{"false"}, "fa")
|
||||
.assertTabCompletion(new String[]{"false"}, "fal")
|
||||
.assertTabCompletion(new String[]{"false"}, "fals")
|
||||
.assertTabCompletion(new String[]{"false"}, "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{}, "h")
|
||||
.assertTabCompletion(new String[]{}, "u")
|
||||
.assertTabCompletion(new String[]{}, "a");
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, double value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, Double value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0.0", "0")
|
||||
.assertExecute("0.5", "0.5")
|
||||
.assertExecute("1.0", "1")
|
||||
.assertExecute("1.5", "1.5")
|
||||
.assertExecute("-1.0", "-1")
|
||||
.assertExecute("-1.5", "-1.5")
|
||||
.assertExecute(Double.MIN_VALUE + "", Double.MIN_VALUE + "")
|
||||
.assertExecute(Double.MIN_NORMAL + "", Double.MIN_NORMAL + "")
|
||||
.assertExecute(Double.MAX_VALUE + "", Double.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "0."}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "1.", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-1.", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1")
|
||||
.assertTabCompletion(new String[]{"-0."}, "-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0.0", "0")
|
||||
.assertExecute("0.5", "0.5")
|
||||
.assertExecute("1.0", "1")
|
||||
.assertExecute("1.5", "1.5")
|
||||
.assertExecute("-1.0", "-1")
|
||||
.assertExecute("-1.5", "-1.5")
|
||||
.assertExecute(Double.MIN_VALUE + "", Double.MIN_VALUE + "")
|
||||
.assertExecute(Double.MIN_NORMAL + "", Double.MIN_NORMAL + "")
|
||||
.assertExecute(Double.MAX_VALUE + "", Double.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "0."}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "1.", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-1.", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1")
|
||||
.assertTabCompletion(new String[]{"-0."}, "-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FloatTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, float value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, Float value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0.0", "0")
|
||||
.assertExecute("0.5", "0.5")
|
||||
.assertExecute("1.0", "1")
|
||||
.assertExecute("1.5", "1.5")
|
||||
.assertExecute("-1.0", "-1")
|
||||
.assertExecute("-1.5", "-1.5")
|
||||
.assertExecute(Float.MIN_VALUE + "", Float.MIN_VALUE + "")
|
||||
.assertExecute(Float.MIN_NORMAL + "", Float.MIN_NORMAL + "")
|
||||
.assertExecute(Float.MAX_VALUE + "", Float.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[] {"0", "0."}, "0")
|
||||
.assertTabCompletion(new String[] {"1", "1.", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[] {"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[] {"-1", "-1.", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1")
|
||||
.assertTabCompletion(new String[] {"-0."}, "-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[] {}, "01")
|
||||
.assertTabCompletion(new String[] {}, "NaN")
|
||||
.assertTabCompletion(new String[] {}, "a")
|
||||
.assertTabCompletion(new String[] {}, "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0.0", "0")
|
||||
.assertExecute("0.5", "0.5")
|
||||
.assertExecute("1.0", "1")
|
||||
.assertExecute("1.5", "1.5")
|
||||
.assertExecute("-1.0", "-1")
|
||||
.assertExecute("-1.5", "-1.5")
|
||||
.assertExecute(Float.MIN_VALUE + "", Float.MIN_VALUE + "")
|
||||
.assertExecute(Float.MIN_NORMAL + "", Float.MIN_NORMAL + "")
|
||||
.assertExecute(Float.MAX_VALUE + "", Float.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0", "0."}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "1.", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-1.", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1")
|
||||
.assertTabCompletion(new String[]{"-0."}, "-0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, int value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, Integer value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Integer.MIN_VALUE + "", Integer.MIN_VALUE + "")
|
||||
.assertExecute(Integer.MAX_VALUE + "", Integer.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Integer.MIN_VALUE + "0")
|
||||
.assertNoExecute(Integer.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Integer.MIN_VALUE + "", Integer.MIN_VALUE + "")
|
||||
.assertExecute(Integer.MAX_VALUE + "", Integer.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Integer.MIN_VALUE + "0")
|
||||
.assertNoExecute(Integer.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongTest {
|
||||
|
||||
public static class PrimitiveCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, Long value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteValid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Long.MIN_VALUE + "", Long.MIN_VALUE + "")
|
||||
.assertExecute(Long.MAX_VALUE + "", Long.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveExecuteInvalid() {
|
||||
AssertionUtils.with(new PrimitiveCommand())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Long.MIN_VALUE + "0")
|
||||
.assertNoExecute(Long.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionValid() {
|
||||
AssertionUtils.with(new IntTest.PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTabCompletionInvalid() {
|
||||
AssertionUtils.with(new IntTest.PrimitiveCommand())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteValid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("1", "1")
|
||||
.assertExecute("-1", "-1")
|
||||
.assertExecute(Long.MIN_VALUE + "", Long.MIN_VALUE + "")
|
||||
.assertExecute(Long.MAX_VALUE + "", Long.MAX_VALUE + "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectExecuteInvalid() {
|
||||
AssertionUtils.with(new ObjectCommand())
|
||||
.assertNoExecute("invalid")
|
||||
.assertNoExecute("-")
|
||||
.assertNoExecute("0.0")
|
||||
.assertNoExecute("-0.0")
|
||||
.assertNoExecute(Long.MIN_VALUE + "0")
|
||||
.assertNoExecute(Long.MAX_VALUE + "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionValid() {
|
||||
AssertionUtils.with(new IntTest.ObjectCommand())
|
||||
.assertTabCompletion(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"}, "")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"}, "1")
|
||||
.assertTabCompletion(new String[]{"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}, "-")
|
||||
.assertTabCompletion(new String[]{"-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"}, "-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectTabCompletionInvalid() {
|
||||
AssertionUtils.with(new IntTest.ObjectCommand())
|
||||
.assertTabCompletion(new String[]{}, "-0")
|
||||
.assertTabCompletion(new String[]{}, "01")
|
||||
.assertTabCompletion(new String[]{}, "NaN")
|
||||
.assertTabCompletion(new String[]{}, "a")
|
||||
.assertTabCompletion(new String[]{}, "Hello");
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.command.tests.primitive;
|
||||
|
||||
import de.steamwar.AssertionUtils;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
import de.steamwar.command.impl.ExecutionIdentifier;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringTest {
|
||||
|
||||
public static class Command {
|
||||
|
||||
@Register
|
||||
public void genericCommand(String sender, String value) {
|
||||
throw new ExecutionIdentifier(value + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertExecute("Hello", "Hello")
|
||||
.assertExecute("s", "s")
|
||||
.assertExecute("0", "0")
|
||||
.assertExecute("_", "_")
|
||||
.assertExecute("-", "-")
|
||||
.assertExecute("/", "/")
|
||||
.assertExecute("@", "@")
|
||||
.assertExecute("\\", "\\")
|
||||
.assertExecute("\"", "\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCompletion() {
|
||||
AssertionUtils.with(new Command())
|
||||
.assertTabCompletion(new String[]{}, "")
|
||||
.assertTabCompletion(new String[]{"a"}, "a")
|
||||
.assertTabCompletion(new String[]{"Hello"}, "Hello")
|
||||
.assertTabCompletion(new String[]{"0"}, "0")
|
||||
.assertTabCompletion(new String[]{"_"}, "_")
|
||||
.assertTabCompletion(new String[]{"-"}, "-")
|
||||
.assertTabCompletion(new String[]{"/"}, "/")
|
||||
.assertTabCompletion(new String[]{"@"}, "@")
|
||||
.assertTabCompletion(new String[]{"\\"}, "\\")
|
||||
.assertTabCompletion(new String[]{"\""}, "\"");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user