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 org.apache.maven.doxia.site.SiteModel; |
25 |
|
import org.apache.maven.project.MavenProject; |
26 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
27 |
|
import org.devacfr.maven.skins.reflow.model.Footer; |
28 |
|
import org.devacfr.maven.skins.reflow.model.Navbar; |
29 |
|
import org.devacfr.maven.skins.reflow.model.ScrollTop; |
30 |
|
import org.devacfr.maven.skins.reflow.model.Toc; |
31 |
|
import org.devacfr.maven.skins.reflow.model.TocTopBar; |
32 |
|
import org.devacfr.testing.jupiter.MockitoTestCase; |
33 |
|
import org.junit.jupiter.api.BeforeEach; |
34 |
|
import org.junit.jupiter.api.Test; |
35 |
|
import org.mockito.Mock; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (44) |
Complexity: 3 |
Complexity Density: 0,07 |
|
37 |
|
public class PageContextTest extends MockitoTestCase { |
38 |
|
|
39 |
|
@Mock |
40 |
|
private ISkinConfig config; |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
42 |
2 |
@SuppressWarnings("unchecked")... |
43 |
|
@BeforeEach |
44 |
|
public void setup() { |
45 |
2 |
final MavenProject project = new MavenProject(); |
46 |
2 |
project.setName("reflow"); |
47 |
2 |
project.setArtifactId("reflow-artifact"); |
48 |
2 |
when(config.getProject()).thenReturn(project); |
49 |
|
|
50 |
2 |
final SiteModel model = new SiteModel(); |
51 |
2 |
when(config.getSiteModel()).thenReturn(model); |
52 |
2 |
when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class))) |
53 |
|
.then(invocation -> invocation.getArguments()[3]); |
54 |
2 |
when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class))) |
55 |
|
.then(invocation -> invocation.getArguments()[2]); |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0,04 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void shouldBuildPageContext() { |
63 |
1 |
when(config.getPropertyValue(Toc.COMPONENT, String.class, null)).thenReturn("top"); |
64 |
|
|
65 |
1 |
final Context<?> context = Context.buildContext(config); |
66 |
1 |
assertThat((PageContext) context, isA(PageContext.class)); |
67 |
|
|
68 |
1 |
final PageContext pageContext = (PageContext) context; |
69 |
|
|
70 |
1 |
final Toc<?> toc = pageContext.getToc(); |
71 |
1 |
assertNotNull(toc, "toc should be exist"); |
72 |
1 |
assertEquals(true, toc.isEnabled()); |
73 |
1 |
assertThat((TocTopBar) pageContext.getToc(), isA(TocTopBar.class)); |
74 |
1 |
final TocTopBar tocTopBar = (TocTopBar) toc; |
75 |
1 |
assertEquals("m-toc-top-enabled", tocTopBar.getCssOptions()); |
76 |
1 |
assertEquals("navbar-light bg-light", tocTopBar.getCssClass()); |
77 |
|
|
78 |
1 |
final Footer footer = pageContext.getFooter(); |
79 |
1 |
assertNotNull(footer, "footer should be exist"); |
80 |
1 |
assertEquals("footer-light bg-light", footer.getCssClass()); |
81 |
1 |
assertEquals("", footer.getCssOptions()); |
82 |
|
|
83 |
1 |
final Navbar navbar = pageContext.getNavbar(); |
84 |
1 |
assertNotNull(navbar, "Navbar should be exist"); |
85 |
1 |
assertEquals("navbar-light bg-light", navbar.getCssClass()); |
86 |
1 |
assertEquals("", navbar.getCssOptions()); |
87 |
|
|
88 |
1 |
final ScrollTop scrollTop = pageContext.getScrollTop(); |
89 |
1 |
assertNotNull(scrollTop, "ScrollTop should be exist"); |
90 |
1 |
assertEquals("", scrollTop.getCssClass()); |
91 |
1 |
assertEquals(true, scrollTop.isSmooth()); |
92 |
1 |
assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions()); |
93 |
|
|
94 |
1 |
assertEquals("anchorjs-enabled scrolltop-smooth-enabled m-toc-top-enabled", pageContext.getCssOptions()); |
95 |
1 |
assertEquals("", pageContext.getCssClass()); |
96 |
1 |
assertEquals("page", pageContext.getType()); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void shouldBuildPageContextWithTocDisabled() { |
101 |
1 |
final Context<?> context = Context.buildContext(config); |
102 |
1 |
assertThat((PageContext) context, isA(PageContext.class)); |
103 |
|
|
104 |
1 |
final PageContext pageContext = (PageContext) context; |
105 |
|
|
106 |
1 |
final Toc<?> toc = pageContext.getToc(); |
107 |
1 |
assertNotNull(toc, "toc should be exist"); |
108 |
1 |
assertEquals(false, toc.isEnabled()); |
109 |
|
} |
110 |
|
} |