@Test public void testGetThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.get("testSubConfigurationPropertyName"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetAll() throws Throwable { Configuration cfg = new SimpleConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); subConfiguration.put("testString", ""); String[] result = subConfiguration.getAll("testString"); assertEquals("result.length", 1, result.length); assertEquals("result[0]", "", result[0]); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); }
@Test public void testGetBooleanThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(new SubConfiguration(), "testSubConfigurationPrefix"); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix1"); try { subConfiguration.getBoolean("testSubConfigurationPropertyName"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testPutThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(new SubConfiguration(new SubConfiguration(), "testSubConfigurationPrefix"), "testSubConfigurationPrefix1"); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix2"); try { subConfiguration.put("testSubConfigurationName", "testString"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testSetConfiguration() throws Throwable { SubConfiguration subConfiguration = new SubConfiguration(new SubConfiguration(), "testSubConfigurationPrefix"); Configuration newCfg = new SimpleConfiguration(); subConfiguration.setConfiguration(newCfg); assertSame("subConfiguration.cfg", newCfg, subConfiguration.cfg); }
@Test public void testGetLongThrowsNumberFormatException1() throws Throwable { SubConfiguration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); cfg.setConfiguration(new SimpleConfiguration()); subConfiguration.put("testString", ""); try { subConfiguration.getLong("testString"); fail("Expected NumberFormatException to be thrown"); } catch (NumberFormatException ex) { assertEquals("ex.getMessage()", "For input string: \"\"", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetIntThrowsNumberFormatException1() throws Throwable { SubConfiguration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); cfg.setConfiguration(new SimpleConfiguration()); subConfiguration.put("testString", ""); try { subConfiguration.getInt("testString"); fail("Expected NumberFormatException to be thrown"); } catch (NumberFormatException ex) { assertEquals("ex.getMessage()", "For input string: \"\"", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testConstructor1() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); assertEquals("subConfiguration.prefix", "testSubConfigurationPrefix", subConfiguration.prefix); }
@Test public void testGetDoubleThrowsNullPointerException1() throws Throwable { Configuration cfg = new SubConfiguration(new SubConfiguration(), "testSubConfigurationPrefix"); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix1"); try { subConfiguration.getDouble("testSubConfigurationPropertyName", 100.0); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetLongThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.getLong("testSubConfigurationPropertyName", 100L); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetIntThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.getInt("testSubConfigurationPropertyName", 100); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetDoubleThrowsNumberFormatException() throws Throwable { Configuration cfg = new SimpleConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); subConfiguration.put("testString", "false"); try { subConfiguration.getDouble("testString"); fail("Expected NumberFormatException to be thrown"); } catch (NumberFormatException ex) { assertEquals("ex.getMessage()", "For input string: \"false\"", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetIntThrowsNumberFormatException() throws Throwable { Configuration cfg = new SimpleConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); subConfiguration.put("testString", ""); try { subConfiguration.getInt("testString", 100); fail("Expected NumberFormatException to be thrown"); } catch (NumberFormatException ex) { assertEquals("ex.getMessage()", "For input string: \"\"", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetLongThrowsNumberFormatException() throws Throwable { Configuration cfg = new SimpleConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); subConfiguration.put("testString", "false"); try { subConfiguration.getLong("testString", 100L); fail("Expected NumberFormatException to be thrown"); } catch (NumberFormatException ex) { assertEquals("ex.getMessage()", "For input string: \"false\"", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testGetAllThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.getAll("testSubConfigurationPropertyName"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
/** * Creates a new object, it takes the class from the value of the property * <code>propertyName</code> * @param propertyName Property whose value is the class name of * the object being created. */ public Object getObject (String propertyName) throws ConfigurationException{ try{ Object ret = Class.forName (get (propertyName)).newInstance(); if(ret instanceof Configurable) ((Configurable)ret).setConfiguration(this); return ret; } catch (Exception e){ throw new ConfigurationException ("Error trying to create an " + "object from property " + prefix + propertyName, e ); } } @Override
@Test public void testSetPrefix() throws Throwable { SubConfiguration subConfiguration = new SubConfiguration(); subConfiguration.setPrefix("testSubConfigurationNewPrefix"); assertEquals("subConfiguration.prefix", "testSubConfigurationNewPrefix", subConfiguration.prefix); } }
@Test public void testGetObjectThrowsConfigurationException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.getObject("testSubConfigurationPropertyName"); fail("Expected ConfigurationException to be thrown"); } catch (ConfigurationException ex) { assertEquals("ex.getMessage()", "Error trying to create an object from property testSubConfigurationPrefixtestSubConfigurationPropertyName", ex.getMessage()); assertNull("ex.getNested().getMessage()", ex.getNested().getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }
@Test public void testConstructor() throws Throwable { new SubConfiguration(); assertTrue("Test completed without Exception", true); }
@Test public void testGetDoubleThrowsNullPointerException() throws Throwable { Configuration cfg = new SubConfiguration(); SubConfiguration subConfiguration = new SubConfiguration(cfg, "testSubConfigurationPrefix"); try { subConfiguration.getDouble("testSubConfigurationPropertyName"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertSame("subConfiguration.cfg", cfg, subConfiguration.cfg); } }