Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions logback-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter-params.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -236,15 +235,19 @@ private byte[] computeHash(String response) {
}
}

@SuppressWarnings("deprecation")
File convertToFile(URL url) {
String protocol = url.getProtocol();
if ("file".equals(protocol)) {
return new File(URLDecoder.decode(url.getFile()));
} else {
if (!"file".equals(protocol)) {
addInfo("URL [" + url + "] is not of type file");
return null;
}

try {
return new File(url.toURI());
} catch (Exception e) {
addWarn("URL [" + url + "] can not be converted to a file", e);
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@
*/
package ch.qos.logback.core.joran.spi;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Named.named;
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* @author Ceki G&uuml;lc&uuml;
*/
public class ConfigurationWatchListTest {
class ConfigurationWatchListTest {

@Test
// See http://jira.qos.ch/browse/LBCORE-119
public void fileToURLAndBack() throws MalformedURLException {
File file = new File("a b.xml");
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("relativeFilePaths")
void fileToURLAndBack(String relativePath) throws MalformedURLException {
File file = new File(relativePath);
URL url = file.toURI().toURL();
ConfigurationWatchList cwl = new ConfigurationWatchList();
File back = cwl.convertToFile(url);
assertEquals(file.getName(), back.getName());
}

static Stream<Arguments> relativeFilePaths() {
return Stream.of(
arguments(named("path with space", "a b.xml")),
arguments(named("path with plus sign", "a+b.xml"))
);
}

}