@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); }
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 { 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 { 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); }
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); }
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);  }