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

File ContextTest.java

 

Code metrics

0
39
6
1
120
80
6
0,15
6,5
6
1

Classes

Class Line # Actions
ContextTest 33 39 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 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 org.apache.maven.doxia.site.SiteModel;
22    import org.apache.maven.project.MavenProject;
23    import org.devacfr.maven.skins.reflow.HtmlTool;
24    import org.devacfr.maven.skins.reflow.ISkinConfig;
25    import org.devacfr.testing.jupiter.MockitoTestCase;
26    import org.junit.jupiter.api.BeforeEach;
27    import org.junit.jupiter.api.Test;
28    import org.mockito.Mock;
29   
30    import static org.hamcrest.MatcherAssert.assertThat;
31    import static org.hamcrest.Matchers.isA;
32   
 
33    public class ContextTest extends MockitoTestCase {
34   
35    @Mock
36    private ISkinConfig config;
37   
 
38  5 toggle @SuppressWarnings("unchecked")
39    @BeforeEach
40    public void setup() {
41  5 final MavenProject project = new MavenProject();
42  5 project.setName("reflow");
43  5 project.setArtifactId("reflow-artifact");
44  5 when(config.getProject()).thenReturn(project);
45   
46  5 final SiteModel siteModel = new SiteModel();
47  5 when(config.getSiteModel()).thenReturn(siteModel);
48  5 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class)))
49    .then(invocation -> invocation.getArguments()[3]);
50  5 when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class)))
51    .then(invocation -> invocation.getArguments()[2]);
52   
53  5 when(config.getToolbox("htmlTool", HtmlTool.class)).thenReturn(new HtmlTool());
54    }
55   
 
56  1 toggle @Test
57    public void shouldReplaceTTTag() {
58  1 final Context<?> context = Context.buildContext(config);
59  1 assertThat((PageContext) context, isA(PageContext.class));
60   
61  1 final PageContext pageContext = (PageContext) context;
62   
63  1 verify(content -> {
64  1 when(config.getContextValue("bodyContent", String.class)).thenReturn(content);
65  1 return pageContext.preRender(config);
66    }, "html");
67    }
68   
 
69  1 toggle @Test
70    public void shouldAddLighboxAttribute() {
71  1 final Context<?> context = Context.buildContext(config);
72  1 assertThat((PageContext) context, isA(PageContext.class));
73   
74  1 final PageContext pageContext = (PageContext) context;
75   
76  1 verify(content -> {
77  1 when(config.getContextValue("bodyContent", String.class)).thenReturn(content);
78  1 return pageContext.preRender(config);
79    }, "html");
80    }
81   
 
82  1 toggle @Test
83    public void shouldApplyBootstrapCss() {
84  1 final Context<?> context = Context.buildContext(config);
85  1 assertThat((PageContext) context, isA(PageContext.class));
86   
87  1 final PageContext pageContext = (PageContext) context;
88   
89  1 verify(content -> {
90  1 when(config.getContextValue("bodyContent", String.class)).thenReturn(content);
91  1 return pageContext.preRender(config);
92    }, "html");
93    }
94   
 
95  1 toggle @Test
96    public void shouldReplaceIcons() {
97  1 final Context<?> context = Context.buildContext(config);
98  1 assertThat((PageContext) context, isA(PageContext.class));
99   
100  1 final PageContext pageContext = (PageContext) context;
101   
102  1 verify(content -> {
103  1 when(config.getContextValue("bodyContent", String.class)).thenReturn(content);
104  1 return pageContext.preRender(config);
105    }, "html");
106    }
107   
 
108  1 toggle @Test
109    public void shouldNotChangeCodePart() {
110  1 final Context<?> context = Context.buildContext(config);
111  1 assertThat((PageContext) context, isA(PageContext.class));
112   
113  1 final PageContext pageContext = (PageContext) context;
114   
115  1 verify(content -> {
116  1 when(config.getContextValue("bodyContent", String.class)).thenReturn(content);
117  1 return pageContext.preRender(config);
118    }, "html");
119    }
120    }