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

File DocumentContextTest.java

 

Code metrics

0
18
2
1
75
45
2
0,11
9
2
1

Classes

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