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

File FrameContextTest.java

 

Code metrics

0
38
2
1
107
78
2
0,05
19
2
1

Classes

Class Line # Actions
FrameContextTest 37 38 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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 java.io.StringReader;
22    import org.apache.maven.doxia.site.SiteModel;
23    import org.apache.maven.project.MavenProject;
24    import org.codehaus.plexus.util.xml.Xpp3Dom;
25    import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
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.TocSidebar;
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 FrameContextTest extends MockitoTestCase {
38   
39    @Mock
40    private ISkinConfig config;
41   
 
42  1 toggle @SuppressWarnings("unchecked")
43    @BeforeEach
44    public void setup() {
45  1 final MavenProject project = new MavenProject();
46  1 project.setName("reflow");
47  1 project.setArtifactId("reflow-artifact");
48  1 when(config.getProject()).thenReturn(project);
49   
50  1 final SiteModel model = new SiteModel();
51  1 when(config.getSiteModel()).thenReturn(model);
52  1 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class)))
53    .then(invocation -> invocation.getArguments()[3]);
54  1 when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class)))
55    .then(invocation -> invocation.getArguments()[2]);
56    }
57   
 
58  1 toggle @Test
59    public void shouldBuildFrameContext() throws Exception {
60  1 final String xml = "<reflowSkin><pages>" + //
61    "<development-documentation type=\"doc\">" + //
62    " <menu name=\"Development Documentation\">" + //
63    " <item name=\"Contribute\" href=\"dev/contribute.html\" />" + //
64    " <item name=\"Code Conventions\" href=\"dev/code-conventions.html\"/>" + //
65    " <item name=\"Release Management\" href=\"dev/release-management.html\"/>" + //
66    " </menu>" + //
67    " </development-documentation>" + //
68    "</pages></reflowSkin>";
69  1 final Xpp3Dom globalProperties = Xpp3DomBuilder.build(new StringReader(xml));
70  1 when(config.getPageProperties()).thenReturn(new Xpp3Dom("dev-contribute"));
71  1 when(config.getGlobalProperties()).thenReturn(globalProperties);
72  1 when(config.getFileId()).thenReturn("dev-contribute");
73  1 when(config.getNamespace()).thenReturn("");
74   
75  1 final Context<?> context = Context.buildContext(config);
76  1 assertThat((FrameContext) context, isA(FrameContext.class));
77  1 final FrameContext frameContext = (FrameContext) context;
78   
79  1 assertEquals("development-documentation", frameContext.getDocumentParent());
80   
81  1 final Toc<?> toc = frameContext.getToc();
82  1 assertNotNull(toc, "toc should be exist");
83  1 assertThat((TocSidebar) frameContext.getToc(), isA(TocSidebar.class));
84   
85  1 final TocSidebar tocSidebar = (TocSidebar) toc;
86  1 assertEquals(Integer.MAX_VALUE, tocSidebar.getLevel());
87  1 assertEquals("sidebar-light bg-light", tocSidebar.getCssClass());
88  1 assertEquals("toc-sidebar-enabled toc-sidebar-expanded toc-sidebar-autoexpandable toc-sidebar-fixed",
89    tocSidebar.getCssOptions());
90   
91  1 final Footer footer = frameContext.getFooter();
92  1 assertNotNull(footer, "footer should be exist");
93  1 assertEquals("footer-light bg-light", footer.getCssClass());
94  1 assertEquals("", footer.getCssOptions());
95   
96  1 final Navbar navbar = frameContext.getNavbar();
97  1 assertNotNull(navbar, "Navbar should be exist");
98  1 assertEquals("navbar-light bg-light", navbar.getCssClass());
99  1 assertEquals("", navbar.getCssOptions());
100   
101  1 final ScrollTop scrollTop = frameContext.getScrollTop();
102  1 assertNotNull(scrollTop, "ScrollTop should be exist");
103  1 assertEquals("", scrollTop.getCssClass());
104  1 assertEquals(true, scrollTop.isSmooth());
105  1 assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions());
106    }
107    }