BATCH-1033: Updated to account for the possibility of a null key in the map

This commit is contained in:
dhgarrette
2009-01-28 05:19:31 +00:00
parent 18f7870ba2
commit 505d8532f9
2 changed files with 36 additions and 10 deletions

View File

@@ -49,16 +49,41 @@ public class PrefixMatchingCompositeLineTokenizerTests {
@Test
public void testNullLineWithKey() throws Exception {
Map<String, LineTokenizer> map = new HashMap<String, LineTokenizer>();
map.put(null, new DelimitedLineTokenizer());
map.put(null, new LineTokenizer() {
public FieldSet tokenize(String line) {
return new DefaultFieldSet(new String[] { "a" });
}
});
map.put("foo", new LineTokenizer() {
public FieldSet tokenize(String line) {
return null;
return new DefaultFieldSet(new String[] { "b" });
}
});
tokenizer.setTokenizers(map);
tokenizer.afterPropertiesSet();
FieldSet fields = tokenizer.tokenize(null);
assertEquals(0, fields.getFieldCount());
assertEquals(1, fields.getFieldCount());
assertEquals("a", fields.readString(0));
}
@Test
public void testNullKey() throws Exception {
Map<String, LineTokenizer> map = new HashMap<String, LineTokenizer>();
map.put(null, new LineTokenizer() {
public FieldSet tokenize(String line) {
return new DefaultFieldSet(new String[] { "a" });
}
});
map.put("foo", new LineTokenizer() {
public FieldSet tokenize(String line) {
return new DefaultFieldSet(new String[] { "b" });
}
});
tokenizer.setTokenizers(map);
tokenizer.afterPropertiesSet();
FieldSet fields = tokenizer.tokenize("foo");
assertEquals(1, fields.getFieldCount());
assertEquals("b", fields.readString(0));
}
@Test