PropertyLoader { public Properties loadProperties(final String configFile) { Properties properties = new Properties(); try { checkPropertyFileArgument(configFile); InputStream inputStream = new FileInputStream(configFile); properties.load(inputStream); logger.debug("Properties loaded from external configuration."); } catch (IOException e) { throw new PropertiesNotAvailableException("Configuration file " + configFile + " cannot be loaded", e); } return properties; }  Properties loadProperties(final String configFile); void loadProperties();  }
@Test public void testLoadPropertiesWhenArgumentsAreValidShouldLoadProperties() throws IOException { underTest.loadProperties(); verify(properties).load(inputStream); }
@Test public void testLoadPropertiesWhenArgumentsAreValidShouldCallPropertyReader() { underTest.loadProperties(); verify(propertyReader).setProperties(properties); }
@Test(expectedExceptions = PropertiesNotAvailableException.class) public void testLoadPropertiesWhenFileNotFoundShouldThrowException() throws Exception { given(inputStreamFactory.createFileInputStream(configFile)).willThrow(new FileNotFoundException()); underTest.loadProperties(); }
@Test(expectedExceptions = PropertiesNotAvailableException.class) public void testLoadPropertiesWhenIOExcpetionShouldThrowException() throws Exception { willThrow(new IOException()).given(properties).load(inputStream); underTest.loadProperties(); }
@Test public void testLoadPropertiesShouldReturnProperties() { Properties actual = underTest.loadProperties(configFile); assertEquals(actual.getProperty("webapp.port"), "8080"); }
@Test(expectedExceptions = PropertiesNotAvailableException.class) public void testLoadPropertiesShouldThrowExceptionWhenPropertiesNotFound() { underTest.loadProperties("conf.properties"); }
@Test(expectedExceptions = PropertiesNotAvailableException.class) public void testLoadPropertiesWhenProgramArgumentEmptyShouldThrowException() { Whitebox.setInternalState(underTest, "configFile", ""); underTest.loadProperties(); }
@Test(expectedExceptions = PropertiesNotAvailableException.class) public void testLoadPropertiesWhenProgramArgumentInvalidShouldThrowException() { Whitebox.setInternalState(underTest, "configFile", "wilma.conf.prop"); underTest.loadProperties(); }