ServiceConfig { public static Configuration getConfiguration(Class<?> clazz) throws ConfigurationException { String className = clazz.getName(); _log.info("Class name is " + className); return getConfiguration(className); } private  ServiceConfig(); static Configuration getConfiguration(Class<?> clazz); static Configuration getConfiguration(String basename); static Configuration getConfiguration(File properties);  }
@Test public void testGetConfigurationClassCheckPropsExist() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertNotNull("Expected to find properties in: " + baseDir + File.separatorChar + getClass().getName() + ".properties", config); }
@Test(expected=ConfigurationException.class) public void testGetConfigurationClassPropsDontExist() throws ConfigurationException { ServiceConfig.getConfiguration(java.lang.UnsupportedOperationException.class); fail("expected ConfigurationException to have been thrown"); }
@Test public void testGetConfigurationClassValidString() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals("testString", config.getString("testValidString")); }
@Test(expected=NoSuchElementException.class) public void testGetConfigurationClassComplexKey1() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals("five", config.getString("http: }
@Test(expected=NoSuchElementException.class) public void testGetConfigurationClassComplexKey2() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals("six", config.getString("http: }
@Test public void testGetConfigurationClassComplexValue() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals("http: }
@Test public void testGetConfigurationClassDefaultString() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals("defaultValue", config.getString("testInvalidString", "defaultValue")); }
@Test(expected=NoSuchElementException.class) public void testGetConfigurationClassNoDefaultString() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); String value = config.getString("testMissingString"); fail("expected NoSuchElementException to have been thrown. Got: " + value); }
@Test(expected=NoSuchElementException.class) public void testGetConfigurationClassNoDefaultPrimitive() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); int value = config.getInteger("testMissingPrimitive"); fail("expected NoSuchElementException to have been thrown. Got: " + value); }
@Test public void testGetConfigurationClassDefaultPrimitive() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); int value = config.getInteger("testMissingPrimitive", 1234); assertEquals(1234, value); }
@Test public void testGetConfigurationClassValidNumber() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals(1234, config.getInteger("testValidNumber")); }
@Test(expected=ConversionException.class) public void testGetConfigurationClassBadParseNumber() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); config.getInteger("testBadParseNumber"); fail("expected ConfigurationException to have been thrown"); }
@Test(expected=NoSuchElementException.class) public void testGetConfigurationClassMissingURI() throws ConfigurationException, URISyntaxException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals(new URI("file: }
@Test public void testGetConfigurationClassValidURI() throws ConfigurationException, URISyntaxException { Configuration config = ServiceConfig.getConfiguration(getClass()); assertEquals(new URI("file: }
@Test public void testGetConfigurationClassDefaultURI() throws ConfigurationException, URISyntaxException { Configuration config = ServiceConfig.getConfiguration(getClass()); URI defaultURI = new URI("file: assertEquals(defaultURI, config.getURI("uriXX", defaultURI)); }
@Test(expected=ConversionException.class) public void testGetConfigurationClassBadParseURI() throws ConfigurationException { Configuration config = ServiceConfig.getConfiguration(getClass()); config.getURI("badUri"); fail("expected ConfigurationException to have been thrown"); }