X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FConfigImplTest.java;h=85860122b71c75bcac18fb61a6b469e000ffb780;hb=5582d07a1ba9821cc789ea63b71f246e89d13cae;hp=8ebdb9f4aa16c2246dc5ff50b494239fab9dc1c8;hpb=f8027d76e1c3e517a8b80a3476f51adee845fc5b;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java index 8ebdb9f..8586012 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java @@ -53,18 +53,28 @@ public class ConfigImplTest { } } + public static final class MyTypeConfig extends ConfigImpl { + public MyTypeConfig(Id aId) { + super(MyType.class, aId); + } + + public MyTypeConfig(MyTypeConfig aConfig) { + super(aConfig); + } + + @Override + public MyType wrap(String aPrefix, MyType aT) { + return new MyTypeWrapper(aPrefix, aT); + } + } + private AtomicLong sequence; - private ExtendedConfig config; + private MyTypeConfig config; @Before public void setUp() { sequence = new AtomicLong(1L); - config = new ConfigImpl(new Id(CONFIG_TYPE)) { - @Override - public MyType wrap(String aPrefix, MyType aT) { - return new MyTypeWrapper(aPrefix, aT); - } - }; + config = new MyTypeConfig(new Id(CONFIG_TYPE)); } @Test @@ -111,22 +121,11 @@ public class ConfigImplTest { @Test public void testEquals() { - Config config1 = new ConfigImpl(new Id( - CONFIG_TYPE)) { - @Override - public MyType wrap(String aPrefix, MyType aT) { - return new MyTypeWrapper(aPrefix, aT); - } - }; + Config config1 = new MyTypeConfig(new Id(CONFIG_TYPE)); assertFalse(config1.equals(null)); assertFalse(config1.equals("hello")); - Config config2 = new ConfigImpl(new Id( - CONFIG_TYPE)) { - @Override - public MyType wrap(String aPrefix, MyType aT) { - return new MyTypeWrapper(aPrefix, aT); - } - }; + Config config2 = new MyTypeConfig(new Id(CONFIG_TYPE)); + assertEquals(config1, config2); assertEquals(config1.hashCode(), config2.hashCode()); @@ -146,4 +145,18 @@ public class ConfigImplTest { assertTrue(config2.remove(type2.getId())); assertFalse(config1.equals(config2)); } + + @Test + public void testCopy() { + testAdd(); + assertEquals(2, config.values().size()); + MyTypeConfig copy = new MyTypeConfig(config); + assertEquals(config.getId(), config.getId()); + assertEquals(config, copy); + + // verify the copy is not shallow + assertTrue(config.remove(new Id("type1"))); + assertEquals(1, config.values().size()); + assertFalse(config.equals(copy)); + } }