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

File DocumentContextTest.java

 

Code metrics

0
19
2
1
72
46
2
0,11
9,5
2
1

Classes

Class Line # Actions
DocumentContextTest 33 19 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.NavSideMenu;
28    import org.devacfr.testing.jupiter.MockitoTestCase;
29    import org.junit.jupiter.api.BeforeEach;
30    import org.junit.jupiter.api.Test;
31    import org.mockito.Mock;
32   
 
33    public class DocumentContextTest extends MockitoTestCase {
34   
35    @Mock
36    private ISkinConfig config;
37   
 
38  2 toggle @SuppressWarnings("unchecked")
39    @BeforeEach
40    public void setup() {
41  2 final MavenProject project = new MavenProject();
42  2 project.setName("reflow");
43  2 project.setArtifactId("reflow-artifact");
44  2 when(config.getProject()).thenReturn(project);
45   
46  2 final SiteModel model = new SiteModel();
47  2 when(config.getSiteModel()).thenReturn(model);
48  2 when(config.getFileId()).thenReturn("currentFile");
49  2 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class)))
50    .then(invocation -> invocation.getArguments()[3]);
51  2 when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class)))
52    .then(invocation -> invocation.getArguments()[2]);
53    }
54   
 
55  2 toggle @Test
56    public void shouldBuildDocumentContext() throws Exception {
57  2 final Xpp3Dom pageProperties = Xpp3DomBuilder.build(new StringReader("<document type=\"doc\"></document>"));
58  2 when(config.getPageProperties()).thenReturn(pageProperties);
59   
60  2 final Context<?> context = Context.buildContext(config);
61  2 assertThat((DocumentContext) context, isA(DocumentContext.class));
62   
63  2 final DocumentContext documentContext = (DocumentContext) context;
64   
65  2 final NavSideMenu navSideMenu = documentContext.getNavSideMenu();
66  2 assertNotNull(navSideMenu, "NavSideMenu should be exist");
67  2 assertEquals("sidenav-enabled", navSideMenu.getCssOptions());
68   
69  2 assertEquals("anchorjs-enabled scrolltop-smooth-enabled sidenav-enabled", documentContext.getCssOptions());
70  2 assertEquals("", documentContext.getCssClass());
71    }
72    }