Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. @RunWith(MockitoJUnitRunner.class)
  2. public class WordCountMapperTest {
  3.  
  4. @Mock
  5. private Mapper.Context mockContext; // declare your mocks
  6.  
  7. org.apache.hadoop.examples.WordCount.TokenizerMapper mapper;
  8.  
  9. @Before
  10. public void setUp() throws Exception {
  11. /*
  12. * mock and define your components here
  13. */
  14. mapper = new WordCount.TokenizerMapper();
  15.  
  16. doNothing().when(mockContext.getCounter(TaskCounter.MAP_OUTPUT_RECORDS)).increment(anyLong());
  17. }
  18.  
  19. @Test
  20. public void testMap() throws IOException, InterruptedException {
  21. /*
  22. * whatever you want to test you can write here in the verify statement
  23. */
  24. String line1 = "key_value";
  25.  
  26. mapper.map(null, new Text(line1), mockContext);
  27. verify(mockContext.getCounter(TaskCounter.MAP_OUTPUT_RECORDS), times(1)).increment(1);
  28. }
  29. }
Add Comment
Please, Sign In to add comment