summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkmb <kmb@google.com>2018-02-21 21:34:01 -0800
committerIvan Gavrilovic <gavra@google.com>2018-05-04 10:38:35 +0100
commit4f68e2ecebee00ab4fe882c691bb750ce6dab64b (patch)
tree4ac7a68d7074b820723e7f6d503569dd81503d1c /test
parent669a724b8244e89d40ffd2ea0390d05c078857a3 (diff)
downloaddesugar-4f68e2ecebee00ab4fe882c691bb750ce6dab64b.tar.gz
add ability to move individual core library methods
RELNOTES: None. PiperOrigin-RevId: 186565673 GitOrigin-RevId: deb99ccfb4e6b236c21e6d425281870aa598804a Change-Id: I56030d75aa6b3666299aa98ec961ef7078917975
Diffstat (limited to 'test')
-rw-r--r--test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java55
-rw-r--r--test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java20
2 files changed, 61 insertions, 14 deletions
diff --git a/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java b/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java
index 853dbbe..cc17748 100644
--- a/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java
+++ b/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java
@@ -32,7 +32,11 @@ public class CoreLibrarySupportTest {
public void testIsRenamedCoreLibrary() throws Exception {
CoreLibrarySupport support =
new CoreLibrarySupport(
- new CoreLibraryRewriter(""), null, ImmutableList.of("java/time/"), ImmutableList.of());
+ new CoreLibraryRewriter(""),
+ null,
+ ImmutableList.of("java/time/"),
+ ImmutableList.of(),
+ ImmutableList.of());
assertThat(support.isRenamedCoreLibrary("java/time/X")).isTrue();
assertThat(support.isRenamedCoreLibrary("java/time/y/X")).isTrue();
assertThat(support.isRenamedCoreLibrary("java/io/X")).isFalse();
@@ -48,6 +52,7 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter("__/"),
null,
ImmutableList.of("java/time/"),
+ ImmutableList.of(),
ImmutableList.of());
assertThat(support.isRenamedCoreLibrary("__/java/time/X")).isTrue();
assertThat(support.isRenamedCoreLibrary("__/java/time/y/X")).isTrue();
@@ -60,7 +65,11 @@ public class CoreLibrarySupportTest {
public void testRenameCoreLibrary() throws Exception {
CoreLibrarySupport support =
new CoreLibrarySupport(
- new CoreLibraryRewriter(""), null, ImmutableList.of(), ImmutableList.of());
+ new CoreLibraryRewriter(""),
+ null,
+ ImmutableList.of(),
+ ImmutableList.of(),
+ ImmutableList.of());
assertThat(support.renameCoreLibrary("java/time/X")).isEqualTo("j$/time/X");
assertThat(support.renameCoreLibrary("com/google/X")).isEqualTo("com/google/X");
}
@@ -69,19 +78,39 @@ public class CoreLibrarySupportTest {
public void testRenameCoreLibrary_prefixedLoader() throws Exception {
CoreLibrarySupport support =
new CoreLibrarySupport(
- new CoreLibraryRewriter("__/"), null, ImmutableList.of(), ImmutableList.of());
+ new CoreLibraryRewriter("__/"),
+ null,
+ ImmutableList.of(),
+ ImmutableList.of(),
+ ImmutableList.of());
assertThat(support.renameCoreLibrary("__/java/time/X")).isEqualTo("j$/time/X");
assertThat(support.renameCoreLibrary("com/google/X")).isEqualTo("com/google/X");
}
@Test
+ public void testMoveTarget() throws Exception {
+ CoreLibrarySupport support =
+ new CoreLibrarySupport(
+ new CoreLibraryRewriter("__/"),
+ null,
+ ImmutableList.of("java/util/Helper"),
+ ImmutableList.of(),
+ ImmutableList.of("java/util/Existing#match -> java/util/Helper"));
+ assertThat(support.getMoveTarget("__/java/util/Existing", "match")).isEqualTo("j$/util/Helper");
+ assertThat(support.getMoveTarget("java/util/Existing", "match")).isEqualTo("j$/util/Helper");
+ assertThat(support.getMoveTarget("__/java/util/Existing", "matchesnot")).isNull();
+ assertThat(support.getMoveTarget("__/java/util/ExistingOther", "match")).isNull();
+ }
+
+ @Test
public void testIsEmulatedCoreClassOrInterface() throws Exception {
CoreLibrarySupport support =
new CoreLibrarySupport(
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of("java/util/concurrent/"),
- ImmutableList.of("java/util/Map"));
+ ImmutableList.of("java/util/Map"),
+ ImmutableList.of());
assertThat(support.isEmulatedCoreClassOrInterface("java/util/Map")).isTrue();
assertThat(support.isEmulatedCoreClassOrInterface("java/util/Map$$Lambda$17")).isFalse();
assertThat(support.isEmulatedCoreClassOrInterface("java/util/Map$$CC")).isFalse();
@@ -98,7 +127,8 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of(),
- ImmutableList.of("java/util/Collection"));
+ ImmutableList.of("java/util/Collection"),
+ ImmutableList.of());
assertThat(
support.getCoreInterfaceRewritingTarget(
Opcodes.INVOKEINTERFACE,
@@ -132,7 +162,8 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of(),
- ImmutableList.of("java/util/Collection"));
+ ImmutableList.of("java/util/Collection"),
+ ImmutableList.of());
assertThat(
support.getCoreInterfaceRewritingTarget(
Opcodes.INVOKEINTERFACE,
@@ -158,7 +189,8 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of(),
- ImmutableList.of("java/util/Map"));
+ ImmutableList.of("java/util/Map"),
+ ImmutableList.of());
assertThat(
support.getCoreInterfaceRewritingTarget(
Opcodes.INVOKEINTERFACE,
@@ -192,7 +224,8 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of(),
- ImmutableList.of("java/util/Comparator"));
+ ImmutableList.of("java/util/Comparator"),
+ ImmutableList.of());
assertThat(
support.getCoreInterfaceRewritingTarget(
Opcodes.INVOKESTATIC,
@@ -208,12 +241,13 @@ public class CoreLibrarySupportTest {
* {@link InterfaceDesugaring}.
*/
@Test
- public void testGetEmulatedCoreLibraryInvocationTarget_renamed() throws Exception {
+ public void testGetCoreInterfaceRewritingTarget_renamed() throws Exception {
CoreLibrarySupport support =
new CoreLibrarySupport(
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of("java/util/"),
+ ImmutableList.of(),
ImmutableList.of());
// regular invocations of default methods: ignored
@@ -281,7 +315,8 @@ public class CoreLibrarySupportTest {
new CoreLibraryRewriter(""),
Thread.currentThread().getContextClassLoader(),
ImmutableList.of("java/util/concurrent/"), // should return null for these
- ImmutableList.of("java/util/Map"));
+ ImmutableList.of("java/util/Map"),
+ ImmutableList.of());
assertThat(
support.getCoreInterfaceRewritingTarget(
Opcodes.INVOKEINTERFACE,
diff --git a/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java b/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java
index 0626b46..0ff0f25 100644
--- a/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java
+++ b/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java
@@ -29,10 +29,15 @@ public class CorePackageRenamerTest {
@Test
public void testSymbolRewrite() throws Exception {
MockClassVisitor out = new MockClassVisitor();
- CorePackageRenamer renamer = new CorePackageRenamer(
- out,
- new CoreLibrarySupport(
- new CoreLibraryRewriter(""), null, ImmutableList.of("java/time/"), ImmutableList.of()));
+ CorePackageRenamer renamer =
+ new CorePackageRenamer(
+ out,
+ new CoreLibrarySupport(
+ new CoreLibraryRewriter(""),
+ null,
+ ImmutableList.of("java/time/"),
+ ImmutableList.of(),
+ ImmutableList.of("java/util/A#m->java/time/B")));
MethodVisitor mv = renamer.visitMethod(0, "test", "()V", null, null);
mv.visitMethodInsn(
@@ -40,6 +45,13 @@ public class CorePackageRenamerTest {
assertThat(out.mv.owner).isEqualTo("j$/time/Instant");
assertThat(out.mv.desc).isEqualTo("()Lj$/time/Instant;");
+ // Ignore moved methods but not their descriptors
+ mv.visitMethodInsn(
+ Opcodes.INVOKESTATIC, "java/util/A", "m", "()Ljava/time/Instant;", false);
+ assertThat(out.mv.owner).isEqualTo("java/util/A");
+ assertThat(out.mv.desc).isEqualTo("()Lj$/time/Instant;");
+
+ // Ignore arbitrary other methods but not their descriptors
mv.visitMethodInsn(
Opcodes.INVOKESTATIC, "other/time/Instant", "now", "()Ljava/time/Instant;", false);
assertThat(out.mv.owner).isEqualTo("other/time/Instant");