1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.resources.app.availability; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
38 |
|
import static org.mockito.BDDMockito.given; |
39 |
|
import static org.mockito.Matchers.anyString; |
40 |
|
import static org.mockito.Mockito.mock; |
41 |
|
|
42 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
43 |
|
import info.magnolia.resourceloader.layered.LayeredResource; |
44 |
|
|
45 |
|
import org.junit.Before; |
46 |
|
import org.junit.Test; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.2 |
|
48 |
|
public class IsFileRuleTest { |
49 |
|
|
50 |
|
private IsFileRule rule; |
51 |
|
private LayeredResource layeredResource; |
52 |
|
|
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
54 |
3 |
@Before... |
55 |
|
public void setUp() throws Exception { |
56 |
3 |
ResourceOrigin origin = mock(ResourceOrigin.class); |
57 |
3 |
rule = new IsFileRule(origin); |
58 |
3 |
layeredResource = mock(LayeredResource.class); |
59 |
|
|
60 |
3 |
given(origin.hasPath(anyString())).willReturn(true); |
61 |
3 |
given(origin.getByPath(anyString())).willReturn(layeredResource); |
62 |
|
} |
63 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
64 |
|
@Test... |
65 |
|
public void isAvailableForFile() { |
66 |
|
|
67 |
|
String filePath = "/a/a.txt"; |
68 |
|
given(layeredResource.isFile()).willReturn(true); |
69 |
|
|
70 |
|
|
71 |
|
boolean isFile = rule.isAvailableForItem(filePath); |
72 |
|
|
73 |
|
|
74 |
|
assertThat(isFile, is(true)); |
75 |
|
} |
76 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
77 |
|
@Test... |
78 |
|
public void isNotAvailableForFolder() { |
79 |
|
|
80 |
|
String folderPath = "/a"; |
81 |
|
given(layeredResource.isFile()).willReturn(false); |
82 |
|
|
83 |
|
|
84 |
|
boolean isFile = rule.isAvailableForItem(folderPath); |
85 |
|
|
86 |
|
|
87 |
|
assertThat(isFile, is(false)); |
88 |
|
} |
89 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
90 |
|
@Test... |
91 |
|
public void isNotAvailableForNonResourcePathItems() { |
92 |
|
|
93 |
|
String wrongInstanceType = ""; |
94 |
|
|
95 |
|
boolean isFile = rule.isAvailableForItem(wrongInstanceType); |
96 |
|
|
97 |
|
assertThat(isFile, is(false)); |
98 |
|
} |
99 |
|
} |