Skip to content

Commit

Permalink
Failing test for lambda impl methods being treated the same way as de…
Browse files Browse the repository at this point in the history
…fault methods

Reproduces #48
  • Loading branch information
luontola committed Apr 14, 2015
1 parent f0ad5a8 commit fe6c8e5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package net.orfjackal.retrolambda.test;

import net.orfjackal.retrolambda.test.anotherpackage.UsesLambdasInAnotherPackage;
import org.apache.commons.lang.SystemUtils;
import org.hamcrest.*;
import org.junit.*;
Expand Down Expand Up @@ -444,7 +445,7 @@ public void lambdas_with_default_methods() {
public void default_methods_with_lambdas() throws Exception {
UsesLambdas obj = new UsesLambdas() {
};
assertThat(obj.foo().call(), is("foo"));
assertThat(obj.stateless().call(), is("foo"));
}

@Test
Expand All @@ -455,15 +456,31 @@ public void default_methods_with_lambdas_that_capture_this() throws Exception {
}

private interface UsesLambdas {
default Callable<String> foo() {
default Callable<String> stateless() {
return () -> "foo";
}

default Callable<String> captureThis() {
return () -> foo().call();
return () -> stateless().call();
}
}

/**
* Lambdas which capture this in default methods will generate the lambda implementation
* method as a private <em>instance</em> method. We must avoid copying those methods to
* the interface implementers as if they were default methods.
*/
@Test
public void default_methods_with_lambdas_in_another_package() throws Exception {
System.out.println("DefaultMethodsTest.default_methods_with_lambdas_in_another_package");
UsesLambdasInAnotherPackage obj = new UsesLambdasInAnotherPackage() {
};
assertThat(obj.stateless().call(), is("foo"));
assertThat(obj.captureThis().call(), is("foo"));
assertThat("should contain only delegates to the two default methods",
obj.getClass().getDeclaredMethods(), arrayWithSize(2));
}


/**
* We're unable to backport default methods if we cannot modify the interface,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

package net.orfjackal.retrolambda.test.anotherpackage;

import java.util.concurrent.Callable;

public interface UsesLambdasInAnotherPackage {

default Callable<String> stateless() {
return () -> "foo";
}

default Callable<String> captureThis() {
return () -> stateless().call();
}
}

0 comments on commit fe6c8e5

Please sign in to comment.