removed the prefix argument from ConfigImpl.wrap().
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / RobustDocumentTypeTest.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.xmlrouter.impl;
17
18 import static junit.framework.Assert.*;
19 import static org.mockito.Matchers.*;
20 import static org.mockito.Mockito.*;
21
22 import javax.xml.transform.dom.DOMSource;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.wamblee.xmlrouter.common.Id;
27 import org.wamblee.xmlrouter.config.DocumentType;
28
29 public class RobustDocumentTypeTest {
30
31     private DocumentType documentType;
32     private DocumentType robust;
33     private DOMSource source;
34
35     @Before
36     public void setUp() {
37         documentType = mock(DocumentType.class);
38         when(documentType.getId()).thenReturn(new Id<DocumentType>("docid"));
39         robust = new RobustDocumentType(documentType);
40         source = mock(DOMSource.class);
41     }
42
43     @Test
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());
49
50         verify(documentType).isInstance(same(source));
51
52         reset(documentType);
53         when(documentType.isInstance(any(DOMSource.class))).thenReturn(false);
54         assertFalse(robust.isInstance(source));
55         verify(documentType).isInstance(same(source));
56     }
57
58     @Test
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));
64     }
65
66     @Test
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));
72     }
73
74     @Test
75     public void testExceptionInGetName() {
76         doThrow(new RuntimeException("bla")).when(documentType).getName();
77         assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
78             robust.getName());
79     }
80
81     @Test
82     public void testGetNameReturnsNull() {
83         when(documentType.getName()).thenReturn(null);
84         assertEquals(Constants.UNKNOWN_DOCUMENT_TYPE.toString(),
85             robust.getName());
86     }
87 }