Skip to content

Commit

Permalink
Merge pull request #1 from caarmen/issue-109-unit-test
Browse files Browse the repository at this point in the history
Issue luontola#109: Add unit test to make sure child lambdas don't hide paren…
  • Loading branch information
caarmen authored Sep 19, 2016
2 parents 93ff6ad + fa0f5a5 commit 88cb0a9
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -8,6 +8,7 @@
import org.junit.Test;

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 @@ -80,6 +81,34 @@ 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())));
}
}
}

// helpers

Expand Down

0 comments on commit 88cb0a9

Please sign in to comment.