-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for lambdas with marker interfaces
Fixes #62
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
retrolambda/src/test/java/net/orfjackal/retrolambda/lambdas/TypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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.lambdas; | ||
|
||
import org.junit.Test; | ||
import org.objectweb.asm.*; | ||
|
||
import java.lang.invoke.*; | ||
import java.util.function.Predicate; | ||
|
||
import static net.orfjackal.retrolambda.lambdas.Types.asmToJdkType; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@SuppressWarnings("UnnecessaryLocalVariable") | ||
public class TypesTest { | ||
|
||
private ClassLoader classLoader = getClass().getClassLoader(); | ||
private MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
|
||
@Test | ||
public void asmToJdkType_MethodType() throws Exception { | ||
Type input = Type.getMethodType("(I)Ljava/util/function/Predicate;"); | ||
MethodType output = MethodType.methodType(Predicate.class, int.class); | ||
|
||
assertThat(asmToJdkType(input, classLoader, lookup), is(output)); | ||
} | ||
|
||
@Test | ||
public void asmToJdkType_MethodHandle() throws Exception { | ||
Handle input = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;"); | ||
MethodHandle output = lookup.findStatic(String.class, "valueOf", MethodType.methodType(String.class, int.class)); | ||
|
||
assertThat(asmToJdkType(input, classLoader, lookup).toString(), is(output.toString())); | ||
} | ||
|
||
@Test | ||
public void asmToJdkType_Class() throws Exception { | ||
Type input = Type.getType(String.class); | ||
Class<?> output = String.class; | ||
|
||
assertThat(asmToJdkType(input, classLoader, lookup), is(equalTo(output))); | ||
} | ||
|
||
@Test | ||
public void asmToJdkType_everything_else() throws Exception { | ||
String input = "foo"; | ||
String output = input; | ||
|
||
assertThat(asmToJdkType(input, classLoader, lookup), is(output)); | ||
} | ||
} |