### Question:
EntityWriter { public Entity write(Entity entity, JsonFileWriter file, ErrorFile errors) { Entity treated = applicator.apply(entity); try { file.write(treated); } catch (JsonProcessingException e) { LOG.error("Error while extracting from " + entity.getType(), e); errors.logEntityError(entity); } catch (IOException e) { LOG.error("Error while extracting from " + entity.getType(), e); errors.logEntityError(entity); } return treated; } EntityWriter(Treatment treatment); Entity write(Entity entity, JsonFileWriter file, ErrorFile errors);  }### Answer:
@Test public void testWrite() { JsonFileWriter file = Mockito.mock(JsonFileWriter.class); ErrorFile errorFile = Mockito.mock(ErrorFile.class); Entity entity = Mockito.mock(Entity.class); Entity check = writer.write(entity, file, errorFile); Assert.assertEquals(treatedEntity, check); try { Mockito.verify(file, Mockito.times(1)).write(treatedEntity); } catch (IOException e) { Assert.fail(); } }
@Test public void testIOException() throws IOException { JsonFileWriter file = Mockito.mock(JsonFileWriter.class); Mockito.doThrow(new IOException("Mock IOException")).when(file).write(Mockito.any(Entity.class)); ErrorFile errorFile = Mockito.mock(ErrorFile.class); Entity entity = Mockito.mock(Entity.class); Mockito.when(entity.getType()).thenReturn("MOCK_ENTITY_TYPE"); writer.write(entity, file, errorFile); Mockito.verify(errorFile).logEntityError(entity); Mockito.doThrow(Mockito.mock(JsonProcessingException.class)).when(file).write(Mockito.any(Entity.class)); writer.write(entity, file, errorFile); Mockito.verify(errorFile, Mockito.times(2)).logEntityError(entity); }