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

File BodyContextTest.java

 

Code metrics

0
37
3
1
106
70
3
0,08
12,33
3
1

Classes

Class Line # Actions
BodyContextTest 39 37 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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