From 3fa992b5c9fa73e0c31525b814cd020e91d9e0fe Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 16 Aug 2022 22:20:17 +0200 Subject: [PATCH] Remove guard system --- .../command/AbstractGuardChecker.java | 29 ------- .../steamwar/command/AbstractSWCommand.java | 49 +----------- src/de/steamwar/command/CommandPart.java | 75 ++----------------- src/de/steamwar/command/GuardCheckType.java | 27 ------- src/de/steamwar/command/GuardResult.java | 27 ------- src/de/steamwar/command/SWCommandUtils.java | 55 +------------- src/de/steamwar/command/SubCommand.java | 31 +------- testsrc/de/steamwar/command/GuardCommand.java | 43 ----------- .../de/steamwar/command/GuardCommandTest.java | 52 ------------- .../command/dto/TestGuardChecker.java | 25 ------- 10 files changed, 14 insertions(+), 399 deletions(-) delete mode 100644 src/de/steamwar/command/AbstractGuardChecker.java delete mode 100644 src/de/steamwar/command/GuardCheckType.java delete mode 100644 src/de/steamwar/command/GuardResult.java delete mode 100644 testsrc/de/steamwar/command/GuardCommand.java delete mode 100644 testsrc/de/steamwar/command/GuardCommandTest.java delete mode 100644 testsrc/de/steamwar/command/dto/TestGuardChecker.java diff --git a/src/de/steamwar/command/AbstractGuardChecker.java b/src/de/steamwar/command/AbstractGuardChecker.java deleted file mode 100644 index dd4c555..0000000 --- a/src/de/steamwar/command/AbstractGuardChecker.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command; - -@Deprecated -@FunctionalInterface -public interface AbstractGuardChecker { - /** - * While guarding the first parameter of the command the parameter s of this method is {@code null} - */ - GuardResult guard(T t, GuardCheckType guardCheckType, String[] previousArguments, String s); -} diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index aa33a64..758be84 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -38,7 +38,6 @@ public abstract class AbstractSWCommand { protected final List> commandHelpList = new ArrayList<>(); private final Map> localTypeMapper = new HashMap<>(); - private final Map> localGuardChecker = new HashMap<>(); private final Map> localValidators = new HashMap<>(); protected AbstractSWCommand(Class clazz, String command) { @@ -126,20 +125,6 @@ public abstract class AbstractSWCommand { SWCommandUtils.getMAPPER_FUNCTIONS().putIfAbsent(anno.value().getTypeName(), typeMapper); } }); - addGuard(Guard.class, method, i -> i == 0, false, AbstractGuardChecker.class, (anno, guardChecker) -> { - if (anno.local()) { - localGuardChecker.putIfAbsent(anno.value(), (AbstractGuardChecker) guardChecker); - } else { - SWCommandUtils.getGUARD_FUNCTIONS().putIfAbsent(anno.value(), guardChecker); - } - }); - addGuard(ClassGuard.class, method, i -> i == 0, false, AbstractGuardChecker.class, (anno, guardChecker) -> { - if (anno.local()) { - localGuardChecker.putIfAbsent(anno.value().getTypeName(), (AbstractGuardChecker) guardChecker); - } else { - SWCommandUtils.getGUARD_FUNCTIONS().putIfAbsent(anno.value().getTypeName(), guardChecker); - } - }); addValidator(Validator.class, method, i -> i == 0, false, AbstractValidator.class, (anno, validator) -> { if (anno.local()) { localValidators.putIfAbsent(anno.value(), (AbstractValidator) validator); @@ -168,7 +153,7 @@ public abstract class AbstractSWCommand { commandSystemWarning(() -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } - commandHelpList.add(new SubCommand<>(this, method, anno.value(), new HashMap<>(), new HashMap<>(), localGuardChecker, true, null, anno.noTabComplete())); + commandHelpList.add(new SubCommand<>(this, method, anno.value(), new HashMap<>(), new HashMap<>(), true, null, anno.noTabComplete())); }); add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { @@ -189,7 +174,7 @@ public abstract class AbstractSWCommand { return; } } - commandList.add(new SubCommand<>(this, method, anno.value(), localTypeMapper, localValidators, localGuardChecker, false, anno.description(), anno.noTabComplete())); + commandList.add(new SubCommand<>(this, method, anno.value(), localTypeMapper, localValidators, false, anno.description(), anno.noTabComplete())); }); } @@ -255,18 +240,6 @@ public abstract class AbstractSWCommand { }); } - @Deprecated - private void addGuard(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer> consumer) { - add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> { - try { - method.setAccessible(true); - consumer.accept(anno, (AbstractGuardChecker) method.invoke(this)); - } catch (Exception e) { - throw new SecurityException(e.getMessage(), e); - } - }); - } - // TODO: Implement this when Message System is ready /* public void addDefaultHelpMessage(String message) { @@ -327,24 +300,6 @@ public abstract class AbstractSWCommand { boolean global() default false; } - @Deprecated - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.PARAMETER, ElementType.METHOD}) - protected @interface Guard { - String value() default ""; - - boolean local() default false; - } - - @Deprecated - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - protected @interface ClassGuard { - Class value(); - - boolean local() default false; - } - @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.METHOD}) protected @interface Validator { diff --git a/src/de/steamwar/command/CommandPart.java b/src/de/steamwar/command/CommandPart.java index d5a5220..f402abe 100644 --- a/src/de/steamwar/command/CommandPart.java +++ b/src/de/steamwar/command/CommandPart.java @@ -42,24 +42,20 @@ class CommandPart { private AbstractSWCommand command; private AbstractTypeMapper typeMapper; private AbstractValidator validator; - private AbstractGuardChecker guardChecker; private Class varArgType; private String optional; - private GuardCheckType guardCheckType; private CommandPart next = null; @Setter private boolean ignoreAsArgument = false; - public CommandPart(AbstractSWCommand command, AbstractTypeMapper typeMapper, AbstractValidator validator, AbstractGuardChecker guardChecker, Class varArgType, String optional, GuardCheckType guardCheckType) { + public CommandPart(AbstractSWCommand command, AbstractTypeMapper typeMapper, AbstractValidator validator, Class varArgType, String optional) { this.command = command; this.typeMapper = typeMapper; this.validator = validator; - this.guardChecker = guardChecker; this.varArgType = varArgType; this.optional = optional; - this.guardCheckType = guardCheckType; validatePart(); } @@ -72,9 +68,6 @@ class CommandPart { } private void validatePart() { - if (guardCheckType == GuardCheckType.TAB_COMPLETE) { - throw new IllegalArgumentException("Tab complete is not allowed as a guard check type!"); - } if (optional != null && varArgType != null) { throw new IllegalArgumentException("A vararg part can't have an optional part!"); } @@ -92,7 +85,7 @@ class CommandPart { if (varArgType != null) { Object array = Array.newInstance(varArgType, args.length - startIndex); for (int i = startIndex; i < args.length; i++) { - CheckArgumentResult validArgument = checkArgument(null, null, sender, args, i); + CheckArgumentResult validArgument = checkArgument(null, sender, args, i); if (!validArgument.success) { throw new CommandParseException(); } @@ -107,7 +100,7 @@ class CommandPart { return; } - CheckArgumentResult validArgument = checkArgument(errors, null, sender, args, startIndex); + CheckArgumentResult validArgument = checkArgument(errors, sender, args, startIndex); if (!validArgument.success && optional == null) { throw new CommandParseException(); } @@ -128,43 +121,10 @@ class CommandPart { } } - public boolean guardCheck(T sender, String[] args, int startIndex) { - if (varArgType != null) { - for (int i = startIndex; i < args.length; i++) { - GuardResult guardResult = checkGuard(guardCheckType, sender, args, i); - if (guardResult == GuardResult.DENIED) { - throw new CommandNoHelpException(); - } - if (guardResult == GuardResult.DENIED_WITH_HELP) { - return false; - } - } - return true; - } - - GuardResult guardResult = checkGuard(guardCheckType, sender, args, startIndex); - if (guardResult == GuardResult.DENIED) { - if (optional != null && next != null) { - return next.guardCheck(sender, args, startIndex); - } - throw new CommandNoHelpException(); - } - if (guardResult == GuardResult.DENIED_WITH_HELP) { - if (optional != null && next != null) { - return next.guardCheck(sender, args, startIndex); - } - return false; - } - if (next != null) { - return next.guardCheck(sender, args, startIndex + 1); - } - return true; - } - public void generateTabComplete(List current, T sender, String[] args, int startIndex) { if (varArgType != null) { for (int i = startIndex; i < args.length - 1; i++) { - CheckArgumentResult validArgument = checkArgument((ignore) -> {}, GuardCheckType.TAB_COMPLETE, sender, args, i); + CheckArgumentResult validArgument = checkArgument((ignore) -> {}, sender, args, i); if (!validArgument.success) { return; } @@ -177,7 +137,7 @@ class CommandPart { } if (args.length - 1 > startIndex) { - CheckArgumentResult checkArgumentResult = checkArgument((ignore) -> {}, GuardCheckType.TAB_COMPLETE, sender, args, startIndex); + CheckArgumentResult checkArgumentResult = checkArgument((ignore) -> {}, sender, args, startIndex); if (checkArgumentResult.success && next != null) { next.generateTabComplete(current, sender, args, startIndex + 1); return; @@ -203,7 +163,7 @@ class CommandPart { }); } - private CheckArgumentResult checkArgument(Consumer errors, GuardCheckType guardCheckType, T sender, String[] args, int index) { + private CheckArgumentResult checkArgument(Consumer errors, T sender, String[] args, int index) { try { Object value = typeMapper.map(sender, Arrays.copyOf(args, index), args[index]); if (validator != null && errors != null) { @@ -216,29 +176,8 @@ class CommandPart { } return new CheckArgumentResult(value != null, value); } - if (value == null) { - return new CheckArgumentResult(false, null); - } - - GuardResult guardResult = checkGuard(guardCheckType, sender, args, index); - switch (guardResult) { - case ALLOWED: - return new CheckArgumentResult(true, value); - case DENIED: - throw new CommandNoHelpException(); - case DENIED_WITH_HELP: - default: - return new CheckArgumentResult(false, null); - } } catch (Exception e) { - return new CheckArgumentResult(false, null); } - } - - private GuardResult checkGuard(GuardCheckType guardCheckType, T sender, String[] args, int index) { - if (guardChecker != null && guardCheckType != null) { - return guardChecker.guard(sender, guardCheckType, Arrays.copyOf(args, index), args[index]); - } - return GuardResult.ALLOWED; + return new CheckArgumentResult(false, null); } } diff --git a/src/de/steamwar/command/GuardCheckType.java b/src/de/steamwar/command/GuardCheckType.java deleted file mode 100644 index d2e6ed0..0000000 --- a/src/de/steamwar/command/GuardCheckType.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command; - -@Deprecated -public enum GuardCheckType { - COMMAND, - HELP_COMMAND, - TAB_COMPLETE -} diff --git a/src/de/steamwar/command/GuardResult.java b/src/de/steamwar/command/GuardResult.java deleted file mode 100644 index 3e6aafc..0000000 --- a/src/de/steamwar/command/GuardResult.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command; - -@Deprecated -public enum GuardResult { - ALLOWED, - DENIED_WITH_HELP, - DENIED -} diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 69e0b8c..61845dc 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -37,10 +37,6 @@ public class SWCommandUtils { @Getter private final Map> MAPPER_FUNCTIONS = new HashMap<>(); - @Getter - @Deprecated - private final Map> GUARD_FUNCTIONS = new HashMap<>(); - @Getter private final Map> VALIDATOR_FUNCTIONS = new HashMap<>(); @@ -78,11 +74,11 @@ public class SWCommandUtils { MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper); } - static CommandPart generateCommandPart(AbstractSWCommand command, boolean help, String[] subCommand, Parameter[] parameters, Map> localTypeMapper, Map> localValidator, Map> localGuardChecker) { + static CommandPart generateCommandPart(AbstractSWCommand command, boolean help, String[] subCommand, Parameter[] parameters, Map> localTypeMapper, Map> localValidator) { CommandPart first = null; CommandPart current = null; for (String s : subCommand) { - CommandPart commandPart = new CommandPart(command, createMapper(s), null, null, null, null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND); + CommandPart commandPart = new CommandPart(command, createMapper(s), null, null, null); commandPart.setIgnoreAsArgument(true); if (current != null) { current.setNext(commandPart); @@ -96,11 +92,10 @@ public class SWCommandUtils { Parameter parameter = parameters[i]; AbstractTypeMapper typeMapper = getTypeMapper(parameter, localTypeMapper); AbstractValidator validator = (AbstractValidator) getValidator(parameter, localValidator); - AbstractGuardChecker guardChecker = getGuardChecker(parameter, localGuardChecker); Class varArgType = parameter.isVarArgs() ? parameter.getType().getComponentType() : null; AbstractSWCommand.OptionalValue optionalValue = parameter.getAnnotation(AbstractSWCommand.OptionalValue.class); - CommandPart commandPart = new CommandPart<>(command, typeMapper, validator, guardChecker, varArgType, optionalValue != null ? optionalValue.value() : null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND); + CommandPart commandPart = new CommandPart<>(command, typeMapper, validator, varArgType, optionalValue != null ? optionalValue.value() : null); if (current != null) { current.setNext(commandPart); } @@ -203,40 +198,6 @@ public class SWCommandUtils { return validator; } - @Deprecated - public static AbstractGuardChecker getGuardChecker(Parameter parameter, Map> localGuardChecker) { - Class clazz = parameter.getType(); - if (parameter.isVarArgs()) { - clazz = clazz.getComponentType(); - } - - AbstractSWCommand.ClassGuard classGuard = parameter.getAnnotation(AbstractSWCommand.ClassGuard.class); - if (classGuard != null) { - if (classGuard.value() != null) { - return getGuardChecker(classGuard.value().getTypeName(), localGuardChecker); - } - return getGuardChecker(clazz.getTypeName(), localGuardChecker); - } - - AbstractSWCommand.Guard guard = parameter.getAnnotation(AbstractSWCommand.Guard.class); - if (guard != null) { - if (guard.value() != null && !guard.value().isEmpty()) { - return getGuardChecker(guard.value(), localGuardChecker); - } - return getGuardChecker(clazz.getTypeName(), localGuardChecker); - } - return null; - } - - @Deprecated - private static AbstractGuardChecker getGuardChecker(String s, Map> localGuardChecker) { - AbstractGuardChecker guardChecker = localGuardChecker.getOrDefault(s, (AbstractGuardChecker) GUARD_FUNCTIONS.getOrDefault(s, null)); - if (guardChecker == null) { - throw new IllegalArgumentException("No guard found for " + s); - } - return guardChecker; - } - public static void addMapper(Class clazz, AbstractTypeMapper mapper) { addMapper(clazz.getTypeName(), mapper); } @@ -253,16 +214,6 @@ public class SWCommandUtils { VALIDATOR_FUNCTIONS.putIfAbsent(name, validator); } - @Deprecated - public static void addGuard(Class clazz, AbstractGuardChecker guardChecker) { - addGuard(clazz.getTypeName(), guardChecker); - } - - @Deprecated - public static void addGuard(String name, AbstractGuardChecker guardChecker) { - GUARD_FUNCTIONS.putIfAbsent(name, guardChecker); - } - public static , K> T createMapper(String... values) { List strings = Arrays.stream(values).map(String::toLowerCase).collect(Collectors.toList()); List tabCompletes = Arrays.asList(values); diff --git a/src/de/steamwar/command/SubCommand.java b/src/de/steamwar/command/SubCommand.java index d3a266c..8626f1d 100644 --- a/src/de/steamwar/command/SubCommand.java +++ b/src/de/steamwar/command/SubCommand.java @@ -38,13 +38,12 @@ public class SubCommand { private Predicate senderPredicate; private Function senderFunction; AbstractValidator validator; - AbstractGuardChecker guardChecker; boolean noTabComplete; int comparableValue; private CommandPart commandPart; - SubCommand(AbstractSWCommand abstractSWCommand, Method method, String[] subCommand, Map> localTypeMapper, Map> localValidator, Map> localGuardChecker, boolean help, String[] description, boolean noTabComplete) { + SubCommand(AbstractSWCommand abstractSWCommand, Method method, String[] subCommand, Map> localTypeMapper, Map> localValidator, boolean help, String[] description, boolean noTabComplete) { this.abstractSWCommand = abstractSWCommand; this.method = method; this.subCommand = subCommand; @@ -55,9 +54,8 @@ public class SubCommand { comparableValue = parameters[parameters.length - 1].isVarArgs() ? Integer.MAX_VALUE : -parameters.length; validator = (AbstractValidator) SWCommandUtils.getValidator(parameters[0], localValidator); - guardChecker = SWCommandUtils.getGuardChecker(parameters[0], localGuardChecker); - commandPart = SWCommandUtils.generateCommandPart(abstractSWCommand, help, subCommand, parameters, localTypeMapper, localValidator, localGuardChecker); + commandPart = SWCommandUtils.generateCommandPart(abstractSWCommand, help, subCommand, parameters, localTypeMapper, localValidator); senderPredicate = t -> parameters[0].getType().isAssignableFrom(t.getClass()); senderFunction = t -> parameters[0].getType().cast(t); @@ -79,17 +77,6 @@ public class SubCommand { })) { throw new CommandNoHelpException(); } - } else if (guardChecker != null) { - GuardResult guardResult = guardChecker.guard(sender, GuardCheckType.COMMAND, new String[0], null); - switch (guardResult) { - case ALLOWED: - break; - case DENIED: - throw new CommandNoHelpException(); - case DENIED_WITH_HELP: - default: - return true; - } } method.setAccessible(true); method.invoke(abstractSWCommand, senderFunction.apply(sender)); @@ -102,19 +89,7 @@ public class SubCommand { })) { throw new CommandNoHelpException(); } - } else if (guardChecker != null) { - GuardResult guardResult = guardChecker.guard(sender, GuardCheckType.COMMAND, new String[0], null); - switch (guardResult) { - case ALLOWED: - break; - case DENIED: - throw new CommandNoHelpException(); - case DENIED_WITH_HELP: - default: - return true; - } } - commandPart.guardCheck(sender, args, 0); objects.add(0, senderFunction.apply(sender)); method.setAccessible(true); method.invoke(abstractSWCommand, objects.toArray()); @@ -138,8 +113,6 @@ public class SubCommand { })) { return null; } - } else if (guardChecker != null && guardChecker.guard(sender, GuardCheckType.TAB_COMPLETE, new String[0], null) != GuardResult.ALLOWED) { - return null; } if (commandPart == null) { return null; diff --git a/testsrc/de/steamwar/command/GuardCommand.java b/testsrc/de/steamwar/command/GuardCommand.java deleted file mode 100644 index 7ee1854..0000000 --- a/testsrc/de/steamwar/command/GuardCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command; - -import de.steamwar.command.dto.ExecutionIdentifier; -import de.steamwar.command.dto.TestGuardChecker; -import de.steamwar.command.dto.TestSWCommand; - -public class GuardCommand extends TestSWCommand { - - public GuardCommand() { - super("typemapper"); - } - - @Register - public void test(@Guard String sender) { - throw new ExecutionIdentifier("RunTypeMapper"); - } - - @ClassGuard(value = String.class, local = true) - public AbstractGuardChecker getGuardChecker() { - return (TestGuardChecker) (s, guardCheckType, previousArguments, s2) -> { - throw new ExecutionIdentifier("GuardChecker " + guardCheckType); - }; - } -} diff --git a/testsrc/de/steamwar/command/GuardCommandTest.java b/testsrc/de/steamwar/command/GuardCommandTest.java deleted file mode 100644 index 51eae0e..0000000 --- a/testsrc/de/steamwar/command/GuardCommandTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command; - -import de.steamwar.command.dto.ExecutionIdentifier; -import org.junit.Test; - -import static de.steamwar.AssertionUtils.assertCMDFramework; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; - -public class GuardCommandTest { - - @Test - public void test() { - GuardCommand cmd = new GuardCommand(); - try { - cmd.execute("test", "", new String[0]); - } catch (Exception e) { - assertThat(e.getMessage(), is("GuardChecker COMMAND")); - } - } - - @Test - public void testTabComplete() { - GuardCommand cmd = new GuardCommand(); - try { - cmd.tabComplete("test", "", new String[]{""}); - } catch (Exception e) { - assertThat(e, is(instanceOf(ExecutionIdentifier.class))); - assertThat(e.getMessage(), is("GuardChecker TAB_COMPLETE")); - } - } -} diff --git a/testsrc/de/steamwar/command/dto/TestGuardChecker.java b/testsrc/de/steamwar/command/dto/TestGuardChecker.java deleted file mode 100644 index b85fa17..0000000 --- a/testsrc/de/steamwar/command/dto/TestGuardChecker.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.command.dto; - -import de.steamwar.command.AbstractGuardChecker; - -public interface TestGuardChecker extends AbstractGuardChecker { -}