1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.url.internal.standard; |
21 |
|
|
22 |
|
import org.junit.Rule; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.component.manager.ComponentLookupException; |
25 |
|
import org.xwiki.component.manager.ComponentManager; |
26 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
27 |
|
import org.xwiki.resource.AbstractResourceReference; |
28 |
|
import org.xwiki.resource.ResourceReferenceSerializer; |
29 |
|
import org.xwiki.resource.ResourceType; |
30 |
|
import org.xwiki.resource.UnsupportedResourceReferenceException; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
import org.xwiki.url.ExtendedURL; |
33 |
|
|
34 |
|
import static org.junit.Assert.assertEquals; |
35 |
|
import static org.junit.Assert.fail; |
36 |
|
import static org.mockito.Mockito.*; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 3 |
Complexity Density: 0.21 |
|
44 |
|
public class StandardExtendedURLResourceReferenceSerializerTest |
45 |
|
{ |
46 |
|
@Rule |
47 |
|
public MockitoComponentMockingRule<StandardExtendedURLResourceReferenceSerializer> mocker = |
48 |
|
new MockitoComponentMockingRule<>(StandardExtendedURLResourceReferenceSerializer.class); |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
|
public class TestResourceReference extends AbstractResourceReference |
51 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
2 |
public TestResourceReference()... |
53 |
|
{ |
54 |
2 |
setType(new ResourceType("test")); |
55 |
|
} |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
public void serialize() throws Exception |
60 |
|
{ |
61 |
1 |
TestResourceReference resource = new TestResourceReference(); |
62 |
|
|
63 |
1 |
ResourceReferenceSerializer serializer = mock(ResourceReferenceSerializer.class); |
64 |
|
|
65 |
1 |
ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context"); |
66 |
1 |
when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, |
67 |
|
TestResourceReference.class, ExtendedURL.class), "standard")).thenReturn(serializer); |
68 |
|
|
69 |
1 |
this.mocker.getComponentUnderTest().serialize(resource); |
70 |
|
|
71 |
|
|
72 |
1 |
verify(serializer).serialize(same(resource)); |
73 |
|
} |
74 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
public void serializeWhenNoMatchingSerializer() throws Exception |
77 |
|
{ |
78 |
1 |
TestResourceReference resource = new TestResourceReference(); |
79 |
|
|
80 |
1 |
ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context"); |
81 |
1 |
when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, |
82 |
|
TestResourceReference.class, ExtendedURL.class), "standard")).thenThrow( |
83 |
|
new ComponentLookupException("error")); |
84 |
1 |
when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, |
85 |
|
TestResourceReference.class, ExtendedURL.class))).thenThrow( |
86 |
|
new ComponentLookupException("error")); |
87 |
|
|
88 |
1 |
try { |
89 |
1 |
this.mocker.getComponentUnderTest().serialize(resource); |
90 |
0 |
fail("Should have thrown an exception here"); |
91 |
|
} catch (UnsupportedResourceReferenceException expected) { |
92 |
1 |
assertEquals("Failed to find serializer for Resource Reference [type = [test], parameters = []] and " |
93 |
|
+ "URL format [standard]", expected.getMessage()); |
94 |
|
} |
95 |
|
} |
96 |
|
} |