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 }))));
}
Aggregations