Clean up and clarify lambda parameters
This commit is contained in:
parent
a50db9ad67
commit
5064af2408
3 changed files with 15 additions and 9 deletions
|
@ -15,7 +15,10 @@ public class AfterTest {
|
|||
//given
|
||||
final List<String> events = new ArrayList<>();
|
||||
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
|
||||
final Integer result = squareDecorated.apply(2);
|
||||
//then
|
||||
|
@ -28,7 +31,7 @@ public class AfterTest {
|
|||
final Integer result,
|
||||
final List<String> events
|
||||
) {
|
||||
events.add("after " + argument + " -> " + result);
|
||||
events.add(String.format("after %d -> %d", argument, result));
|
||||
}
|
||||
|
||||
private static Integer function(
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AroundTest {
|
|||
final List<String> events = new ArrayList<>();
|
||||
final Function<Integer, Integer> squareDecorated =
|
||||
Around.decorate(
|
||||
i -> function(i, events),
|
||||
argument -> function(argument, events),
|
||||
(executable, argument) -> around(executable, argument, events)
|
||||
);
|
||||
//when
|
||||
|
|
|
@ -15,26 +15,29 @@ public class BeforeTest {
|
|||
//given
|
||||
final List<String> events = new ArrayList<>();
|
||||
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
|
||||
final Integer result = squareDecorated.apply(2);
|
||||
//then
|
||||
assertThat(result).isEqualTo(4);
|
||||
assertThat(events).containsExactly("before", "function");
|
||||
assertThat(events).containsExactly("before 2", "function");
|
||||
}
|
||||
|
||||
private static void before(
|
||||
final Integer v,
|
||||
final Integer argument,
|
||||
final List<String> events
|
||||
) {
|
||||
events.add("before");
|
||||
events.add("before " + argument);
|
||||
}
|
||||
|
||||
private static Integer function(
|
||||
final Integer i,
|
||||
final Integer argument,
|
||||
final List<String> events
|
||||
) {
|
||||
events.add("function");
|
||||
return i * i;
|
||||
return argument * argument;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue