equality based on the ids of the contents of SingleRouterConfig.
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / XMLRouterTest.java
index 2746253de58653f31b04a21d63ef990f89680b44..c1776f475e8723e677530c2c0382f7e56890a23f 100644 (file)
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.*;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.UUID;
 import java.util.logging.Level;
 
 import javax.xml.transform.dom.DOMSource;
@@ -102,7 +103,7 @@ public class XMLRouterTest {
 
     @Test
     public void testMisBehavingDocumentType() {
-        DocumentType type = mock(DocumentType.class);
+        DocumentType type = mockDocument("docid");
         doThrow(new RuntimeException("x")).when(type).isInstance(
             any(DOMSource.class));
         routerConfig.documentTypeConfig().add(type);
@@ -111,10 +112,16 @@ public class XMLRouterTest {
         // no exception should occur.
     }
 
+    private DocumentType mockDocument(String docid) {
+        DocumentType type = mock(DocumentType.class);
+        when(type.getId()).thenReturn(new Id<DocumentType>(docid));
+        return type;
+    }
+
     @Test
     public void testMisBehavingFilter() {
         registerDocumentType("any");
-        Filter filter = mock(Filter.class);
+        Filter filter = mockFilter("filterid");
         doThrow(new RuntimeException("x")).when(filter).isAllowed(anyString(),
             any(DOMSource.class));
         routerConfig.filterConfig().add(filter);
@@ -123,6 +130,12 @@ public class XMLRouterTest {
         // no exception should occur.
     }
 
+    private Filter mockFilter(String filterId) {
+        Filter filter = mock(Filter.class);
+        when(filter.getId()).thenReturn(new Id<Filter>(filterId));
+        return filter;
+    }
+
     @Test
     public void testOneDestinationNoTransformationSuccess() {
         destinationSpy = registerDestination(true, "any");
@@ -147,7 +160,7 @@ public class XMLRouterTest {
     }
 
     private void registerDocumentType(String aType) {
-        DocumentType type = mock(DocumentType.class);
+        DocumentType type = mockDocument(UUID.randomUUID().toString());
         when(type.isInstance(any(DOMSource.class))).thenReturn(true);
         when(type.getName()).thenReturn(aType);
         routerConfig.documentTypeConfig().add(type);
@@ -157,6 +170,7 @@ public class XMLRouterTest {
         DocumentType type = mock(DocumentType.class);
         when(type.isInstance(same(aSource))).thenReturn(true);
         when(type.getName()).thenReturn(aType);
+        when(type.getId()).thenReturn(new Id<DocumentType>(aType));
         routerConfig.documentTypeConfig().add(type);
     }
 
@@ -327,8 +341,8 @@ public class XMLRouterTest {
     private Transformation createTransformation(String aFrom, String aTo,
         DOMSource aSource, DOMSource aTarget) {
         Transformation transformation = mock(Transformation.class);
-        when(transformation.getId())
-            .thenReturn(new Id<Transformation>("trans"));
+        when(transformation.getId()).thenReturn(
+            new Id<Transformation>(UUID.randomUUID().toString()));
         when(transformation.getFromType()).thenReturn(aFrom);
         when(transformation.getToType()).thenReturn(aTo);
         when(transformation.transform(same(aSource))).thenReturn(aTarget);