Topics { public static List<String> sanitize(String topic) { if (topic.contains("+") || topic.endsWith("#") || topic.endsWith("#/" + END)) { return sanitizeTopicFilter(topic); } else { return sanitizeTopicName(topic); } } private  Topics(); static String antidote(String topic); static String antidote(List<String> topicLevels); static List<String> sanitize(String topic); static List<String> sanitizeTopicName(String topicName); static List<String> sanitizeTopicFilter(String topicFilter); static boolean isTopicFilter(List<String> topicLevels); static final String EMPTY; static final String END; }
@Test public void sanitizeTest() { assert Arrays.equals(Topics.sanitize("abc/+/g/h").toArray(), new String[]{"abc", "+", "g", "h", END}); assert Arrays.equals(Topics.sanitize("abc/def/g/#").toArray(), new String[]{"abc", "def", "g", "#", END}); assert Arrays.equals(Topics.sanitize("abc/def/#").toArray(), new String[]{"abc", "def", "#", END}); assert Arrays.equals(Topics.sanitize("+/+/g/#").toArray(), new String[]{"+", "+", "g", "#", END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/#").toArray(), new String[]{EMPTY, "abc", "def", "g", "#", END}); assert Arrays.equals(Topics.sanitize("/abc assert Arrays.equals(Topics.sanitize("/abc/+/g/h/").toArray(), new String[]{EMPTY, "abc", "+", "g", "h", EMPTY, END}); assert Arrays.equals(Topics.sanitize("abc/def/g/h").toArray(), new String[]{"abc", "def", "g", "h", END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/h").toArray(), new String[]{EMPTY, "abc", "def", "g", "h", END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/h/").toArray(), new String[]{EMPTY, "abc", "def", "g", "h", EMPTY, END}); assert Arrays.equals(Topics.sanitize("/abc/def }
@Test public void sanitizeTest() { assert Arrays.equals(Topics.sanitize("abc/+/g/h").toArray(), new String[]{"abc", "+", "g", "h", Topics.END}); assert Arrays.equals(Topics.sanitize("abc/def/g/#").toArray(), new String[]{"abc", "def", "g", "#", Topics.END}); assert Arrays.equals(Topics.sanitize("abc/def/#").toArray(), new String[]{"abc", "def", "#", Topics.END}); assert Arrays.equals(Topics.sanitize("+/+/g/#").toArray(), new String[]{"+", "+", "g", "#", Topics.END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/#").toArray(), new String[]{Topics.EMPTY, "abc", "def", "g", "#", Topics.END}); assert Arrays.equals(Topics.sanitize("/abc assert Arrays.equals(Topics.sanitize("/abc/+/g/h/").toArray(), new String[]{Topics.EMPTY, "abc", "+", "g", "h", Topics.EMPTY, Topics.END}); assert Arrays.equals(Topics.sanitize("abc/def/g/h").toArray(), new String[]{"abc", "def", "g", "h", Topics.END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/h").toArray(), new String[]{Topics.EMPTY, "abc", "def", "g", "h", Topics.END}); assert Arrays.equals(Topics.sanitize("/abc/def/g/h/").toArray(), new String[]{Topics.EMPTY, "abc", "def", "g", "h", Topics.EMPTY, Topics.END}); assert Arrays.equals(Topics.sanitize("/abc/def }