Пример #1
0
  @Test
  public void setDifferentNonHashingResourceSourcePaths() {
    ResourceSourcePath resourceSourcePathOne =
        new ResourceSourcePath(
            PackagedResourceTestUtil.getPackagedResource("testdata/packaged_resource_one"));

    ResourceSourcePath resourceSourcePathTwo =
        new ResourceSourcePath(
            PackagedResourceTestUtil.getPackagedResource("testdata/packaged_resource_two"));

    // Changing the resource identifier should change the rule key
    assertNotEquals(
        createEmptyRuleKey(
                new SourcePathResolver(
                    new BuildRuleResolver(
                        TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer())))
            .setReflectively("key", new NonHashableSourcePathContainer(resourceSourcePathOne))
            .build(),
        createEmptyRuleKey(
                new SourcePathResolver(
                    new BuildRuleResolver(
                        TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer())))
            .setReflectively("key", new NonHashableSourcePathContainer(resourceSourcePathTwo))
            .build());
  }
  @Test
  public void testPackagedResourceOnIndividualFile() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    PackagedResource packagedResource =
        PackagedResourceTestUtil.getPackagedResource(filesystem, "testdata/packaged_resource_one");

    assertThat(packagedResource.getFilenamePath().toString(), is("packaged_resource_one"));

    assertThat(
        packagedResource.getResourceIdentifier(),
        is(
            "com.facebook.buck.testutil.packaged_resource.PackagedResourceTestUtil"
                + "#testdata/packaged_resource_one"));

    String fileContent = filesystem.readFileIfItExists(packagedResource.get()).get();
    assertThat(fileContent, is("abc"));
  }