Search in sources :

Example 1 with ResourcesRootPackageFinder

use of com.facebook.buck.jvm.java.ResourcesRootPackageFinder in project buck by facebook.

the class JavaPackageFinderSerializerTest method testSerializingAndDeserializing.

@Test
public void testSerializingAndDeserializing() throws Exception {
    DefaultJavaPackageFinder defaultFinder = new DefaultJavaPackageFinder(ImmutableSortedSet.of("paths", "from", "root"), ImmutableSet.of("path", "elements"));
    ResourcesRootPackageFinder resourcesRootFinder = new ResourcesRootPackageFinder(Paths.get("/path/to/res/root"), defaultFinder);
    Map<String, Object> data = JavaPackageFinderSerializer.serialize(resourcesRootFinder);
    JavaPackageFinder result = JavaPackageFinderSerializer.deserialize(data);
    assertThat(result, Matchers.instanceOf(ResourcesRootPackageFinder.class));
    ResourcesRootPackageFinder outResFinder = (ResourcesRootPackageFinder) result;
    assertThat(outResFinder.getResourcesRoot(), Matchers.equalToObject(resourcesRootFinder.getResourcesRoot()));
    JavaPackageFinder chainedFinder = outResFinder.getFallbackFinder();
    assertThat(chainedFinder, Matchers.instanceOf(DefaultJavaPackageFinder.class));
    DefaultJavaPackageFinder outDefFinder = (DefaultJavaPackageFinder) chainedFinder;
    assertThat(outDefFinder.getPathElements(), Matchers.equalToObject(defaultFinder.getPathElements()));
    assertThat(outDefFinder.getPathsFromRoot(), Matchers.equalToObject(defaultFinder.getPathsFromRoot()));
}
Also used : JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) ResourcesRootPackageFinder(com.facebook.buck.jvm.java.ResourcesRootPackageFinder) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) Test(org.junit.Test)

Example 2 with ResourcesRootPackageFinder

use of com.facebook.buck.jvm.java.ResourcesRootPackageFinder in project buck by facebook.

the class ResourcesRootPackageFinderTest method testResourcesPath.

@Test
public void testResourcesPath() {
    Path resourcesRoot = Paths.get("java/example/resources");
    ResourcesRootPackageFinder finder = new ResourcesRootPackageFinder(resourcesRoot, new FakeJavaPackageFinder());
    assertEquals(Paths.get("com/facebook/"), finder.findJavaPackageFolder(Paths.get("java/example/resources/com/facebook/bar.txt")));
    assertEquals("com.facebook", finder.findJavaPackage(Paths.get("java/example/resources/com/facebook/bar.txt")));
}
Also used : Path(java.nio.file.Path) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) ResourcesRootPackageFinder(com.facebook.buck.jvm.java.ResourcesRootPackageFinder) Test(org.junit.Test)

Example 3 with ResourcesRootPackageFinder

use of com.facebook.buck.jvm.java.ResourcesRootPackageFinder in project buck by facebook.

the class ResourcesRootPackageFinderTest method testNonmatchingPath.

@Test
public void testNonmatchingPath() {
    Path resourcesRoot = Paths.get("java/example/resources");
    ResourcesRootPackageFinder finder = new ResourcesRootPackageFinder(resourcesRoot, new FakeJavaPackageFinder());
    assertNull("Should fall back to the FakeJavaPackageFinder and return null.", finder.findJavaPackageFolder(Paths.get("does/not/match.txt")));
}
Also used : Path(java.nio.file.Path) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) ResourcesRootPackageFinder(com.facebook.buck.jvm.java.ResourcesRootPackageFinder) Test(org.junit.Test)

Aggregations

ResourcesRootPackageFinder (com.facebook.buck.jvm.java.ResourcesRootPackageFinder)3 Test (org.junit.Test)3 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)2 Path (java.nio.file.Path)2 JavaPackageFinder (com.facebook.buck.jvm.core.JavaPackageFinder)1 DefaultJavaPackageFinder (com.facebook.buck.jvm.java.DefaultJavaPackageFinder)1