Skip to content

Commit

Permalink
Merge pull request #112 from caarmen/issue-109-unit-test
Browse files Browse the repository at this point in the history
Issue #109: Add unit test to make sure child lambdas don't hide parent lambdas
  • Loading branch information
luontola authored Jan 10, 2017
2 parents b734ee8 + 5ec03ca commit abd862d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion end-to-end-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<skipTests>false</skipTests>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;

import static net.orfjackal.retrolambda.test.TestUtil.assertClassExists;
Expand Down Expand Up @@ -82,6 +83,35 @@ public void enclosing_classes_contain_no_unnecessary_methods_in_addition_to_the_
assertThat("capturing lambda", getMethodsNames(Capturing.class), contains(startsWith("lambda$new$")));
}

private class Parent {
protected void foo() {
Runnable lambda = () -> {
System.out.println("parent");
};
}
}

private class Child extends Parent {
@Override
protected void foo() {
super.foo();
Runnable lambda = () -> {
System.out.println("child");
};
}
}

@Test
public void child_class_lambda_doesnt_hide_parent_class_lambda() {
Method[] methods = Child.class.getDeclaredMethods();
Set<String> parentMethods = getMethodsNames(Parent.class);
for (Method method : methods) {
if (method.getName().startsWith("lambda$") && !Modifier.isPrivate(method.getModifiers())) {
assertThat("child lambda " + method.getName() + " overrides parent", parentMethods, not(hasItem(method.getName())));
}
}
}

@Test
public void does_not_contain_references_to_JDK_lambda_classes() throws IOException {
ClassReader cr = new ClassReader("net/orfjackal/retrolambda/test/LambdaClassesTest$Dummy1$$Lambda$1");
Expand Down

0 comments on commit abd862d

Please sign in to comment.