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

File URIToolTest.java

 

Code metrics

0
46
10
1
116
85
10
0,22
4,6
10
1

Classes

Class Line # Actions
URIToolTest 24 46 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 10 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 java.io.IOException;
19    import java.net.URI;
20    import org.devacfr.maven.skins.reflow.URITool.URLRebaser;
21    import org.devacfr.testing.jupiter.TestCase;
22    import org.junit.jupiter.api.Test;
23   
 
24    public class URIToolTest extends TestCase {
25   
 
26  1 toggle @Test
27    public void shouldRelativizeLinkAccetupNullBase() throws IOException {
28  1 final String actual = URITool.relativizeLink(null, "link");
29  1 assertEquals("link", actual);
30    }
31   
 
32  1 toggle @Test
33    public void shouldRelativizeLinkAcceptsAbsoluteBaseUri() throws IOException {
34  1 final String actual = URITool.relativizeLink("reflow-maven-skin", "link");
35  1 assertEquals("link", actual);
36    }
37   
 
38  1 toggle @Test
39    public void relativeRootLink() throws IOException {
40  1 final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin";
41  1 final String currentFilename = "index.html";
42  1 final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/";
43   
44  1 final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString();
45  1 final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL);
46  1 assertEquals(".", actual);
47    }
48   
 
49  1 toggle @Test
50    public void relativeSubModuleLink() throws IOException {
51  1 final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin";
52  1 final String currentFilename = "index.html";
53  1 final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/skin/";
54   
55  1 final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString();
56  1 final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL);
57  1 assertEquals("..", actual);
58    }
59   
 
60  1 toggle @Test
61    public void relativeSubFolderLink() throws IOException {
62  1 final String absoluteResourceURL = "https://devacfr.github.io/reflow-maven-skin";
63  1 final String currentFilename = "themes/index.html";
64  1 final String projectUrl = "https://devacfr.github.io/reflow-maven-skin/skin/";
65   
66  1 final String currentFileDir = URITool.toURI(projectUrl).resolve(currentFilename).resolve(".").toString();
67  1 final String actual = URITool.relativizeLink(currentFileDir, absoluteResourceURL);
68  1 assertEquals("../..", actual);
69    }
70   
 
71  1 toggle @Test
72    public void shouldNormalisedBaseUrlAcceptNullParameter() {
73  1 assertNull(URITool.normalisedBaseUrl(null));
74    }
75   
 
76  1 toggle @Test
77    public void rebaseUrlNonInterpolate() {
78  1 assertThrows(IllegalArgumentException.class, () -> {
79  1 final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/";
80  1 final String relativePath = ".";
81  1 final URI parent = URI.create(childBaseUrl);
82  1 final String parentBaseUrl = parent.resolve(relativePath).normalize().toString();
83  1 final URLRebaser rebaser = URITool.createURLRebaser(parentBaseUrl, childBaseUrl);
84  1 rebaser.rebaseLink("${project.path}/reflow.png");
85    });
86    }
87   
 
88  1 toggle @Test
89    public void rebaseUrlOnRootProject() {
90  1 final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/";
91  1 final String relativePath = ".";
92  1 final URI parent = URI.create(childBaseUrl);
93  1 final String parentBaseUrl = parent.resolve(relativePath).normalize().toString();
94  1 final URLRebaser rebaser = URITool.createURLRebaser(parentBaseUrl, childBaseUrl);
95  1 assertEquals("images/reflow.png", rebaser.rebaseLink("images/reflow.png"));
96    }
97   
 
98  1 toggle @Test
99    public void rebaseUrlOnChildProject() {
100  1 final String childBaseUrl = "https://devacfr.github.io/reflow-maven-skin/skin/";
101  1 final String relativePath = "..";
102  1 final URI parent = URI.create(childBaseUrl);
103  1 final String parentBaseUrl = parent.resolve(relativePath).normalize().toString();
104  1 final URLRebaser rebaser = new URLRebaser(parentBaseUrl, childBaseUrl);
105  1 assertEquals("../images/reflow.png", rebaser.rebaseLink("images/reflow.png"));
106    }
107   
 
108  1 toggle @Test
109    public void rebaseUrlWithParentNullValue() {
110  1 final String childBaseUrl = null;
111  1 final String parentBaseUrl = null;
112   
113  1 final URLRebaser rebaser = new URLRebaser(parentBaseUrl, childBaseUrl);
114  1 assertEquals("images/reflow.png", rebaser.rebaseLink("images/reflow.png"));
115    }
116    }