mahout-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank Scholten (JIRA)" <>
Subject [jira] [Commented] (MAHOUT-730) Replace EasyMock with Mockito
Date Mon, 13 Jun 2011 12:30:52 GMT


Frank Scholten commented on MAHOUT-730:

The following works. Let's say we have the WordCountMapper Hadoop example. By removing the
private modifier of the Text key we can inject a mock for testing:

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
  private final static IntWritable one = new IntWritable(1);

  Text key = new Text();

  public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
    String line = value.toString();
    StringTokenizer tokenizer = new StringTokenizer(line);
    while (tokenizer.hasMoreTokens()) {
      context.write(this.key, one);

In the test we verify that our inserted mock key was set 4 times with the correct value and
written to the context, in the expected order.

public class WordCountMapperTest {

  private Mapper.Context context;
  private WordCountMapper mapper;
  private InOrder inOrder;
  private IntWritable countOnce;

  public void before() {
    context = mock(Mapper.Context.class);
    mapper = new WordCountMapper();
    mapper.key = mock(Text.class);
    inOrder = inOrder(mapper.key, context, mapper.key, context, mapper.key, context, mapper.key,
    countOnce = new IntWritable(1);

  public void testMap() throws IOException, InterruptedException {
    String line = "Machine learning with Mahout"; LongWritable(1), new Text(line), context);


  private void assertCountedOnce(String word) throws IOException, InterruptedException {
    inOrder.verify(context).write(eq(mapper.key), eq(countOnce));

> Replace EasyMock with Mockito
> -----------------------------
>                 Key: MAHOUT-730
>                 URL:
>             Project: Mahout
>          Issue Type: Improvement
>    Affects Versions: 0.6
>            Reporter: Sebastian Schelter
>            Assignee: Sebastian Schelter
> I'd like to switch our mock library from EasyMock to Mockito. The later one needs less
code (and doesn't need to be "replayed") and it's more intuitive to write tests with it in
my experience. Switching shouldn't be a big effort.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message