/** * <p>Obtain Context object for furthering mocking with Mockito. * For example, causing write() to throw an exception:</p> * * <pre> * import static org.mockito.Matchers.*; * import static org.mockito.Mockito.*; * doThrow(new IOException()).when(context).write(any(), any()); * </pre> * * <p>Or implement other logic:</p> * * <pre> * import static org.mockito.Matchers.*; * import static org.mockito.Mockito.*; * doAnswer(new Answer<Object>() { * public Object answer(final InvocationOnMock invocation) { * ... * return null; * } * }).when(context).write(any(), any()); * </pre> * @return the mocked context */ public Mapper<K1, V1, K2, V2>.Context getContext() { return getContextWrapper().getMockContext(); }
@Override public List<Pair<K2, V2>> run() throws IOException { try { preRunChecks(myMapper); initDistributedCache(); MockMapContextWrapper<K1, V1, K2, V2> wrapper = getContextWrapper(); mos = new MockMultipleOutputs(wrapper.getMockContext()); try { PowerMockito.whenNew(MultipleOutputs.class).withArguments(wrapper.getMockContext()).thenReturn(mos); } catch (Exception e) { throw new RuntimeException(e); } myMapper.run(wrapper.getMockContext()); return wrapper.getOutputs(); } catch (final InterruptedException ie) { throw new IOException(ie); } finally { cleanupDistributedCache(); } }