Skip to content

Commit

Permalink
Fixed #55 Add tests for various Lambda Method Reference calling patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Apr 3, 2018
1 parent fcfff56 commit f6af743
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,43 @@ public void testLambda() {
};
}

interface Adder {
int add(int aValue);
}

public static int add(int aValue) {
return aValue + 1;
}

public int addMethodRef(int aValue) {
return aValue + 1;
}

public int add(Adder adder) {
return adder.add(10);
}

@Test
public void testLambdaArguments() {
int theResult = computeWith((x,y) -> x + y, 10, 20);
Assert.assertEquals(theResult, 30, 0);
}

@Test
public void testLambdaAdd() {
int theResult = add((i) -> i + 10);
Assert.assertEquals(20, theResult, 0);
}

@Test
public void testStaticMethodRefAdd() {
int theResult = add(InvokeDynamicTest::add);
Assert.assertEquals(11, theResult, 0);
}

@Test
public void testInstanceMethodRefAdd() {
int theResult = add(this::addMethodRef);
Assert.assertEquals(11, theResult, 0);
}
}

0 comments on commit f6af743

Please sign in to comment.