1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.devacfr.maven.skins.reflow.context

File FrameContextTest.java

 

Code metrics

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

Classes

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

Contributing tests

This file is covered by 1 test. .

Source view

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