### Question:
Condition implements Internal<Condition<S, T>, T> { public <R> Optional<R> thenMap(Function<T, R> mapper) { if (isSourceChainUpdateAccepted()) { return new Optional<>(Invoker.invoke(mapper, sourceProxy.getItem()), sourceProxy.getConfiguration()); } else { return new Optional<>(null, sourceProxy.getConfiguration()); } } 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 thenMapWithValidConditionThenReturnAnOptionalContainingMappedValue() { TestClassTwo result = new Chain<>(new TestClass(), chainConfiguration) .when(new Predicate<TestClass>() { @Override public boolean test(TestClass testClass) throws Exception { return true; } }) .thenMap(new Function<TestClass, TestClassTwo>() { @Override public TestClassTwo apply(TestClass testClass) throws Exception { return new TestClassTwo("1"); } }) .defaultIfEmpty(new TestClassTwo("2")) .call(); assertEquals("1", result.text); }
@Test public void thenMapWithInvalidConditionThenReturnAnOptionalContainingNull() { TestClassTwo result = new Chain<>(new TestClass(), chainConfiguration) .when(new Predicate<TestClass>() { @Override public boolean test(TestClass testClass) throws Exception { return false; } }) .thenMap(new Function<TestClass, TestClassTwo>() { @Override public TestClassTwo apply(TestClass testClass) throws Exception { return new TestClassTwo("1"); } }) .defaultIfEmpty(new TestClassTwo("2")) .call(); assertEquals("2", result.text); }
@Test(expected = UnsupportedOperationException.class) public void thenMapWithExceptionThenThrowException() { new Chain<>(new TestClass(), chainConfiguration) .when(new Predicate<TestClass>() { @Override public boolean test(TestClass testClass) throws Exception { return true; } }) .thenMap(new Function<TestClass, TestClassTwo>() { @Override public TestClassTwo apply(TestClass testClass) throws Exception { throw new UnsupportedOperationException(); } }); }