@Test public void shouldThrowApplicationLoadExceptionWhenIOExceptionOccurs() throws Exception { Resource applicationResource = mock(Resource.class); IOException ioException = new IOException(); given(applicationResource.getInputStream()).willThrow(ioException); given(applicationDiscovery.discoverApplications()).willReturn(Collections.singletonList(applicationResource)); Throwable thrown = catchThrowable(() -> applicationService.loadApplications()); assertThat(thrown).isInstanceOf(AppliationLoadException.class) .hasCause(ioException); }
public List<ApplicationContent> loadApplications() { List<ApplicationContent> applications = new ArrayList<>(); List<Resource> applicationResources = applicationDiscovery.discoverApplications(); try { for (Resource applicationResource : applicationResources) { try (InputStream inputStream = applicationResource.getInputStream()) { applications.add(applicationReader.read(inputStream)); } } } catch (IOException e) { throw new AppliationLoadException("Unable to load application resource", e); } return applications; }
ApplicationService { public List<ApplicationContent> loadApplications() { List<ApplicationContent> applications = new ArrayList<>(); List<Resource> applicationResources = applicationDiscovery.discoverApplications(); try { for (Resource applicationResource : applicationResources) { try (InputStream inputStream = applicationResource.getInputStream()) { applications.add(applicationReader.read(inputStream)); } } } catch (IOException e) { throw new AppliationLoadException("Unable to load application resource", e); } return applications; } }
ApplicationService { public List<ApplicationContent> loadApplications() { List<ApplicationContent> applications = new ArrayList<>(); List<Resource> applicationResources = applicationDiscovery.discoverApplications(); try { for (Resource applicationResource : applicationResources) { try (InputStream inputStream = applicationResource.getInputStream()) { applications.add(applicationReader.read(inputStream)); } } } catch (IOException e) { throw new AppliationLoadException("Unable to load application resource", e); } return applications; } ApplicationService(ApplicationDiscovery applicationDiscovery,
                              ApplicationReader applicationReader); }
ApplicationService { public List<ApplicationContent> loadApplications() { List<ApplicationContent> applications = new ArrayList<>(); List<Resource> applicationResources = applicationDiscovery.discoverApplications(); try { for (Resource applicationResource : applicationResources) { try (InputStream inputStream = applicationResource.getInputStream()) { applications.add(applicationReader.read(inputStream)); } } } catch (IOException e) { throw new AppliationLoadException("Unable to load application resource", e); } return applications; } ApplicationService(ApplicationDiscovery applicationDiscovery,
                              ApplicationReader applicationReader); List<ApplicationContent> loadApplications(); }
ApplicationService { public List<ApplicationContent> loadApplications() { List<ApplicationContent> applications = new ArrayList<>(); List<Resource> applicationResources = applicationDiscovery.discoverApplications(); try { for (Resource applicationResource : applicationResources) { try (InputStream inputStream = applicationResource.getInputStream()) { applications.add(applicationReader.read(inputStream)); } } } catch (IOException e) { throw new AppliationLoadException("Unable to load application resource", e); } return applications; } ApplicationService(ApplicationDiscovery applicationDiscovery,
                              ApplicationReader applicationReader); List<ApplicationContent> loadApplications();  }