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