class WordReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        if (containsTargetWord(key)) {
            int wordCount = 0;
            for (IntWritable value: values) {
                wordCount += value.get();
            }
            context.write(key, new IntWritable(wordCount));
        }
    }

}

class WordReducerTest {

    private static final String NOT_TARGET_WORD;
    private Reducer.Context contextMock;
    private WordReducer reducer;

    @Test
    public void reduceWhenTargetWordIsFound() throws IOException, InterruptedException {

        Text key = new Text(WordReducer.TARGET_WORD);
        Iterable<IntWritable> values = createValues(1, 1, 1);
        reducer.reduce(key, values, contextMock);

        ArgumentCaptor<IntWritable> countArgument = ArgumentCaptor.forClass(IntWritable.class);

        verify(contextMock, times(1)).write(eq(key), countArgument.capture());
        verifyNoMoreInteractions(contextMock);

        IntWritable count = countArgument.getValue();
        assertEquals(3, count.get());
    }

}