From b48a25453d89218f33987af532c83ad6b074b3af Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Mar 2023 12:35:44 +0100 Subject: [PATCH] Hotfix the hotfix for Validator --- src/de/steamwar/command/AbstractSWCommand.java | 8 +------- .../de/steamwar/command/InvertValidatorCommand.java | 6 ++++++ testsrc/de/steamwar/command/ValidatorCommandTest.java | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index bda6e90..b8dc078 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -363,19 +363,13 @@ public abstract class AbstractSWCommand { private boolean invert; public Handler(AbstractSWCommand.Validator validator, Class clazz, Map> localValidator) { - System.out.println("Validator: " + validator + " " + clazz); inner = (AbstractValidator) SWCommandUtils.getValidator(validator, clazz, localValidator); invert = validator.invert(); } @Override public boolean validate(T sender, Object value, MessageSender messageSender) { - System.out.println("Validator: " + inner + " " + invert); - if (invert) { - return !inner.validate(sender, value, messageSender); - } else { - return inner.validate(sender, value, messageSender); - } + return inner.validate(sender, value, messageSender) ^ invert; } } } diff --git a/testsrc/de/steamwar/command/InvertValidatorCommand.java b/testsrc/de/steamwar/command/InvertValidatorCommand.java index 505d09b..076d77a 100644 --- a/testsrc/de/steamwar/command/InvertValidatorCommand.java +++ b/testsrc/de/steamwar/command/InvertValidatorCommand.java @@ -35,6 +35,12 @@ public class InvertValidatorCommand extends TestSWCommand { throw new ExecutionIdentifier("RunTestInvert"); } + @Register + public void test(String sender, @Validator(value = "Text", invert = true) String h, int i) { + System.out.println("test: " + sender + " " + h + " " + i); + throw new ExecutionIdentifier("RunTestInvert2"); + } + @Validator(value = "Text", local = true) public TestValidator testValidator() { return (sender, value, messageSender) -> { diff --git a/testsrc/de/steamwar/command/ValidatorCommandTest.java b/testsrc/de/steamwar/command/ValidatorCommandTest.java index 084f53e..9f55f97 100644 --- a/testsrc/de/steamwar/command/ValidatorCommandTest.java +++ b/testsrc/de/steamwar/command/ValidatorCommandTest.java @@ -71,4 +71,15 @@ public class ValidatorCommandTest { assertCMDFramework(e, ExecutionIdentifier.class, "RunTestInvert"); } } + + @Test + public void testInvertOther() { + InvertValidatorCommand cmd = new InvertValidatorCommand(); + try { + cmd.execute("test", "", new String[]{"Hello", "0"}); + assertThat(true, is(false)); + } catch (Exception e) { + assertCMDFramework(e, ExecutionIdentifier.class, "RunTestInvert2"); + } + } }