aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android
diff options
context:
space:
mode:
authorGravatar kmb <kmb@google.com>2018-02-21 21:34:01 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-21 21:36:41 -0800
commitdeb99ccfb4e6b236c21e6d425281870aa598804a (patch)
treedaf1155b4cdcbf9af657d79a3fa8fea843fd9e5e /src/test/java/com/google/devtools/build/android
parentcfb8a74908459d839c755abcc1c68bfa2ed25f2a (diff)
add ability to move individual core library methods
RELNOTES: None. PiperOrigin-RevId: 186565673
Diffstat (limited to 'src/test/java/com/google/devtools/build/android')
-rw-r--r--src/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java55
-rw-r--r--src/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java20
2 files changed, 61 insertions, 14 deletions
diff --git a/src/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java b/src/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java
index 853dbbe3b1..cc177482c9 100644
--- a/src/test/java/com/google/devtools/build/android/desugar/CoreLibrarySupportTest.java
+++ b/src/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/src/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java b/src/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java
index 0626b469fd..0ff0f25ea3 100644
--- a/src/test/java/com/google/devtools/build/android/desugar/CorePackageRenamerTest.java
+++ b/src/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");