Dieser Commit ist enthalten in:
Ursprung
53efec2d0f
Commit
b48a25453d
@ -363,19 +363,13 @@ public abstract class AbstractSWCommand<T> {
|
|||||||
private boolean invert;
|
private boolean invert;
|
||||||
|
|
||||||
public Handler(AbstractSWCommand.Validator validator, Class<?> clazz, Map<String, AbstractValidator<T, ?>> localValidator) {
|
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);
|
inner = (AbstractValidator<T, Object>) SWCommandUtils.getValidator(validator, clazz, localValidator);
|
||||||
invert = validator.invert();
|
invert = validator.invert();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validate(T sender, Object value, MessageSender messageSender) {
|
public boolean validate(T sender, Object value, MessageSender messageSender) {
|
||||||
System.out.println("Validator: " + inner + " " + invert);
|
return inner.validate(sender, value, messageSender) ^ invert;
|
||||||
if (invert) {
|
|
||||||
return !inner.validate(sender, value, messageSender);
|
|
||||||
} else {
|
|
||||||
return inner.validate(sender, value, messageSender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,12 @@ public class InvertValidatorCommand extends TestSWCommand {
|
|||||||
throw new ExecutionIdentifier("RunTestInvert");
|
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)
|
@Validator(value = "Text", local = true)
|
||||||
public TestValidator<String> testValidator() {
|
public TestValidator<String> testValidator() {
|
||||||
return (sender, value, messageSender) -> {
|
return (sender, value, messageSender) -> {
|
||||||
|
@ -71,4 +71,15 @@ public class ValidatorCommandTest {
|
|||||||
assertCMDFramework(e, ExecutionIdentifier.class, "RunTestInvert");
|
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