1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.maven.skins.reflow.context; |
20 |
|
|
21 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
22 |
|
import static org.hamcrest.Matchers.isA; |
23 |
|
|
24 |
|
import java.io.StringReader; |
25 |
|
|
26 |
|
import org.apache.maven.doxia.site.SiteModel; |
27 |
|
import org.apache.maven.project.MavenProject; |
28 |
|
import org.codehaus.plexus.util.xml.Xpp3Dom; |
29 |
|
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
30 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
31 |
|
import org.devacfr.maven.skins.reflow.model.Footer; |
32 |
|
import org.devacfr.maven.skins.reflow.model.Navbar; |
33 |
|
import org.devacfr.maven.skins.reflow.model.ScrollTop; |
34 |
|
import org.devacfr.testing.jupiter.MockitoTestCase; |
35 |
|
import org.junit.jupiter.api.BeforeEach; |
36 |
|
import org.junit.jupiter.api.Test; |
37 |
|
import org.mockito.Mock; |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 3 |
Complexity Density: 0,08 |
|
39 |
|
public class BodyContextTest extends MockitoTestCase { |
40 |
|
|
41 |
|
@Mock |
42 |
|
private ISkinConfig config; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
44 |
2 |
@SuppressWarnings("unchecked")... |
45 |
|
@BeforeEach |
46 |
|
public void setup() { |
47 |
2 |
final MavenProject project = new MavenProject(); |
48 |
2 |
project.setName("reflow"); |
49 |
2 |
project.setArtifactId("reflow-artifact"); |
50 |
2 |
when(config.getProject()).thenReturn(project); |
51 |
|
|
52 |
2 |
final SiteModel model = new SiteModel(); |
53 |
2 |
when(config.getSiteModel()).thenReturn(model); |
54 |
2 |
when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class))) |
55 |
|
.then(invocation -> invocation.getArguments()[3]); |
56 |
2 |
when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class))) |
57 |
|
.then(invocation -> invocation.getArguments()[2]); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0,05 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void shouldBuildBodyContext() throws Exception { |
62 |
1 |
final Xpp3Dom pageProperties = Xpp3DomBuilder.build(new StringReader("<document type=\"body\"></document>")); |
63 |
1 |
when(config.getPageProperties()).thenReturn(pageProperties); |
64 |
|
|
65 |
1 |
final Context<?> context = Context.buildContext(config); |
66 |
1 |
assertThat((BodyContext) context, isA(BodyContext.class)); |
67 |
|
|
68 |
1 |
final BodyContext bodyContext = (BodyContext) context; |
69 |
|
|
70 |
1 |
final Footer footer = bodyContext.getFooter(); |
71 |
1 |
assertNotNull(footer, "footer should be exist"); |
72 |
1 |
assertEquals("footer-light bg-light", footer.getCssClass()); |
73 |
1 |
assertEquals("", footer.getCssOptions()); |
74 |
|
|
75 |
1 |
final Navbar navbar = bodyContext.getNavbar(); |
76 |
1 |
assertNotNull(navbar, "Navbar should be exist"); |
77 |
1 |
assertEquals("navbar-light bg-light", navbar.getCssClass()); |
78 |
1 |
assertEquals("", navbar.getCssOptions()); |
79 |
|
|
80 |
1 |
final ScrollTop scrollTop = bodyContext.getScrollTop(); |
81 |
1 |
assertNotNull(scrollTop, "ScrollTop should be exist"); |
82 |
1 |
assertEquals("", scrollTop.getCssClass()); |
83 |
1 |
assertEquals(true, scrollTop.isSmooth()); |
84 |
1 |
assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions()); |
85 |
|
|
86 |
1 |
assertEquals("scrolltop-smooth-enabled", bodyContext.getCssOptions()); |
87 |
1 |
assertEquals("", bodyContext.getCssClass()); |
88 |
1 |
assertEquals("body", bodyContext.getType()); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void shouldRenderBodyWihoutModify() throws Exception { |
93 |
1 |
final Xpp3Dom pageProperties = Xpp3DomBuilder.build(new StringReader("<document type=\"body\"></document>")); |
94 |
1 |
when(config.getPageProperties()).thenReturn(pageProperties); |
95 |
|
|
96 |
1 |
final Context<?> context = Context.buildContext(config); |
97 |
1 |
assertThat((BodyContext) context, isA(BodyContext.class)); |
98 |
|
|
99 |
1 |
final BodyContext bodyContext = (BodyContext) context; |
100 |
|
|
101 |
1 |
verify((content) -> { |
102 |
1 |
when(config.getContextValue("bodyContent", String.class)).thenReturn(content); |
103 |
1 |
return bodyContext.preRender(config); |
104 |
|
}, "html"); |
105 |
|
} |
106 |
|
} |