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.module.googlesitemap.app.subapp.sitemapdetail.contentviews.formatter; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.Mockito.mock; |
39 |
|
|
40 |
|
import info.magnolia.jcr.util.NodeTypes; |
41 |
|
import info.magnolia.test.mock.jcr.MockNode; |
42 |
|
import info.magnolia.ui.vaadin.integration.jcr.DefaultProperty; |
43 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
44 |
|
import info.magnolia.ui.workbench.column.definition.PropertyColumnDefinition; |
45 |
|
|
46 |
|
import javax.jcr.Node; |
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
|
49 |
|
import org.junit.Before; |
50 |
|
import org.junit.Test; |
51 |
|
import org.mockito.Mockito; |
52 |
|
|
53 |
|
import com.vaadin.data.Item; |
54 |
|
import com.vaadin.ui.Table; |
55 |
|
|
56 |
|
|
57 |
|
@link |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 5 |
Complexity Density: 0.21 |
|
59 |
|
public class FolderNameColumnFormatterTest { |
60 |
|
|
61 |
|
private final String columnId = "displayName"; |
62 |
|
|
63 |
|
private Table table; |
64 |
|
private Item item; |
65 |
|
private Object itemId; |
66 |
|
|
67 |
|
private PropertyColumnDefinition propertyColumnDefinition; |
68 |
|
private FolderNameColumnFormatter folderNameColumnFormatter; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
70 |
4 |
@Before... |
71 |
|
public void setIp() { |
72 |
4 |
table = mock(Table.class); |
73 |
4 |
item = mock(Item.class); |
74 |
4 |
itemId = item; |
75 |
|
|
76 |
4 |
propertyColumnDefinition = new PropertyColumnDefinition(); |
77 |
4 |
folderNameColumnFormatter = new FolderNameColumnFormatter(propertyColumnDefinition); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testGenerateCellWhenFolder() throws RepositoryException { |
82 |
|
|
83 |
1 |
final String nodeName = "nodeName"; |
84 |
|
|
85 |
1 |
JcrNodeAdapter nodeAdapter = mock(JcrNodeAdapter.class); |
86 |
1 |
Node node = new MockNode(nodeName, NodeTypes.Folder.NAME); |
87 |
|
|
88 |
1 |
Mockito.when(nodeAdapter.getJcrItem()).thenReturn(node); |
89 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(nodeAdapter); |
90 |
|
|
91 |
|
|
92 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
93 |
|
|
94 |
|
|
95 |
1 |
assertThat((String) cell, is(nodeName)); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testGenerateCellWhenItemPropertyIsNotNull() { |
100 |
|
|
101 |
1 |
final String value = "testValue"; |
102 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(item); |
103 |
1 |
Mockito.when(item.getItemProperty(columnId)).thenReturn(new DefaultProperty(value)); |
104 |
|
|
105 |
|
|
106 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
107 |
|
|
108 |
|
|
109 |
1 |
assertThat((String) cell, is(value)); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void testGenerateCellWhenItemPropertyIsNull() { |
114 |
|
|
115 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(item); |
116 |
1 |
Mockito.when(item.getItemProperty(columnId)).thenReturn(null); |
117 |
|
|
118 |
|
|
119 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
120 |
|
|
121 |
|
|
122 |
1 |
assertThat((String) cell, is("")); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testGenerateCellWhenItemIsNull() { |
127 |
|
|
128 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(null); |
129 |
|
|
130 |
|
|
131 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
132 |
|
|
133 |
|
|
134 |
1 |
assertThat((String) cell, is("")); |
135 |
|
} |
136 |
|
|
137 |
|
} |