From f3363ecedf485d9fcaac1da1f7c26203f22b0ba7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 26 Apr 2022 09:04:36 +0200 Subject: [PATCH] Add more tests --- testsrc/de/steamwar/command/GuardCommand.java | 24 ++++++++++++++ .../de/steamwar/command/GuardCommandTest.java | 33 +++++++++++++++++++ .../steamwar/command/TypeMapperCommand.java | 21 ++++++++++++ .../command/TypeMapperCommandTest.java | 17 ++++++++++ ...stTypeChecker.java => TestTypeMapper.java} | 2 +- 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 testsrc/de/steamwar/command/GuardCommand.java create mode 100644 testsrc/de/steamwar/command/GuardCommandTest.java create mode 100644 testsrc/de/steamwar/command/TypeMapperCommand.java create mode 100644 testsrc/de/steamwar/command/TypeMapperCommandTest.java rename testsrc/de/steamwar/command/dto/{TestTypeChecker.java => TestTypeMapper.java} (52%) diff --git a/testsrc/de/steamwar/command/GuardCommand.java b/testsrc/de/steamwar/command/GuardCommand.java new file mode 100644 index 0000000..4285daf --- /dev/null +++ b/testsrc/de/steamwar/command/GuardCommand.java @@ -0,0 +1,24 @@ +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 new file mode 100644 index 0000000..9937185 --- /dev/null +++ b/testsrc/de/steamwar/command/GuardCommandTest.java @@ -0,0 +1,33 @@ +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) { + assertCMDFramework(e, ExecutionIdentifier.class, "RunTypeMapper"); + } + } + + @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/TypeMapperCommand.java b/testsrc/de/steamwar/command/TypeMapperCommand.java new file mode 100644 index 0000000..466d5ca --- /dev/null +++ b/testsrc/de/steamwar/command/TypeMapperCommand.java @@ -0,0 +1,21 @@ +package de.steamwar.command; + +import de.steamwar.command.dto.ExecutionIdentifier; +import de.steamwar.command.dto.TestSWCommand; + +public class TypeMapperCommand extends TestSWCommand { + + public TypeMapperCommand() { + super("typemapper"); + } + + @Register + public void test(String sender, String s) { + throw new ExecutionIdentifier("RunTypeMapper with CustomMapper"); + } + + @ClassMapper(value = String.class, local = true) + public AbstractTypeMapper getTypeMapper() { + return SWCommandUtils.createMapper("1", "2", "3", "4", "5"); + } +} diff --git a/testsrc/de/steamwar/command/TypeMapperCommandTest.java b/testsrc/de/steamwar/command/TypeMapperCommandTest.java new file mode 100644 index 0000000..c7a20c6 --- /dev/null +++ b/testsrc/de/steamwar/command/TypeMapperCommandTest.java @@ -0,0 +1,17 @@ +package de.steamwar.command; + +import org.junit.Test; + +import java.util.List; + +import static de.steamwar.AssertionUtils.assertTabCompletes; + +public class TypeMapperCommandTest { + + @Test + public void testTabComplete() { + TypeMapperCommand cmd = new TypeMapperCommand(); + List strings = cmd.tabComplete("test", "", new String[]{""}); + assertTabCompletes(strings, "1", "2", "3", "4", "5"); + } +} diff --git a/testsrc/de/steamwar/command/dto/TestTypeChecker.java b/testsrc/de/steamwar/command/dto/TestTypeMapper.java similarity index 52% rename from testsrc/de/steamwar/command/dto/TestTypeChecker.java rename to testsrc/de/steamwar/command/dto/TestTypeMapper.java index 42a7933..edac69d 100644 --- a/testsrc/de/steamwar/command/dto/TestTypeChecker.java +++ b/testsrc/de/steamwar/command/dto/TestTypeMapper.java @@ -2,5 +2,5 @@ package de.steamwar.command.dto; import de.steamwar.command.AbstractTypeMapper; -public interface TestTypeChecker extends AbstractTypeMapper { +public interface TestTypeMapper extends AbstractTypeMapper { }