X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FConfigImplTest.java;h=5e3ad92059625e3b4b5e1a5152da4ed0e9feefd1;hb=e52385618670b54a5c6a4f2fbfab381bef43a905;hp=1e8cfc3b35c1ef5ce9a0631f9ce8dee0d0525570;hpb=0db97b9f39c69528900f915dd2bb463c27debe39;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 1e8cfc3..5e3ad92 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java @@ -23,25 +23,30 @@ import java.util.concurrent.atomic.AtomicLong; import org.junit.Before; import org.junit.Test; import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.Config; +import org.wamblee.xmlrouter.config.Identifiable; public class ConfigImplTest { - private static interface MyType { + private static interface MyType extends Identifiable { } private static class MyTypeWrapper implements MyType { - private Id id; private MyType type; - public MyTypeWrapper(Id aId, MyType aType) { - id = aId; + public MyTypeWrapper(MyType aType) { type = aType; } public MyType getType() { return type; } + + @Override + public Id getId() { + return type.getId(); + } } private AtomicLong sequence; @@ -50,10 +55,10 @@ public class ConfigImplTest { @Before public void setUp() { sequence = new AtomicLong(1L); - config = new ConfigImpl(sequence) { + config = new ConfigImpl(new Id("mytype")) { @Override - public MyType wrap(Id aId, MyType aT) { - return new MyTypeWrapper(aId, aT); + public MyType wrap(MyType aT) { + return new MyTypeWrapper(aT); } }; } @@ -61,36 +66,37 @@ public class ConfigImplTest { @Test public void testAdd() { MyType type1 = mock(MyType.class); + when(type1.getId()).thenReturn(new Id("type1")); - Id id1 = config.add(type1); + config.add(type1); - assertNotNull(id1); - assertEquals(1, config.map().size()); - assertTrue(config.map().get(id1) instanceof MyTypeWrapper); - assertSame(type1, ((MyTypeWrapper) config.map().get(id1)).getType()); + assertEquals(1, config.values().size()); + assertTrue(config.values().get(0) instanceof MyTypeWrapper); + assertSame(type1, ((MyTypeWrapper) config.values().get(0)).getType()); // add another one. MyType type2 = mock(MyType.class); - Id id2 = config.add(type2); - assertNotNull(id2); - assertEquals(2, config.map().size()); - assertFalse(id1.equals(id2)); + when(type2.getId()).thenReturn(new Id("type2")); + config.add(type2); + + assertEquals(2, config.values().size()); } @Test public void testRemove() { MyType type1 = mock(MyType.class); - Id id1 = config.add(type1); + when(type1.getId()).thenReturn(new Id("type1")); + + config.add(type1); - assertNotNull(id1); - assertEquals(1, config.map().size()); + assertEquals(1, config.values().size()); - config.remove(id1); - assertTrue(config.map().isEmpty()); + assertTrue(config.remove(new Id("type1"))); + assertTrue(config.values().isEmpty()); } @Test(expected = UnsupportedOperationException.class) public void testUnmodifiable() { - config.map().put(new Id(100L), mock(MyType.class)); + config.values().add(mock(MyType.class)); } }