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