1. Project Clover database mer. févr. 4 2026 12:48:44 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 2 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  2 toggle @SuppressWarnings("unchecked")
40    @BeforeEach
41    public void setup() {
42  2 final MavenProject project = new MavenProject();
43  2 project.setName("reflow");
44  2 project.setArtifactId("reflow-artifact");
45  2 when(config.getProject()).thenReturn(project);
46   
47  2 final SiteModel model = new SiteModel();
48  2 when(config.getFileId()).thenReturn("currentFile");
49  2 when(config.getSiteModel()).thenReturn(model);
50  2 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class)))
51    .then(invocation -> invocation.getArguments()[3]);
52  2 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  1 toggle @Test
60    public void shouldBuildPageContext() {
61  1 when(config.getPropertyValue(Toc.COMPONENT, String.class, null)).thenReturn("top");
62   
63  1 final Context<?> context = Context.buildContext(config);
64  1 assertThat((PageContext) context, isA(PageContext.class));
65   
66  1 final PageContext pageContext = (PageContext) context;
67   
68  1 final Toc<?> toc = pageContext.getToc();
69  1 assertNotNull(toc, "toc should be exist");
70  1 assertEquals(true, toc.isEnabled());
71  1 assertThat((TocTopBar) pageContext.getToc(), isA(TocTopBar.class));
72  1 final TocTopBar tocTopBar = (TocTopBar) toc;
73  1 assertEquals("toc-top-enabled", tocTopBar.getCssOptions());
74  1 assertEquals("navbar-light bg-light", tocTopBar.getCssClass());
75   
76  1 final Footer footer = pageContext.getFooter();
77  1 assertNotNull(footer, "footer should be exist");
78  1 assertEquals("footer-light bg-light", footer.getCssClass());
79  1 assertEquals("", footer.getCssOptions());
80   
81  1 final Navbar navbar = pageContext.getNavbar();
82  1 assertNotNull(navbar, "Navbar should be exist");
83  1 assertEquals("navbar-light bg-light", navbar.getCssClass());
84  1 assertEquals("", navbar.getCssOptions());
85   
86  1 final ScrollTop scrollTop = pageContext.getScrollTop();
87  1 assertNotNull(scrollTop, "ScrollTop should be exist");
88  1 assertEquals("", scrollTop.getCssClass());
89  1 assertEquals(true, scrollTop.isSmooth());
90  1 assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions());
91   
92  1 assertEquals("anchorjs-enabled scrolltop-smooth-enabled toc-top-enabled", pageContext.getCssOptions());
93  1 assertEquals("", pageContext.getCssClass());
94  1 assertEquals("page", pageContext.getType());
95    }
96   
 
97  1 toggle @Test
98    public void shouldBuildPageContextWithTocDisabled() {
99  1 final Context<?> context = Context.buildContext(config);
100  1 assertThat((PageContext) context, isA(PageContext.class));
101   
102  1 final PageContext pageContext = (PageContext) context;
103   
104  1 final Toc<?> toc = pageContext.getToc();
105  1 assertNotNull(toc, "toc should be exist");
106  1 assertEquals(false, toc.isEnabled());
107    }
108    }