1. Project Clover database mer. févr. 4 2026 12:48:28 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 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 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  2 toggle @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  2 toggle @Test
59    public void shouldBuildFrameContext() throws Exception {
60  2 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  2 final Xpp3Dom globalProperties = Xpp3DomBuilder.build(new StringReader(xml));
70  2 when(config.getPageProperties()).thenReturn(new Xpp3Dom("dev-contribute"));
71  2 when(config.getGlobalProperties()).thenReturn(globalProperties);
72  2 when(config.getFileId()).thenReturn("dev-contribute");
73  2 when(config.getNamespace()).thenReturn("");
74   
75  2 final Context<?> context = Context.buildContext(config);
76  2 assertThat((FrameContext) context, isA(FrameContext.class));
77  2 final FrameContext frameContext = (FrameContext) context;
78   
79  2 assertEquals("development-documentation", frameContext.getDocumentParent());
80   
81  2 final Toc<?> toc = frameContext.getToc();
82  2 assertNotNull(toc, "toc should be exist");
83  2 assertThat((TocSidebar) frameContext.getToc(), isA(TocSidebar.class));
84   
85  2 final TocSidebar tocSidebar = (TocSidebar) toc;
86  2 assertEquals(Integer.MAX_VALUE, tocSidebar.getLevel());
87  2 assertEquals("sidebar-light bg-light", tocSidebar.getCssClass());
88  2 assertEquals("toc-sidebar-enabled toc-sidebar-expanded toc-sidebar-autoexpandable toc-sidebar-fixed",
89    tocSidebar.getCssOptions());
90   
91  2 final Footer footer = frameContext.getFooter();
92  2 assertNotNull(footer, "footer should be exist");
93  2 assertEquals("footer-light bg-light", footer.getCssClass());
94  2 assertEquals("", footer.getCssOptions());
95   
96  2 final Navbar navbar = frameContext.getNavbar();
97  2 assertNotNull(navbar, "Navbar should be exist");
98  2 assertEquals("navbar-light bg-light", navbar.getCssClass());
99  2 assertEquals("", navbar.getCssOptions());
100   
101  2 final ScrollTop scrollTop = frameContext.getScrollTop();
102  2 assertNotNull(scrollTop, "ScrollTop should be exist");
103  2 assertEquals("", scrollTop.getCssClass());
104  2 assertEquals(true, scrollTop.isSmooth());
105  2 assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions());
106    }
107    }