@Test public void appendString() { ImmutableMap<String, String> map = this.newMapWithKeysValues("1", "One", "2", "Two", "3", "Three", "4", "Four"); StringBuilder builder1 = new StringBuilder(); map.appendString(builder1); String defaultString = builder1.toString(); StringBuilder builder2 = new StringBuilder(); map.appendString(builder2, "|"); String delimitedString = builder2.toString(); StringBuilder builder3 = new StringBuilder(); map.appendString(builder3, "{", "|", "}"); String wrappedString = builder3.toString(); switch (map.size()) { case 1: Assert.assertEquals("One", defaultString); Assert.assertEquals("One", delimitedString); Assert.assertEquals("{One}", wrappedString); break; case 2: Assert.assertEquals(8, defaultString.length()); Assert.assertEquals(7, delimitedString.length()); Verify.assertContains("|", delimitedString); Assert.assertEquals(9, wrappedString.length()); Verify.assertContains("|", wrappedString); Assert.assertTrue(wrappedString.startsWith("{")); Assert.assertTrue(wrappedString.endsWith("}")); break; case 3: Assert.assertEquals(15, defaultString.length()); Assert.assertEquals(13, delimitedString.length()); Verify.assertContains("|", delimitedString); Assert.assertEquals(15, wrappedString.length()); Verify.assertContains("|", wrappedString); Assert.assertTrue(wrappedString.startsWith("{")); Assert.assertTrue(wrappedString.endsWith("}")); break; case 4: Assert.assertEquals(21, defaultString.length()); Assert.assertEquals(18, delimitedString.length()); Verify.assertContains("|", delimitedString); Assert.assertEquals(20, wrappedString.length()); Verify.assertContains("|", wrappedString); Assert.assertTrue(wrappedString.startsWith("{")); Assert.assertTrue(wrappedString.endsWith("}")); break; default: Assert.assertEquals("", defaultString); Assert.assertEquals("", delimitedString); Assert.assertEquals("{}", wrappedString); break; } }
@Test public void appendString() { MutableMap<String, String> map = this.classUnderTest(); StringBuilder builder1 = new StringBuilder(); map.appendString(builder1); String defaultString = builder1.toString(); StringBuilder builder2 = new StringBuilder(); map.appendString(builder2, "|"); String delimitedString = builder2.toString(); StringBuilder builder3 = new StringBuilder(); map.appendString(builder3, "{", "|", "}"); String wrappedString = builder3.toString(); switch (map.size()) { case 1: Assert.assertEquals("One", defaultString); Assert.assertEquals("One", delimitedString); Assert.assertEquals("{One}", wrappedString); break; case 2: Assert.assertEquals(8, defaultString.length()); Assert.assertEquals(7, delimitedString.length()); Verify.assertContains("|", delimitedString); Assert.assertEquals(9, wrappedString.length()); Verify.assertContains("|", wrappedString); Assert.assertTrue(wrappedString.startsWith("{")); Assert.assertTrue(wrappedString.endsWith("}")); break; case 3: Assert.assertEquals(15, defaultString.length()); Assert.assertEquals(13, delimitedString.length()); Verify.assertContains("|", delimitedString); Assert.assertEquals(15, wrappedString.length()); Verify.assertContains("|", wrappedString); Assert.assertTrue(wrappedString.startsWith("{")); Assert.assertTrue(wrappedString.endsWith("}")); break; default: Assert.assertEquals("", defaultString); Assert.assertEquals("", delimitedString); Assert.assertEquals("{}", wrappedString); break; } }