2 * Copyright 2005-2011 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.xmlrouter.impl;
18 import static junit.framework.Assert.*;
19 import static org.mockito.Matchers.*;
20 import static org.mockito.Mockito.*;
22 import javax.xml.transform.dom.DOMSource;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.wamblee.xmlrouter.common.Id;
27 import org.wamblee.xmlrouter.config.DocumentType;
29 public class RobustDocumentTypeTest {
31 private DocumentType documentType;
32 private DocumentType robust;
33 private DOMSource source;
37 documentType = mock(DocumentType.class);
38 when(documentType.getId()).thenReturn(new Id<DocumentType>("docid"));
39 robust = new RobustDocumentType(documentType);
40 source = mock(DOMSource.class);
44 public void testNoEzception() {
45 when(documentType.isInstance(any(DOMSource.class))).thenReturn(true);
46 when(documentType.getName()).thenReturn("hello");
47 assertTrue(robust.isInstance(source));
48 assertEquals("hello", robust.getName());
50 verify(documentType).isInstance(same(source));
53 when(documentType.isInstance(any(DOMSource.class))).thenReturn(false);
54 assertFalse(robust.isInstance(source));
55 verify(documentType).isInstance(same(source));
59 public void testExceptionInIsInstance() {
60 doThrow(new RuntimeException("bla")).when(documentType).isInstance(
61 any(DOMSource.class));
62 assertFalse(robust.isInstance(source));
63 verify(documentType).isInstance(same(source));
67 public void testExceptionInValidate() {
68 doThrow(new RuntimeException("bla")).when(documentType).validate(
69 any(DOMSource.class));
70 assertFalse(robust.validate(source));
71 verify(documentType).validate(same(source));
75 public void testExceptionInGetName() {
76 doThrow(new RuntimeException("bla")).when(documentType).getName();
77 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
82 public void testGetNameReturnsNull() {
83 when(documentType.getName()).thenReturn(null);
84 assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),