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

File SkinConfigToolTest.java

 

Code metrics

0
40
7
1
121
82
9
0,22
5,71
7
1,29

Classes

Class Line # Actions
SkinConfigToolTest 34 40 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 6 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;
20   
21    import java.io.InputStream;
22   
23    import com.google.common.collect.ImmutableMap;
24    import org.apache.maven.doxia.site.SiteModel;
25    import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader;
26    import org.apache.maven.project.MavenProject;
27    import org.apache.velocity.tools.ToolContext;
28    import org.apache.velocity.tools.generic.RenderTool;
29    import org.apache.velocity.tools.generic.ValueParser;
30    import org.devacfr.testing.jupiter.MockitoTestCase;
31    import org.junit.jupiter.api.BeforeEach;
32    import org.junit.jupiter.api.Test;
33   
 
34    public class SkinConfigToolTest extends MockitoTestCase {
35   
36    private ToolContext velocityContext;
37   
38    private ValueParser valueParser;
39   
40    private SkinConfigTool skinConfig;
41   
42    private SiteModel siteModel;
43   
 
44  6 toggle @BeforeEach
45    public void setup() throws Exception {
46  6 velocityContext = new ToolContext();
47  6 final SiteXpp3Reader reader = new SiteXpp3Reader();
48   
49  6 try (final InputStream in = getResource("default.site.xml").openBufferedStream()) {
50  6 siteModel = reader.read(in);
51    }
52  6 valueParser = new ValueParser(
53    ImmutableMap.<String, Object> builder().put("velocityContext", velocityContext).build());
54   
55  6 final MavenProject maven = new MavenProject();
56  6 maven.setArtifactId("maven-reflow-plugin");
57  6 maven.setUrl("https://devacfr.github.io/reflow-maven-skin/");
58   
59  6 velocityContext.put("project", maven);
60  6 velocityContext.put("site", siteModel);
61  6 velocityContext.put("render", new RenderTool());
62  6 velocityContext.put("currentFileName", "summary.html");
63  6 velocityContext.put("alignedFileName", "summary.html");
64  6 skinConfig = new SkinConfigTool();
65  6 skinConfig.configure(valueParser);
66    }
67   
 
68  1 toggle @Test
69    public void testIs() {
70  1 assertEquals(true, skinConfig.is("localResources"));
71  1 assertEquals(false, skinConfig.is("markPageHeader"));
72    }
73   
 
74  1 toggle @Test
75    public void testNot() {
76  1 assertEquals(true, skinConfig.not("markPageHeader"));
77  1 assertEquals(false, skinConfig.not("localResources"));
78    }
79   
 
80  1 toggle @Test
81    public void testIsValue() {
82  1 assertEquals(true, skinConfig.isValue("localResources", "true"));
83  1 assertEquals(false, skinConfig.isValue("localResources", "value"));
84    }
85   
 
86  1 toggle @Test
87    public void testIsActiveLink() {
88   
89  1 velocityContext.put("alignedFileName", "index.html");
90  1 assertEquals(true, skinConfig.isActiveLink("."), "should be active");
91  1 assertEquals(true, skinConfig.isActiveLink(""), "should be active");
92   
93  1 velocityContext.put("alignedFileName", "summary.html");
94  1 assertEquals(false, skinConfig.isActiveLink(null), "should be note active");
95  1 assertEquals(false, skinConfig.isActiveLink("."), "should be note active");
96  1 assertEquals(false, skinConfig.isActiveLink("index.html"), "should be note active");
97    }
98   
 
99  1 toggle @Test
100    public void testIsExternalLink() {
101   
102  1 assertEquals(true, skinConfig.isExternalLink("http://foo.com"), "should be external");
103  1 assertEquals(true, skinConfig.isExternalLink("https://foo.com"), "should be external");
104  1 assertEquals(true, skinConfig.isExternalLink("ftp://foo.com"), "should be external");
105  1 assertEquals(true, skinConfig.isExternalLink("mailto:john@foo.com"), "should be external");
106  1 assertEquals(true, skinConfig.isExternalLink("file://foo.com"), "should be external");
107   
108  1 assertEquals(false, skinConfig.isExternalLink(null), "should be internal");
109  1 assertEquals(false, skinConfig.isExternalLink("summary.html"), "should be internal");
110  1 assertEquals(false,
111    skinConfig.isExternalLink("https://devacfr.github.io/reflow-maven-skin/dev/summary.html"),
112    "should be internal");
113    }
114   
 
115  1 toggle @Test
116    public void testSlugFilename() {
117  1 assertEquals("dev-release-management", SkinConfigTool.slugFilename("dev/release-management.html"));
118  1 assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide.html"));
119  1 assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide"));
120    }
121    }