Clean up and clarify lambda parameters

This commit is contained in:
Paul Campbell 2017-12-12 23:35:39 +00:00
parent a50db9ad67
commit 5064af2408
3 changed files with 15 additions and 9 deletions

View file

@ -15,7 +15,10 @@ public class AfterTest {
//given //given
final List<String> events = new ArrayList<>(); final List<String> events = new ArrayList<>();
final Function<Integer, Integer> squareDecorated = final Function<Integer, Integer> squareDecorated =
After.decorate(i -> function(i, events), (v, r) -> after(v, r, events)); After.decorate(
argument -> function(argument, events),
(argument, result) -> after(argument, result, events)
);
//when //when
final Integer result = squareDecorated.apply(2); final Integer result = squareDecorated.apply(2);
//then //then
@ -28,7 +31,7 @@ public class AfterTest {
final Integer result, final Integer result,
final List<String> events final List<String> events
) { ) {
events.add("after " + argument + " -> " + result); events.add(String.format("after %d -> %d", argument, result));
} }
private static Integer function( private static Integer function(

View file

@ -16,7 +16,7 @@ public class AroundTest {
final List<String> events = new ArrayList<>(); final List<String> events = new ArrayList<>();
final Function<Integer, Integer> squareDecorated = final Function<Integer, Integer> squareDecorated =
Around.decorate( Around.decorate(
i -> function(i, events), argument -> function(argument, events),
(executable, argument) -> around(executable, argument, events) (executable, argument) -> around(executable, argument, events)
); );
//when //when

View file

@ -15,26 +15,29 @@ public class BeforeTest {
//given //given
final List<String> events = new ArrayList<>(); final List<String> events = new ArrayList<>();
final Function<Integer, Integer> squareDecorated = final Function<Integer, Integer> squareDecorated =
Before.decorate(v -> before(v, events), i -> function(i, events)); Before.decorate(
argument -> before(argument, events),
argument -> function(argument, events)
);
//when //when
final Integer result = squareDecorated.apply(2); final Integer result = squareDecorated.apply(2);
//then //then
assertThat(result).isEqualTo(4); assertThat(result).isEqualTo(4);
assertThat(events).containsExactly("before", "function"); assertThat(events).containsExactly("before 2", "function");
} }
private static void before( private static void before(
final Integer v, final Integer argument,
final List<String> events final List<String> events
) { ) {
events.add("before"); events.add("before " + argument);
} }
private static Integer function( private static Integer function(
final Integer i, final Integer argument,
final List<String> events final List<String> events
) { ) {
events.add("function"); events.add("function");
return i * i; return argument * argument;
} }
} }