ToolMapper extends Mapper<LongWritable, Text, LongWritable, Text> { static List<String> extractAttributes(Text value) { List<String> result = Lists.newArrayList(); for (String token : COMMA.split(value.toString())) { result.add(token.trim()); } return result; }   static final String ATTRIBUTES; }
@Test public void testExtractAttributes() throws Exception { LongWritable key = new LongWritable(); Text value = new Text(); Configuration conf = new Configuration(); ToolMapper mapper = new ToolMapper(); DummyRecordWriter<LongWritable, Text> writer = new DummyRecordWriter<LongWritable, Text>(); Mapper<LongWritable, Text, LongWritable, Text>.Context context = DummyRecordWriter.build(mapper, conf, writer); char[] descriptors = { 'N', 'N', 'C', 'C', 'N', 'N' }; mapper.configure(descriptors); String dataline = "A1, A2, A3, A4, A5, A6"; value.set(dataline); mapper.map(key, value, context); for (int index = 0; index < 6; index++) { List<Text> values = writer.getValue(new LongWritable(index)); assertEquals("should extract one value per attribute", 1, values.size()); assertEquals("Bad extracted value", "A" + (index + 1), values.get(0).toString()); } }