TagUtil { public static boolean addTag(String tag, Map<String, String> properties) { String tags = properties.get(TAGS); if (tags == null) { properties.put(TAGS, tag); return true; } Set<String> list = parseTags(tags); boolean result = list.add(tag); properties.put(TAGS, formatTags(list)); return result; } private  TagUtil(); static boolean removeTag(String tag, Map<String, String> properties); static Set<String> parseTags(String tagsValue); static boolean addTag(String tag, Map<String, String> properties); static void remove(String[] tags, Map<String, String> properties); static void add(String[] tags, Map<String, String> properties); static final String TAGS; }
@Test public void testAddTag() { Assert.assertTrue(TagUtil.addTag("test3", properties)); Assert.assertFalse(TagUtil.addTag("test3", properties)); Assert.assertTrue(properties.get(TagUtil.TAGS).contains("test3")); Assert.assertTrue(properties.get(TagUtil.TAGS).contains("test2")); }