Introduced trivial tokenization of topic

This commit is contained in:
andsel
2012-08-03 17:08:18 +02:00
parent 279b16fd26
commit c54b35c79c
2 changed files with 92 additions and 0 deletions
@@ -0,0 +1,50 @@
package org.dna.mqtt.moquette.messaging.spi.impl;
import java.util.Arrays;
import java.util.List;
import org.dna.mqtt.moquette.messaging.spi.impl.SubscriptionsStore.Token;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
/**
*
* @author andrea
*/
public class SubscriptionsStoreTest {
private SubscriptionsStore store;
public SubscriptionsStoreTest() {
}
@Before
public void setUp() {
store = new SubscriptionsStore();
}
@Test
public void testSplitTopic() {
List<Token> result = store.splitTopic("finance/stock/ibm");
assertEqualsSeq(asArray("finance", "stock", "ibm"), result);
}
private static Token[] asArray(Object... l) {
Token[] tokens = new Token[l.length];
for (int i = 0; i < l.length; i++) {
Object o = l[i];
if (o instanceof Token) {
tokens[i] = (Token)o;
} else {
tokens[i] = new Token(o.toString());
}
}
return tokens;
}
private void assertEqualsSeq(Token[] exptected, List<Token> result) {
List<Token> expectedList = Arrays.asList(exptected);
assertEquals(expectedList, result);
}
}