1. Project Clover database mar. janv. 20 2026 12:32:22 CET
  2. Package org.devacfr.maven.skins.reflow

File SkinConfigToolTest.java

 

Code metrics

0
84
13
2
199
157
15
0,18
6,46
6,5
1,15

Classes

Class Line # Actions
SkinConfigToolTest 34 84 0% 15 0
1.0100%
SkinConfigToolTest.ReflowContext 188 0 - 0 0
-1.0 -
 

Contributing tests

This file is covered by 12 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;
17   
18    import com.google.common.collect.ImmutableMap;
19    import java.io.InputStream;
20    import lombok.Builder;
21    import lombok.Data;
22    import org.apache.maven.doxia.site.SiteModel;
23    import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader;
24    import org.apache.maven.project.MavenProject;
25    import org.apache.velocity.tools.Scope;
26    import org.apache.velocity.tools.ToolContext;
27    import org.apache.velocity.tools.ToolManager;
28    import org.apache.velocity.tools.config.EasyFactoryConfiguration;
29    import org.apache.velocity.tools.generic.RenderTool;
30    import org.apache.velocity.tools.generic.ValueParser;
31    import org.devacfr.testing.jupiter.MockitoTestCase;
32    import org.junit.jupiter.api.Test;
33   
 
34    public class SkinConfigToolTest extends MockitoTestCase {
35   
 
36  1 toggle @Test
37    public void testIs() throws Exception {
38  1 ReflowContext context = createSkinConfig();
39  1 assertEquals(true, context.getSkinConfig().is("localResources"));
40  1 assertEquals(false, context.getSkinConfig().is("markPageHeader"));
41    }
42   
 
43  1 toggle @Test
44    public void testNot() throws Exception {
45  1 ReflowContext context = createSkinConfig();
46  1 SkinConfigTool skinConfig = context.getSkinConfig();
47  1 assertEquals(true, skinConfig.not("markPageHeader"));
48  1 assertEquals(false, skinConfig.not("localResources"));
49    }
50   
 
51  1 toggle @Test
52    public void testIsValue() throws Exception {
53  1 ReflowContext context = createSkinConfig();
54  1 SkinConfigTool skinConfig = context.getSkinConfig();
55  1 assertEquals(true, skinConfig.isValue("localResources", "true"));
56  1 assertEquals(false, skinConfig.isValue("localResources", "value"));
57    }
58   
 
59  1 toggle @Test
60    public void testIsActiveLink() throws Exception {
61  1 ReflowContext context = createSkinConfig();
62  1 SkinConfigTool skinConfig = context.getSkinConfig();
63  1 ToolContext velocityContext = context.getVelocityContext();
64  1 velocityContext.put("alignedFileName", "index.html");
65  1 assertEquals(true, skinConfig.isActiveLink("."), "should be active");
66  1 assertEquals(true, skinConfig.isActiveLink(""), "should be active");
67   
68  1 velocityContext.put("alignedFileName", "summary.html");
69  1 assertEquals(false, skinConfig.isActiveLink(null), "should be not active");
70  1 assertEquals(false, skinConfig.isActiveLink("."), "should be not active");
71  1 assertEquals(false, skinConfig.isActiveLink("index.html"), "should be not active");
72    }
73   
 
74  1 toggle @Test
75    public void testIsExternalLink() throws Exception {
76  1 ReflowContext context = createSkinConfig();
77  1 SkinConfigTool skinConfig = context.getSkinConfig();
78  1 assertEquals(true, skinConfig.isExternalLink("http://foo.com"), "should be external");
79  1 assertEquals(true, skinConfig.isExternalLink("https://foo.com"), "should be external");
80  1 assertEquals(true, skinConfig.isExternalLink("ftp://foo.com"), "should be external");
81  1 assertEquals(true, skinConfig.isExternalLink("mailto:john@foo.com"), "should be external");
82  1 assertEquals(true, skinConfig.isExternalLink("file://foo.com"), "should be external");
83   
84  1 assertEquals(false, skinConfig.isExternalLink(null), "should be internal");
85  1 assertEquals(false, skinConfig.isExternalLink("summary.html"), "should be internal");
86  1 assertEquals(false,
87    skinConfig.isExternalLink("https://devacfr.github.io/reflow-maven-skin/dev/summary.html"),
88    "should be internal");
89    }
90   
 
91  1 toggle @Test
92    public void testSlugFilename() throws Exception {
93  1 assertEquals("dev-release-management", SkinConfigTool.slugFilename("dev/release-management.html"));
94  1 assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide.html"));
95  1 assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide"));
96    }
97   
 
98  1 toggle @Test
99    public void shouldReturnProjectLocationNotNull() throws Exception {
100  1 ReflowContext context = createSkinConfig();
101  1 SkinConfigTool skinConfig = context.getSkinConfig();
102  1 context.getMaven().setUrl(null);
103  1 assertEquals("https://localhost/", skinConfig.getProjectLocation());
104    }
105   
 
106  1 toggle @Test
107    public void shouldRenderSnippet() throws Exception {
108  1 ReflowContext context = createSkinConfig();
109   
110  1 assertEquals("<span class=\"badge badge-success\">INFO</span>",
111    context.skinConfig.renderSnippet("<badge color=\"success\" text=\"INFO\" />"));
112    }
113   
 
114  1 toggle @Test
115    public void shouldGetTitle() throws Exception {
116  1 ReflowContext context = createSkinConfig();
117  1 context.getVelocityContext().put("title", "Maven Reflow Plugin");
118  1 context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin");
119  1 SkinConfigTool skinConfig = context.getSkinConfig();
120  1 assertEquals("Maven Reflow Plugin | Maven Reflow Plugin", skinConfig.getTitle());
121    }
122   
 
123  1 toggle @Test
124    public void shouldGetTitleWithoutTitleTemplate() throws Exception {
125  1 ReflowContext context = createSkinConfig();
126  1 context.getVelocityContext().put("title", "Maven Reflow Plugin");
127  1 context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin");
128  1 SkinConfigTool skinConfig = context.getSkinConfig();
129  1 skinConfig.getGlobalProperties().removeChild(skinConfig.get("titleTemplate"));
130  1 assertEquals("Maven Reflow Plugin - Maven Reflow Plugin", skinConfig.getTitle());
131    }
132   
 
133  1 toggle @Test
134    public void shouldGetTitleUsingModelName() throws Exception {
135  1 ReflowContext context = createSkinConfig();
136  1 context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin");
137  1 SkinConfigTool skinConfig = context.getSkinConfig();
138  1 assertEquals("Maven Reflow Plugin | Reflow Maven Skin", skinConfig.getTitle());
139    }
140   
 
141  1 toggle @Test
142    public void shouldGetTitleUsingProjectName() throws Exception {
143  1 ReflowContext context = createSkinConfig();
144  1 context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin");
145  1 SkinConfigTool skinConfig = context.getSkinConfig();
146  1 context.getSiteModel().setName(null);
147  1 assertEquals("Maven Reflow Plugin | Reflow Maven Skin Project", skinConfig.getTitle());
148    }
149   
 
150  11 toggle private ReflowContext createSkinConfig() throws Exception {
151  11 SkinConfigTool skinConfig;
152  11 final EasyFactoryConfiguration config = new EasyFactoryConfiguration(false);
153  11 config.toolbox(Scope.APPLICATION).tool(HtmlTool.class);
154   
155  11 final ToolManager manager = new ToolManager(false, false);
156  11 manager.configure(config);
157  11 ToolContext velocityContext = manager.createContext();
158  11 final SiteXpp3Reader reader = new SiteXpp3Reader();
159  11 SiteModel siteModel = null;
160  11 try (final InputStream in = getResource("default.site.xml").openBufferedStream()) {
161  11 siteModel = reader.read(in);
162    }
163  11 ValueParser valueParser = new ValueParser(
164    ImmutableMap.<String, Object> builder().put("velocityContext", velocityContext).build());
165   
166  11 final MavenProject maven = new MavenProject();
167  11 maven.setArtifactId("maven-reflow-plugin");
168  11 maven.setName("Reflow Maven Skin Project");
169  11 maven.setUrl("https://devacfr.github.io/reflow-maven-skin/");
170   
171  11 velocityContext.put("project", maven);
172  11 velocityContext.put("site", siteModel);
173  11 velocityContext.put("render", new RenderTool());
174  11 velocityContext.put("currentFileName", "summary.html");
175  11 velocityContext.put("alignedFileName", "summary.html");
176  11 skinConfig = new SkinConfigTool();
177  11 skinConfig.configure(valueParser);
178  11 return ReflowContext.builder()
179    .maven(maven)
180    .velocityContext(velocityContext)
181    .skinConfig(skinConfig)
182    .siteModel(siteModel)
183    .build();
184    }
185   
186    @Data
187    @Builder
 
188    private static class ReflowContext {
189   
190    private ToolContext velocityContext;
191   
192    private SkinConfigTool skinConfig;
193   
194    private MavenProject maven;
195   
196    private SiteModel siteModel;
197   
198    }
199    }