diff options
author | George Fraser <george@fivetran.com> | 2018-06-29 20:08:14 -0700 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-06-29 20:08:14 -0700 |
commit | 0297056b17b1ac2808e3ac501aee9129fe3b06e7 (patch) | |
tree | be84cd222bc0edd5c205b066e8e4999c122769f9 /src/test/java/org/javacs/ClassesTest.java | |
parent | 9b66c6aea292d1aeec178ccf69f9605cdf3b4801 (diff) | |
download | java-language-server-0297056b17b1ac2808e3ac501aee9129fe3b06e7.zip |
FIx class path indexing
Diffstat (limited to 'src/test/java/org/javacs/ClassesTest.java')
-rw-r--r-- | src/test/java/org/javacs/ClassesTest.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/ClassesTest.java b/src/test/java/org/javacs/ClassesTest.java new file mode 100644 index 0000000..f5e6d5f --- /dev/null +++ b/src/test/java/org/javacs/ClassesTest.java @@ -0,0 +1,84 @@ +package org.javacs; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import com.google.common.collect.*; +import com.google.common.reflect.*; +import java.net.*; +import java.nio.file.*; +import java.util.*; +import org.junit.*; + +public class ClassesTest { + + @Test + public void list() { + var jdk = Classes.jdkTopLevelClasses(); + assertThat(jdk.classes(), hasItem("java.util.List")); + assertThat(jdk.load("java.util.List"), not(nullValue())); + + var empty = Classes.classPathTopLevelClasses(Collections.emptySet()); + assertThat(empty.classes(), not(hasItem("java.util.List"))); + } + + @Test + public void arrayList() { + var jdk = Classes.jdkTopLevelClasses(); + assertThat(jdk.classes(), hasItem("java.util.ArrayList")); + assertThat(jdk.load("java.util.ArrayList"), not(nullValue())); + } + + @Test + public void platformClassPath() throws Exception { + var fs = FileSystems.getFileSystem(URI.create("jrt:/")); + var path = fs.getPath("/"); + Files.walk(path).forEach(p -> System.out.println(p)); + } + + @Test + public void loadMain() throws Exception { + var classes = ClassPath.from(this.getClass().getClassLoader()); + var found = classes.getTopLevelClasses("org.javacs"); + assertThat(found, hasItem(hasToString("org.javacs.Main"))); + + var main = found.stream().filter(c -> c.getName().equals("org.javacs.Main")).findFirst(); + assertTrue(main.isPresent()); + + var load = main.get().load(); + assertNotNull(load); + } + + @Test + public void loadList() throws Exception { + var classes = ClassPath.from(ClassLoader.getPlatformClassLoader()); + var found = classes.getTopLevelClasses("java.util"); + assertThat(found, not(empty())); + assertThat(found, hasItem(hasToString("java.util.List"))); + + var list = found.stream().filter(c -> c.getName().equals("java.util.List")).findFirst(); + assertTrue(list.isPresent()); + + var load = list.get().load(); + assertNotNull(load); + } + + void ancestors(ClassLoader classLoader) { + while (classLoader != null) { + System.out.println(classLoader.toString()); + classLoader = classLoader.getParent(); + } + } + + @Test + public void printAncestors() throws Exception { + System.out.println("This:"); + ancestors(this.getClass().getClassLoader()); + System.out.println("List:"); + ancestors(java.util.List.class.getClassLoader()); + System.out.println("System:"); + ancestors(ClassLoader.getSystemClassLoader()); + System.out.println("Platform:"); + ancestors(ClassLoader.getPlatformClassLoader()); + } +} |