TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> { List<String> codes(String value) { List<String> result = new LinkedList<>(); StringTokenizer tokenizer = new StringTokenizer(value, SEPARATORS); while (tokenizer.hasMoreElements()) { result.add((String) tokenizer.nextElement()); } return result; }   static final String SEPARATORS; }
@Test public void givenString_whenCodes_whenTokenized() { TokenizerMapper tokenizerMapper = new TokenizerMapper(); List<String> codes = tokenizerMapper.codes("OSL,WRO\nWRO,OSL\nWRO,NYC"); assertTrue(codes.contains("OSL")); assertTrue(codes.contains("WRO")); assertTrue(codes.contains("NYC")); assertTrue(codes.size() == 6); }