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

File BodyContextTest.java

 

Code metrics

0
39
3
1
104
72
3
0,08
13
3
1

Classes

Class Line # Actions
BodyContextTest 35 39 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 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.testing.jupiter.MockitoTestCase;
31    import org.junit.jupiter.api.BeforeEach;
32    import org.junit.jupiter.api.Test;
33    import org.mockito.Mock;
34   
 
35    public class BodyContextTest extends MockitoTestCase {
36   
37    @Mock
38    private ISkinConfig config;
39   
 
40  4 toggle @SuppressWarnings("unchecked")
41    @BeforeEach
42    public void setup() {
43  4 final MavenProject project = new MavenProject();
44  4 project.setName("reflow");
45  4 project.setArtifactId("reflow-artifact");
46  4 when(config.getProject()).thenReturn(project);
47   
48  4 final SiteModel model = new SiteModel();
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  2 toggle @Test
57    public void shouldBuildBodyContext() throws Exception {
58  2 final Xpp3Dom pageProperties = Xpp3DomBuilder.build(new StringReader("<document type=\"body\"></document>"));
59  2 when(config.getPageProperties()).thenReturn(pageProperties);
60  2 when(config.getFileId()).thenReturn("currentFile");
61   
62  2 final Context<?> context = Context.buildContext(config);
63  2 assertThat((BodyContext) context, isA(BodyContext.class));
64   
65  2 final BodyContext bodyContext = (BodyContext) context;
66   
67  2 final Footer footer = bodyContext.getFooter();
68  2 assertNotNull(footer, "footer should be exist");
69  2 assertEquals("footer-light bg-light", footer.getCssClass());
70  2 assertEquals("", footer.getCssOptions());
71   
72  2 final Navbar navbar = bodyContext.getNavbar();
73  2 assertNotNull(navbar, "Navbar should be exist");
74  2 assertEquals("navbar-light bg-light", navbar.getCssClass());
75  2 assertEquals("", navbar.getCssOptions());
76   
77  2 final ScrollTop scrollTop = bodyContext.getScrollTop();
78  2 assertNotNull(scrollTop, "ScrollTop should be exist");
79  2 assertEquals("", scrollTop.getCssClass());
80  2 assertEquals(true, scrollTop.isSmooth());
81  2 assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions());
82   
83  2 assertEquals("scrolltop-smooth-enabled", bodyContext.getCssOptions());
84  2 assertEquals("", bodyContext.getCssClass());
85  2 assertEquals("body", bodyContext.getType());
86    }
87   
 
88  2 toggle @Test
89    public void shouldRenderBodyWihoutModify() throws Exception {
90  2 final Xpp3Dom pageProperties = Xpp3DomBuilder.build(new StringReader("<document type=\"body\"></document>"));
91  2 when(config.getPageProperties()).thenReturn(pageProperties);
92  2 when(config.getFileId()).thenReturn("currentFile");
93   
94  2 final Context<?> context = Context.buildContext(config);
95  2 assertThat((BodyContext) context, isA(BodyContext.class));
96   
97  2 final BodyContext bodyContext = (BodyContext) context;
98   
99  2 verify((content) -> {
100  2 when(config.getBodyContent()).thenReturn(content);
101  2 return bodyContext.preRender();
102    }, "html");
103    }
104    }