Report { public static Report createFromString(final String s) { return new Report(s); } Report(); private  Report(String s); void put(final String key, final String value, boolean append); void put(final String key, final String value); void remove(final String key); XTraceMetadata getMetadata(); List<String> get(String key); @Override String toString(); static Report createFromString(final String s); @Override boolean equals(Object o);  }
@Test public void testCreateFromString() { Report r = new Report(); r.put("Key1", "Value1"); r.put("Key2", "Value2"); r.put("Key4", "Value4.1"); r.put("Key4", "Value4.2"); r.put("Key4", "Value4.3"); r.put("X-Trace", "100000000000000000"); Report r2 = Report.createFromString(r.toString()); String s = r2.toString(); assertNotNull(s); assertTrue(s.startsWith("X-Trace Report ver 1.0")); assertTrue(s.contains("Key1: Value1")); assertTrue(s.contains("Key2: Value2")); assertTrue(s.contains("Key4: Value4.1")); assertTrue(s.contains("Key4: Value4.2")); assertTrue(s.contains("Key4: Value4.3")); assertTrue(s.contains("X-Trace: 100000000000000000")); r = Report.createFromString("X-Trace Report ver 1.0\n" + "X-Trace: 0000000000\n" + "Key1: Value1\n" + "Key2: Value2\n" + "Key4: Value4.1\n" + "Key4: Value4.2\n" + "Key4: Value4.3"); List<String> kset = r.get("Key1"); assertEquals(kset.size(), 1); assertTrue(kset.contains("Value1")); kset = r.get("Key2"); assertEquals(kset.size(), 1); assertTrue(kset.contains("Value2")); kset = r.get("Key3"); assertNull(kset); kset = r.get("Key4"); assertEquals(kset.size(), 3); assertTrue(kset.contains("Value4.1")); assertTrue(kset.contains("Value4.2")); assertTrue(kset.contains("Value4.3")); }