### Question:
Condition implements Internal<Condition<S, T>, T> { public S invoke(Action action) { if (isSourceChainUpdateAccepted()) Invoker.invoke(action); return sourceProxy.owner(); } private  Condition(S source, Predicate<T> predicate, boolean negateExpression); S then(Consumer<T> action); S invoke(Action action); Optional<R> thenMap(Function<T, R> mapper); Optional<R> thenTo(@NonNull R item); Optional<R> thenTo(@NonNull Callable<R> itemCallable); Logger<Condition<S, T>, T> log(Object tag); @Override Proxy<Condition<S, T>, T> access();  }### Answer:
@Test public void whenNotWithTruePredicateThenDoNotInvokeAction() { final boolean[] result = {false}; new Chain<>(new TestClass(), chainConfiguration) .apply(new Consumer<TestClass>() { @Override public void accept(@NonNull TestClass testClass) throws Exception { testClass.setText("!"); } }) .whenNot(new Predicate<TestClass>() { @Override public boolean test(@NonNull TestClass testClass) throws Exception { return testClass.text.equals("!"); } }) .invoke(new Action() { @Override public void run() throws Exception { result[0] = true; } }) .call(); assertFalse(result[0]); }
@Test public void whenNotWithFalsePredicateThenInvokeAction() { final boolean[] result = {false}; TestClass testClass = new Chain<>(new TestClass(), chainConfiguration) .apply(new Consumer<TestClass>() { @Override public void accept(@NonNull TestClass testClass) throws Exception { testClass.setText("!"); } }) .whenNot(new Predicate<TestClass>() { @Override public boolean test(@NonNull TestClass testClass) throws Exception { return false; } }) .invoke(new Action() { @Override public void run() throws Exception { result[0] = true; } }) .call(); assertTrue(result[0]); }
@Test(expected = UnsupportedOperationException.class) public void invokeActionWithExceptionThenThrowException() { new Chain<>(new TestClass(), chainConfiguration) .apply(new Consumer<TestClass>() { @Override public void accept(@NonNull TestClass testClass) throws Exception { testClass.setText("!"); } }) .when(new Predicate<TestClass>() { @Override public boolean test(@NonNull TestClass testClass) throws Exception { return testClass.text.equals("!"); } }) .invoke(new Action() { @Override public void run() throws Exception { throw new UnsupportedOperationException(); } }) .call(); }
@Test public void whenWithTruePredicateThenInvokeAction() { final boolean[] result = {false}; new Chain<>(new TestClass(), chainConfiguration) .apply(new Consumer<TestClass>() { @Override public void accept(@NonNull TestClass testClass) throws Exception { testClass.setText("!"); } }) .when(new Predicate<TestClass>() { @Override public boolean test(@NonNull TestClass testClass) throws Exception { return testClass.text.equals("!"); } }) .invoke(new Action() { @Override public void run() throws Exception { result[0] = true; } }) .call(); assertTrue(result[0]); }
@Test public void whenWithFalsePredicateThenDoNotInvokeAction() { final boolean[] result = {false}; TestClass testClass = new Chain<>(new TestClass(), chainConfiguration) .apply(new Consumer<TestClass>() { @Override public void accept(@NonNull TestClass testClass) throws Exception { testClass.setText("!"); } }) .when(new Predicate<TestClass>() { @Override public boolean test(@NonNull TestClass testClass) throws Exception { return false; } }) .invoke(new Action() { @Override public void run() throws Exception { result[0] = true; } }) .call(); assertFalse(result[0]); }