### Question:
SubscriptionsStore { protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; }  void init(IStorageService storageService); void add(Subscription newSubscription); void removeSubscription(String topic, String clientID); void clearAllSubscriptions(); void removeForClient(String clientID); void deactivate(String clientID); void activate(String clientID); List<Subscription> matches(String topic); boolean contains(Subscription sub); int size(); String dumpTree(); static boolean matchTopics(String msgTopic, String subscriptionTopic);  }### Answer:
@Test public void testSplitTopic() throws ParseException { List tokens = store.splitTopic("finance/stock/ibm"); assertEqualsSeq(asArray("finance", "stock", "ibm"), tokens); tokens = store.splitTopic("/finance/stock/ibm"); assertEqualsSeq(asArray(Token.EMPTY, "finance", "stock", "ibm"), tokens); tokens = store.splitTopic("/"); assertEqualsSeq(asArray(Token.EMPTY), tokens); }
@Test(expected = ParseException.class) public void testSplitTopicTwinsSlashAvoided() throws ParseException { store.splitTopic("/finance }
@Test public void testSplitTopicMultiValid() throws ParseException { List tokens = store.splitTopic("finance/stock/#"); assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens); tokens = store.splitTopic("#"); assertEqualsSeq(asArray(Token.MULTI), tokens); }
@Test(expected = ParseException.class) public void testSplitTopicMultiInTheMiddleNotValid() throws ParseException { store.splitTopic("finance/#/closingprice"); }
@Test(expected = ParseException.class) public void testSplitTopicMultiNotAferSeparatorNotValid() throws ParseException { store.splitTopic("finance#"); }
@Test public void testSplitTopicSingleValid() throws ParseException { List tokens = store.splitTopic("finance/stock/+"); assertEqualsSeq(asArray("finance", "stock", Token.SINGLE), tokens); tokens = store.splitTopic("+"); assertEqualsSeq(asArray(Token.SINGLE), tokens); tokens = store.splitTopic("finance/+/ibm"); assertEqualsSeq(asArray("finance", Token.SINGLE, "ibm"), tokens); }
@Test(expected = ParseException.class) public void testSplitTopicSingleNotAferSeparatorNotValid() throws ParseException { store.splitTopic("finance+"); }