Search in sources :

Example 1 with HasJsonField

use of com.facebook.buck.json.HasJsonField in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testClassUsageFileOutputProperly.

@Test
public void testClassUsageFileOutputProperly() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "class_usage_file", tmp);
    workspace.setUp();
    // Run `buck build`.
    BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
    ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    Path bizClassUsageFilePath = BuildTargets.getGenPath(filesystem, bizTarget, "lib__%s__output/used-classes.json");
    final List<String> lines = Files.readAllLines(workspace.getPath(bizClassUsageFilePath), UTF_8);
    assertEquals("Expected just one line of JSON", 1, lines.size());
    final String utilJarPath = MorePaths.pathWithPlatformSeparators("buck-out/gen/lib__util__output/util.jar");
    final String utilClassPath = MorePaths.pathWithPlatformSeparators("com/example/Util.class");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    JsonNode jsonNode = objectMapper.readTree(lines.get(0));
    assertThat(jsonNode, new HasJsonField(objectMapper, utilJarPath, Matchers.equalTo(objectMapper.valueToTree(new String[] { utilClassPath }))));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) HasJsonField(com.facebook.buck.json.HasJsonField) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

HasJsonField (com.facebook.buck.json.HasJsonField)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Path (java.nio.file.Path)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1