git://wamblee.org
/
xmlrouter
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
First version after introduction of meaningful ids and Identifiable interface.
[xmlrouter]
/
impl
/
src
/
test
/
java
/
org
/
wamblee
/
xmlrouter
/
impl
/
ConfigImplTest.java
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 98296d4d8cc110bf2174340fbe13478576b0ef06..5e3ad92059625e3b4b5e1a5152da4ed0e9feefd1 100644
(file)
--- 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.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 {
public class ConfigImplTest {
- private static interface MyType {
+ private static interface MyType
extends Identifiable
{
}
private static class MyTypeWrapper implements MyType {
}
private static class MyTypeWrapper implements MyType {
- private Id<MyType> id;
private MyType type;
private MyType type;
- public MyTypeWrapper(Id<MyType> aId, MyType aType) {
- id = aId;
+ public MyTypeWrapper(MyType aType) {
type = aType;
}
public MyType getType() {
return type;
}
type = aType;
}
public MyType getType() {
return type;
}
+
+ @Override
+ public Id getId() {
+ return type.getId();
+ }
}
private AtomicLong sequence;
}
private AtomicLong sequence;
@@
-50,10
+55,10
@@
public class ConfigImplTest {
@Before
public void setUp() {
sequence = new AtomicLong(1L);
@Before
public void setUp() {
sequence = new AtomicLong(1L);
- config = new ConfigImpl<MyType>(
sequence
) {
+ config = new ConfigImpl<MyType>(
new Id<Config>("mytype")
) {
@Override
@Override
- public MyType wrap(
Id<MyType> aId,
MyType aT) {
- return new MyTypeWrapper(a
Id, a
T);
+ public MyType wrap(MyType aT) {
+ return new MyTypeWrapper(aT);
}
};
}
}
};
}
@@
-61,47
+66,37
@@
public class ConfigImplTest {
@Test
public void testAdd() {
MyType type1 = mock(MyType.class);
@Test
public void testAdd() {
MyType type1 = mock(MyType.class);
- assertFalse(config.isDirty());
-
- Id<MyType> id1 = config.add(type1);
+ when(type1.getId()).thenReturn(new Id("type1"));
- assertNotNull(id1);
- assertEquals(1, config.map().size());
- assertTrue(config.map().get(id1) instanceof MyTypeWrapper);
- assertSame(type1, ((MyTypeWrapper) config.map().get(id1)).getType());
- assertTrue(config.isDirty());
+ config.add(type1);
- config.resetDirty();
- assertFalse(config.isDirty());
+ 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);
// add another one.
MyType type2 = mock(MyType.class);
- Id<MyType> id2 = config.add(type2);
- assertNotNull(id2);
- assertEquals(2, config.map().size());
- assertFalse(id1.equals(id2));
- assertTrue(config.isDirty());
+ when(type2.getId()).thenReturn(new Id("type2"));
+ config.add(type2);
+ assertEquals(2, config.values().size());
}
@Test
public void testRemove() {
MyType type1 = mock(MyType.class);
}
@Test
public void testRemove() {
MyType type1 = mock(MyType.class);
-
Id<MyType> id1 = config.add(type1
);
+
when(type1.getId()).thenReturn(new Id("type1")
);
- assertNotNull(id1);
- assertEquals(1, config.map().size());
+ config.add(type1);
- config.resetDirty();
- assertFalse(config.isDirty());
+ assertEquals(1, config.values().size());
- config.remove(id1);
- assertTrue(config.map().isEmpty());
- assertTrue(config.isDirty());
+ assertTrue(config.remove(new Id("type1")));
+ assertTrue(config.values().isEmpty());
}
@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiable() {
}
@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiable() {
- config.
map().put(new Id<MyType>(100L),
mock(MyType.class));
+ config.
values().add(
mock(MyType.class));
}
}
}
}