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