RobustIdentifiable implemented and tested + test impacts.
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / XMLRouterTest.java
index 2746253de58653f31b04a21d63ef990f89680b44..ae40327050f34eae08805923a65397fc5096d0a1 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);
     }