Dieser Commit ist enthalten in:
Ursprung
53efec2d0f
Commit
b48a25453d
@ -363,19 +363,13 @@ public abstract class AbstractSWCommand<T> {
|
||||
private boolean invert;
|
||||
|
||||
public Handler(AbstractSWCommand.Validator validator, Class<?> clazz, Map<String, AbstractValidator<T, ?>> localValidator) {
|
||||
System.out.println("Validator: " + validator + " " + clazz);
|
||||
inner = (AbstractValidator<T, Object>) 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String> testValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren