Class |
Line # |
Actions |
|||||
---|---|---|---|---|---|---|---|
PageContextTest | 37 | 41 | 0% | 3 | 0 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
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 | ||
37 | public class PageContextTest extends MockitoTestCase { | |
38 | ||
39 | @Mock | |
40 | private ISkinConfig config; | |
41 | ||
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 | * test the page context is the default context when any type is defined. | |
60 | */ | |
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 | ||
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 | } |