X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustDestinationTest.java;fp=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustDestinationTest.java;h=0000000000000000000000000000000000000000;hb=8e41cb29f75362a792292d21b481bd06a9506296;hp=b92e4887430243b30a0103c0434270166408dd14;hpb=9dbc2844950b55ae552fe74840954ea71b754c7a;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDestinationTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDestinationTest.java deleted file mode 100644 index b92e488..0000000 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDestinationTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2005-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.xmlrouter.impl; - -import static junit.framework.Assert.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import javax.xml.transform.dom.DOMSource; - -import org.junit.Before; -import org.junit.Test; -import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.subscribe.Destination; - -public class RobustDestinationTest { - - private Destination destination; - private Destination robust; - private DOMSource source; - - @Before - public void setUp() { - destination = mock(Destination.class); - robust = new RobustDestination(new Id("100"), destination); - source = mock(DOMSource.class); - } - - @Test - public void testNormalFlow() { - when(destination.getName()).thenReturn("name"); - when( - destination.chooseFromTargetTypes((Collection) anyObject())) - .thenReturn(Arrays.asList("x")); - - assertEquals("name", robust.getName()); - assertEquals(Arrays.asList("x"), - robust.chooseFromTargetTypes(Arrays.asList("x", "y"))); - when(destination.receive(same(source))).thenReturn(true); - assertTrue(robust.receive(source)); - verify(destination).receive(same(source)); - - when(destination.receive(same(source))).thenReturn(false); - assertFalse(robust.receive(source)); - - } - - @Test - public void testNameReturnsNull() { - when(destination.getName()).thenReturn(null); - assertEquals(Constants.UNKNOWN_DESTINATION_NAME.toString(), - robust.getName()); - } - - @Test - public void testNameThrowsException() { - doThrow(new RuntimeException("x")).when(destination).getName(); - assertEquals(Constants.UNKNOWN_DESTINATION_NAME.toString(), - robust.getName()); - } - - @Test - public void testChooseFromTargetTypesReturnsNull() { - when( - destination.chooseFromTargetTypes((Collection) anyObject())) - .thenReturn(null); - assertEquals(Collections.EMPTY_LIST, - robust.chooseFromTargetTypes(Arrays.asList("x"))); - } - - @Test - public void testChooseFromTargetTypesThrowsException() { - doThrow(new RuntimeException("x")).when(destination) - .chooseFromTargetTypes(anyList()); - assertEquals(Collections.EMPTY_LIST, - robust.chooseFromTargetTypes(Arrays.asList("x"))); - } - - @Test - public void testChooseFromTargetTypesReturnsInvalidType() { - when( - destination.chooseFromTargetTypes((Collection) anyObject())) - .thenReturn(Arrays.asList("x", "y")); - assertEquals(Arrays.asList("y"), - robust.chooseFromTargetTypes(Arrays.asList("y", "z"))); - } - - @Test - public void testReceiveThrowsException() { - doThrow(new RuntimeException("x")).when(destination).receive( - any(DOMSource.class)); - assertEquals(false, robust.receive(source)); - } -}