summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2019-01-08 00:10:18 -0800
committerGeorge Fraser <george@fivetran.com>2019-01-08 00:10:18 -0800
commit46e72551e73f1de2417102fd3d7fbc358a42cfa6 (patch)
treec6bce16cec95ebd660657b4dd662cb3ec754a82a /src/test
parent297dd5f8fb1c72f5807595c3029acf40ce6afcd9 (diff)
downloadjava-language-server-46e72551e73f1de2417102fd3d7fbc358a42cfa6.zip
Hide module-info.java
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/javacs/SourceFileManagerTest.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/SourceFileManagerTest.java b/src/test/java/org/javacs/SourceFileManagerTest.java
new file mode 100644
index 0000000..ab40c5e
--- /dev/null
+++ b/src/test/java/org/javacs/SourceFileManagerTest.java
@@ -0,0 +1,69 @@
+package org.javacs;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.util.*;
+import java.util.logging.Logger;
+import javax.tools.*;
+import org.junit.Test;
+
+public class SourceFileManagerTest {
+ static final Path src = LanguageServerFixture.DEFAULT_WORKSPACE_ROOT.resolve("src");
+ static final Path classes = LanguageServerFixture.DEFAULT_WORKSPACE_ROOT.resolve("target/classes");
+ final SourceFileManager sourceFileManager = createSourceFileManager();
+ final StandardJavaFileManager standardFileManager = createDelegateFileManager();
+
+ private static SourceFileManager createSourceFileManager() {
+ var fileManager = new SourceFileManager(Set.of(src));
+ try {
+ fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, List.of(src));
+ fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(classes));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return fileManager;
+ }
+
+ private static StandardJavaFileManager createDelegateFileManager() {
+ var compiler = ServiceLoader.load(JavaCompiler.class).iterator().next();
+ var fileManager =
+ compiler.getStandardFileManager(
+ err -> LOG.severe(err.getMessage(null)), null, Charset.defaultCharset());
+ try {
+ fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, List.of(src));
+ fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(classes));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return fileManager;
+ }
+
+ @Test
+ public void binaryNameOfPackagePrivateClass() throws IOException {
+ var standardJava =
+ standardFileManager.getJavaFileForInput(
+ StandardLocation.SOURCE_PATH, "com.example.PackagePrivate", JavaFileObject.Kind.SOURCE);
+ var standardClass =
+ standardFileManager.getJavaFileForInput(
+ StandardLocation.CLASS_PATH, "com.example.PackagePrivate", JavaFileObject.Kind.CLASS);
+ var sourceJava =
+ sourceFileManager.getJavaFileForInput(
+ StandardLocation.SOURCE_PATH, "com.example.PackagePrivate", JavaFileObject.Kind.SOURCE);
+ var sourceClass =
+ sourceFileManager.getJavaFileForInput(
+ StandardLocation.CLASS_PATH, "com.example.PackagePrivate", JavaFileObject.Kind.CLASS);
+ var standardJavaName = standardFileManager.inferBinaryName(StandardLocation.SOURCE_PATH, standardJava);
+ var standardClassName = standardFileManager.inferBinaryName(StandardLocation.CLASS_PATH, standardClass);
+ var sourceJavaName = sourceFileManager.inferBinaryName(StandardLocation.SOURCE_PATH, sourceJava);
+ var sourceClassName = sourceFileManager.inferBinaryName(StandardLocation.CLASS_PATH, sourceClass);
+ assertThat(standardClassName, equalTo(standardJavaName));
+ assertThat(sourceJavaName, equalTo(standardJavaName));
+ assertThat(sourceClassName, equalTo(standardJavaName));
+ }
+
+ private static final Logger LOG = Logger.getLogger("main");
+}