diff options
Diffstat (limited to 'src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java')
-rw-r--r-- | src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java index a7cb666291..341fa013a0 100644 --- a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java +++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java @@ -36,7 +36,8 @@ public class ClassCacheTest extends AbstractClassCacheTest { @Test public void testLibraryJar() throws Exception { try (ClassCache cache = - new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryJar))) { + new ClassCache( + ImmutableList.of(bootclasspath), ImmutableList.of(libraryJar), ImmutableList.of())) { assertCache( cache, libraryJarPositives, @@ -52,7 +53,8 @@ public class ClassCacheTest extends AbstractClassCacheTest { try (ClassCache cache = new ClassCache( ImmutableList.of(bootclasspath), - ImmutableList.of(clientJar, libraryJar, libraryInterfaceJar))) { + ImmutableList.of(libraryJar, libraryInterfaceJar), + ImmutableList.of(clientJar))) { assertCache( cache, clientJarPositives, @@ -63,7 +65,8 @@ public class ClassCacheTest extends AbstractClassCacheTest { @Test public void testClientJarWithoutSuperClasses() throws IOException { try (ClassCache cache = - new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(clientJar))) { + new ClassCache( + ImmutableList.of(bootclasspath), ImmutableList.of(), ImmutableList.of(clientJar))) { // Client should be incomplete, as its parent class and interfaces are not available on the // classpath. The following is the resolution path. { @@ -86,7 +89,10 @@ public class ClassCacheTest extends AbstractClassCacheTest { @Test public void testLibraryException() throws IOException { try (ClassCache cache = - new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryExceptionJar))) { + new ClassCache( + ImmutableList.of(bootclasspath), + ImmutableList.of(), + ImmutableList.of(libraryExceptionJar))) { assertCache( cache, libraryExceptionJarPositives, @@ -97,7 +103,10 @@ public class ClassCacheTest extends AbstractClassCacheTest { @Test public void testLibraryAnnotations() throws IOException { try (ClassCache cache = - new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryAnnotationsJar))) { + new ClassCache( + ImmutableList.of(bootclasspath), + ImmutableList.of(), + ImmutableList.of(libraryAnnotationsJar))) { assertCache( cache, libraryAnnotationsJarPositives, @@ -107,7 +116,7 @@ public class ClassCacheTest extends AbstractClassCacheTest { @Test public void testCannotAccessClosedCache() throws IOException { - ClassCache cache = new ClassCache(ImmutableList.of(), ImmutableList.of()); + ClassCache cache = new ClassCache(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()); cache.close(); cache.close(); // Can close multiple times. assertThrows(IllegalStateException.class, () -> cache.getClassState("empty")); @@ -122,8 +131,8 @@ public class ClassCacheTest extends AbstractClassCacheTest { try (ClassCache cache = new ClassCache( ImmutableList.of(), - ImmutableList.of( - libraryJar, libraryJar, libraryAnnotationsJar, libraryInterfaceJar, clientJar))) { + ImmutableList.of(libraryJar, libraryJar, libraryAnnotationsJar, libraryInterfaceJar), + ImmutableList.of(clientJar))) { assertThat( cache .getClassState("com/google/devtools/build/importdeps/testdata/Library$Class9") @@ -138,10 +147,45 @@ public class ClassCacheTest extends AbstractClassCacheTest { } @Test + public void testJdepsOutput() throws IOException { + try (ClassCache cache = + new ClassCache( + ImmutableList.of(), + ImmutableList.of(libraryJar, libraryJar, libraryAnnotationsJar, libraryInterfaceJar), + ImmutableList.of(clientJar))) { + assertThat( + cache + .getClassState("com/google/devtools/build/importdeps/testdata/Library$Class9") + .isIncompleteState()) + .isTrue(); + assertThat(cache.collectUsedJarsInRegularClasspath()).containsExactly(libraryJar); + + assertThat( + cache + .getClassState("com/google/devtools/build/importdeps/testdata/LibraryAnnotations") + .isIncompleteState()) + .isTrue(); + assertThat(cache.collectUsedJarsInRegularClasspath()) + .containsExactly(libraryJar, libraryAnnotationsJar); + + assertThat( + cache + .getClassState("com/google/devtools/build/importdeps/testdata/LibraryInterface") + .isIncompleteState()) + .isTrue(); + assertThat(cache.collectUsedJarsInRegularClasspath()) + .containsExactly(libraryJar, libraryAnnotationsJar, libraryInterfaceJar); + } + } + + @Test public void testLazyClasspathLoadsBootclasspathFirst() throws IOException { { LazyClasspath classpath = - new LazyClasspath(ImmutableList.of(libraryJar), ImmutableList.of(libraryWoMembersJar)); + new LazyClasspath( + ImmutableList.of(libraryJar), + ImmutableList.of(libraryWoMembersJar), + ImmutableList.of()); LazyClassEntry entry = classpath.getLazyEntry("com/google/devtools/build/importdeps/testdata/Library$Class4"); AbstractClassEntryState state = entry.getState(classpath); @@ -159,7 +203,10 @@ public class ClassCacheTest extends AbstractClassCacheTest { } { LazyClasspath classpath = - new LazyClasspath(ImmutableList.of(libraryWoMembersJar), ImmutableList.of(libraryJar)); + new LazyClasspath( + ImmutableList.of(libraryWoMembersJar), + ImmutableList.of(libraryJar), + ImmutableList.of()); LazyClassEntry entry = classpath.getLazyEntry("com/google/devtools/build/importdeps/testdata/Library$Class4"); AbstractClassEntryState state = entry.getState(classpath); |