1. Introduction
in progress…
Initially generated by using generator-jvm yeoman generator (java)
2. Implementation
2.1. predicate (java 7 API):
impl
public class Java7Predicate {
public interface MyPredicate {
boolean test(final String value);
}
@RequiredArgsConstructor
public static class Is implements MyPredicate {
final String value;
@Override
public boolean test(String value) {
return value != null && value.contains(this.value);
}
}
public static class IsRed implements MyPredicate {
@Override
public boolean test(final String value) {
return nonNull(value) && value.toLowerCase().contains("red");
}
}
public static void sideEffect(final MyPredicate predicate) {
final List<String> list = Arrays.asList("ololo", "trololo", "red", "blue", "green", "red devil");
for (String i : list) {
if (predicate.test(i)) {
System.out.println("i = " + i);
}
}
}
}
test
@Slf4j
@CaptureSystemOutput
@DisplayName("test predicate API: java 7")
class Java7PredicateTest {
@Test
@DisplayName("test positive")
void testPredicate(final CaptureSystemOutput.OutputCapture outputCapture) {
assertAll(() -> {
sideEffect(new Java7Predicate.IsRed());
Assertions.assertThat(outputCapture.toString())
.contains("i = red", "i = red devil");
sideEffect(new Java7Predicate.Is("green"));
Assertions.assertThat(outputCapture.toString().contains("t = green"));
});
}
}