1. Project Clover database mer. févr. 4 2026 12:48:28 CET
  2. Package org.devacfr.maven.skins.reflow.context

File PageContextTest.java

 

Code metrics

0
42
3
1
108
73
3
0,07
14
3
1

Classes

Class Line # Actions
PageContextTest 34 42 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * Copyright 2012-2025 Christophe Friederich
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.devacfr.maven.skins.reflow.context;
17   
18    import static org.hamcrest.MatcherAssert.assertThat;
19    import static org.hamcrest.Matchers.isA;
20   
21    import org.apache.maven.doxia.site.SiteModel;
22    import org.apache.maven.project.MavenProject;
23    import org.devacfr.maven.skins.reflow.ISkinConfig;
24    import org.devacfr.maven.skins.reflow.model.Footer;
25    import org.devacfr.maven.skins.reflow.model.Navbar;
26    import org.devacfr.maven.skins.reflow.model.ScrollTop;
27    import org.devacfr.maven.skins.reflow.model.Toc;
28    import org.devacfr.maven.skins.reflow.model.TocTopBar;
29    import org.devacfr.testing.jupiter.MockitoTestCase;
30    import org.junit.jupiter.api.BeforeEach;
31    import org.junit.jupiter.api.Test;
32    import org.mockito.Mock;
33   
 
34    public class PageContextTest extends MockitoTestCase {
35   
36    @Mock
37    private ISkinConfig config;
38   
 
39  4 toggle @SuppressWarnings("unchecked")
40    @BeforeEach
41    public void setup() {
42  4 final MavenProject project = new MavenProject();
43  4 project.setName("reflow");
44  4 project.setArtifactId("reflow-artifact");
45  4 when(config.getProject()).thenReturn(project);
46   
47  4 final SiteModel model = new SiteModel();
48  4 when(config.getFileId()).thenReturn("currentFile");
49  4 when(config.getSiteModel()).thenReturn(model);
50  4 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class)))
51    .then(invocation -> invocation.getArguments()[3]);
52  4 when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class)))
53    .then(invocation -> invocation.getArguments()[2]);
54    }
55   
56    /**
57    * test the page context is the default context when any type is defined.
58    */
 
59  2 toggle @Test
60    public void shouldBuildPageContext() {
61  2 when(config.getPropertyValue(Toc.COMPONENT, String.class, null)).thenReturn("top");
62   
63  2 final Context<?> context = Context.buildContext(config);
64  2 assertThat((PageContext) context, isA(PageContext.class));
65   
66  2 final PageContext pageContext = (PageContext) context;
67   
68  2 final Toc<?> toc = pageContext.getToc();
69  2 assertNotNull(toc, "toc should be exist");
70  2 assertEquals(true, toc.isEnabled());
71  2 assertThat((TocTopBar) pageContext.getToc(), isA(TocTopBar.class));
72  2 final TocTopBar tocTopBar = (TocTopBar) toc;
73  2 assertEquals("toc-top-enabled", tocTopBar.getCssOptions());
74  2 assertEquals("navbar-light bg-light", tocTopBar.getCssClass());
75   
76  2 final Footer footer = pageContext.getFooter();
77  2 assertNotNull(footer, "footer should be exist");
78  2 assertEquals("footer-light bg-light", footer.getCssClass());
79  2 assertEquals("", footer.getCssOptions());
80   
81  2 final Navbar navbar = pageContext.getNavbar();
82  2 assertNotNull(navbar, "Navbar should be exist");
83  2 assertEquals("navbar-light bg-light", navbar.getCssClass());
84  2 assertEquals("", navbar.getCssOptions());
85   
86  2 final ScrollTop scrollTop = pageContext.getScrollTop();
87  2 assertNotNull(scrollTop, "ScrollTop should be exist");
88  2 assertEquals("", scrollTop.getCssClass());
89  2 assertEquals(true, scrollTop.isSmooth());
90  2 assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions());
91   
92  2 assertEquals("anchorjs-enabled scrolltop-smooth-enabled toc-top-enabled", pageContext.getCssOptions());
93  2 assertEquals("", pageContext.getCssClass());
94  2 assertEquals("page", pageContext.getType());
95    }
96   
 
97  2 toggle @Test
98    public void shouldBuildPageContextWithTocDisabled() {
99  2 final Context<?> context = Context.buildContext(config);
100  2 assertThat((PageContext) context, isA(PageContext.class));
101   
102  2 final PageContext pageContext = (PageContext) context;
103   
104  2 final Toc<?> toc = pageContext.getToc();
105  2 assertNotNull(toc, "toc should be exist");
106  2 assertEquals(false, toc.isEnabled());
107    }
108    }