EasyMock with Java8 Lambdas

Sometimes the existing Java8 Lambda syntax is clumsy and hard to get. For that reason I decided to write a fairly simple snippet in the hope that it will be useful.

This one is for the case when you want to capture something produced inside the tested method and compare it against something passed by that method in other places.

class Memo {
  public void remember(A a, B b) {
    Date now = new Date();
    Date later = A.compute(now);
    B.remember(now, later);

class MemoTest {
  public voif testRemember() {
    A a = createMock(A.class);
    B b = createMock(B.class);
    final Capture<Date> now = new Capture<>();
    expect(A.compute(capture(now))).andReturn(new Date(100L));
      cmp(new Date(0L), (Date d1, Date d2) -> d1.compareTo(now.getValue()), EQUAL),
      eq(new Date(100L)));
    new Memo().remember(a, b);

This test would verify that values passed into A and B mocks are the same.