### Question:
FragmentStats { public static String dataToJSON(FragmentStats stats) throws IOException { ObjectMapper mapper = new ObjectMapper(); return "{\"PXFFragmentsStats\":" + mapper.writeValueAsString(stats) + "}"; } FragmentStats(long fragmentsNumber, long firstFragmentSize,
                         long totalSize); static String dataToJSON(FragmentStats stats); static String dataToString(FragmentStats stats, String datapath); long getFragmentsNumber(); SizeAndUnit getFirstFragmentSize(); SizeAndUnit getTotalSize(); static final long DEFAULT_FRAGMENT_SIZE; }### Answer:
@Test public void dataToJSON() throws IOException { FragmentStats fragmentStats = new FragmentStats(25, 20000000, (long) Math.pow(5, 30)); String json = FragmentStats.dataToJSON(fragmentStats); String expectedJson = "{\"PXFFragmentsStats\":" + "{\"fragmentsNumber\":" + fragmentStats.getFragmentsNumber() + ",\"firstFragmentSize\":" + "{\"size\":" + fragmentStats.getFirstFragmentSize().getSize() + ",\"unit\":\"" + fragmentStats.getFirstFragmentSize().getUnit() + "\"}" + ",\"totalSize\":" + "{\"size\":" + fragmentStats.getTotalSize().getSize() + ",\"unit\":\"" + fragmentStats.getTotalSize().getUnit() + "\"}" + "}}"; assertEquals(expectedJson, json); }