ApplicationDiscovery { public List<Resource> discoverApplications() { List<Resource> resources = new ArrayList<>(); Resource resource = resourceLoader.getResource(applicationsLocation); if (resource.exists()) { try { resources = Arrays.asList(resourceLoader.getResources(applicationsLocation + "**.zip")); } catch (IOException e) { throw new AppliationLoadException("Unable to load application resources", e); } } return resources; } ApplicationDiscovery(ResourcePatternResolver resourceLoader,
                                String applicationsLocation); List<Resource> discoverApplications();  }
@Test public void discoverApplicationsShouldReturnResourcesFoundByResourceLoader() throws Exception { givenExistingResourceFolder(); Resource applicationResource = mock(Resource.class); given(resourceLoader.getResources(anyString())).willReturn(new Resource[]{applicationResource}); List<Resource> resources = applicationDiscovery.discoverApplications(); assertThat(resources).containsExactly(applicationResource); }
@Test public void discoverApplicationsShouldThrowApplicationLoadExceptionWhenIOExceptionOccurs() throws IOException { givenExistingResourceFolder(); IOException ioException = new IOException(); given(resourceLoader.getResources(anyString())).willThrow(ioException); Throwable thrown = catchThrowable(() -> applicationDiscovery.discoverApplications()); assertThat(thrown) .isInstanceOf(AppliationLoadException.class) .hasCause(ioException); }