### Question:
DefProConfigurationLoader implements ConfigurationLoader { @Override @SuppressWarnings("IllegalCatch") public Configuration load(File file) throws FileNotFoundException { if (!file.exists()) { throw new FileNotFoundException("The given file does not exist"); } try { return new DefProConfiguration(APIProvider.getAPI(file.getAbsolutePath())); } catch (Exception e) { throw new FileNotFoundException(e.getMessage()); } }  @Override @SuppressWarnings("IllegalCatch") Configuration load(File file); @Override Configuration load(InputStream input);  }### Answer:
@Test public void nonExistentFile() throws Exception { File file = mock(File.class); when(file.exists()).thenReturn(false); assertThatThrownBy(() -> loader.load(file)).isInstanceOf(FileNotFoundException.class); }
@Test public void invalidFile() throws Exception { File file = mock(File.class); when(file.exists()).thenReturn(true); assertThatThrownBy(() -> loader.load(file)).isInstanceOf(FileNotFoundException.class); }
@Test public void existentFile() throws Exception { File file = File.createTempFile("defpro", "test"); String content = "int a = 1"; Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE); assertThat(loader.load(file).get(new IntegerProperty("a"))).isEqualTo(1); file.deleteOnExit(); }
@Test public void validStream() throws Exception { String content = "int a = 1"; InputStream input = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); assertThat(loader.load(input).get(new IntegerProperty("a"))).isEqualTo(1); }
@Test public void invalidStream() throws Exception { InputStream input = mock(InputStream.class); when(input.read(any())).thenThrow(new IOException()); assertThatThrownBy(() -> loader.load(input)).isInstanceOf(IOException.class); }