### Question:
TemplateMap { final void add(final String key, final T value) { this.map.put(key, value); }    }### Answer:
@Test public void add() { TemplateMap.Arguments arguments = new TemplateMap.Arguments(); arguments.add("foo", "bar"); Assert.assertEquals(1, arguments.map.size()); Assert.assertEquals("bar", getValue(arguments, "foo")); }
@Test public void addMappedObject() { String key = "string"; String value = "aString"; TemplateMap.Arguments arguments = new TemplateMap.Arguments(); arguments.addMappedObject(key, value, (string, stringMap) -> { stringMap.add("lower", string.toLowerCase()); stringMap.add("upper", string.toUpperCase()); }); Assert.assertEquals(1, arguments.map.size()); Assert.assertEquals(value, getValue(arguments, key)); }
@Test public void addCollection() { Collection<String> strings = Arrays.asList("foo", "bar"); TemplateMap.Arguments arguments = new TemplateMap.Arguments(); arguments.addCollection("strings", strings, (string, stringMap) -> { stringMap.add("lower", string.toLowerCase()); stringMap.add("upper", string.toUpperCase()); stringMap.add("size", string.length() + ""); stringMap.addCollection("chars", getChars(string), (character, charsMap) -> charsMap.add("asciiCode", character.toString()) ); }); Assert.assertEquals(1, arguments.map.size()); Assert.assertTrue(arguments.map.get("strings") instanceof TemplateObject.Collection); }
@Test public void map() { final TemplateObject.Mapped<String> mapped; mapped = new TemplateObject.Mapped<>("foo", (string, stringMap) -> { stringMap.add("lower", string.toLowerCase()); stringMap.add("upper", string.toUpperCase()); stringMap.add("size", string.length() + ""); }); final TemplateMap.Arguments map = mapped.map(); Assert.assertEquals("foo", getValue(map, "lower")); Assert.assertEquals("FOO", getValue(map, "upper")); Assert.assertEquals("3", getValue(map, "size")); }