X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouterTest.java;h=c1776f475e8723e677530c2c0382f7e56890a23f;hb=f8027d76e1c3e517a8b80a3476f51adee845fc5b;hp=2746253de58653f31b04a21d63ef990f89680b44;hpb=e52385618670b54a5c6a4f2fbfab381bef43a905;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java index 2746253..c1776f4 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java @@ -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(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(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(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("trans")); + when(transformation.getId()).thenReturn( + new Id(UUID.randomUUID().toString())); when(transformation.getFromType()).thenReturn(aFrom); when(transformation.getToType()).thenReturn(aTo); when(transformation.transform(same(aSource))).thenReturn(aTarget);