Skip to content

Commit

Permalink
Fix URL constructor deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardsph committed Nov 1, 2024
1 parent 218ee4e commit 5df7d07
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
});
}
URL website = new URL(urlString);
URL website = URI.create(urlString).toURL();
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/solid/testharness/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

import jakarta.inject.Inject;
import java.io.File;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -168,7 +168,7 @@ void targetBlank() throws Exception {
void target() throws Exception {
final TestSuiteResults results = mockResults(1, false);
when(conformanceTestHarness.runTestSuites(any(), any())).thenReturn(results);
when(config.getSubjectsUrl()).thenReturn(new URL("https://example.org/subjects.ttl"));
when(config.getSubjectsUrl()).thenReturn(URI.create("https://example.org/subjects.ttl").toURL());
assertEquals(0, application.run("--target", "test"));
verify(config).setTestSubject(iri("https://example.org/test"));
}
Expand All @@ -177,7 +177,7 @@ void target() throws Exception {
void targetIri() throws Exception {
final TestSuiteResults results = mockResults(1, false);
when(conformanceTestHarness.runTestSuites(any(), any())).thenReturn(results);
when(config.getSubjectsUrl()).thenReturn(new URL("https://example.org/subjects.ttl"));
when(config.getSubjectsUrl()).thenReturn(URI.create("https://example.org/subjects.ttl").toURL());
assertEquals(0, application.run("--target", "https://example.org/test"));
verify(config).setTestSubject(iri("https://example.org/test"));
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/solid/testharness/config/ConfigLogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ void getSubjectsUrlNoConfigException() {
void getSubjectsUrlUseConfigHttp() throws MalformedURLException {
final Config config = new Config();
config.subjectsFile = Optional.of("http://example.org");
assertEquals(new URL("http://example.org"), config.getSubjectsUrl());
assertEquals(URI.create("http://example.org").toURL(), config.getSubjectsUrl());
}

@Test
void getSubjectsUrlUseConfigHttps() throws MalformedURLException {
final Config config = new Config();
config.subjectsFile = Optional.of(TestUtils.SAMPLE_BASE);
assertEquals(new URL(TestUtils.SAMPLE_BASE), config.getSubjectsUrl());
assertEquals(URI.create(TestUtils.SAMPLE_BASE).toURL(), config.getSubjectsUrl());
}

@Test
void getSubjectsUrlUseConfigFile() throws MalformedURLException {
final Config config = new Config();
config.subjectsFile = Optional.of("file:/subjectFile");
assertEquals(new URL("file:/subjectFile"), config.getSubjectsUrl());
assertEquals(URI.create("file:/subjectFile").toURL(), config.getSubjectsUrl());
}

@Test
Expand Down Expand Up @@ -110,7 +110,7 @@ void getSubjectsUrlUseConfigBad() {
void getSubjectsUrlUseSet() throws MalformedURLException {
final Config config = new Config();
config.setSubjectsUrl(TestUtils.SAMPLE_BASE);
assertEquals(new URL(TestUtils.SAMPLE_BASE), config.getSubjectsUrl());
assertEquals(URI.create(TestUtils.SAMPLE_BASE).toURL(), config.getSubjectsUrl());
}

@Test
Expand Down Expand Up @@ -140,7 +140,7 @@ void getTestSourcesUseConfigOne() throws MalformedURLException {
config.sourceList = Optional.of(List.of(TestUtils.SAMPLE_BASE));
final List<URL> list = config.getTestSources();
assertEquals(1, list.size());
assertEquals(new URL(TestUtils.SAMPLE_BASE), list.get(0));
assertEquals(URI.create(TestUtils.SAMPLE_BASE).toURL(), list.get(0));
}

@Test
Expand All @@ -149,8 +149,8 @@ void getTestSourcesUseConfigTwo() throws MalformedURLException {
config.sourceList = Optional.of(List.of("https://example.org", "http://example.org"));
final List<URL> list = config.getTestSources();
assertEquals(2, list.size());
assertEquals(new URL("https://example.org"), list.get(0));
assertEquals(new URL("http://example.org"), list.get(1));
assertEquals(URI.create("https://example.org").toURL(), list.get(0));
assertEquals(URI.create("http://example.org").toURL(), list.get(1));
}

@Test
Expand All @@ -166,8 +166,8 @@ void getTestSourcesUseSet() throws MalformedURLException {
config.setTestSources(List.of("https://example.org", "http://example.org"));
final List<URL> list = config.getTestSources();
assertEquals(2, list.size());
assertEquals(new URL("https://example.org"), list.get(0));
assertEquals(new URL("http://example.org"), list.get(1));
assertEquals(URI.create("https://example.org").toURL(), list.get(0));
assertEquals(URI.create("http://example.org").toURL(), list.get(1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ void mapIriNoMapping() {

@Test
void mapUrl() throws MalformedURLException {
final URL url = pathMappings.mapUrl(new URL("https://example.org/specification-sample-1.ttl"));
final URL url = pathMappings.mapUrl(URI.create("https://example.org/specification-sample-1.ttl").toURL());
assertEquals(TestUtils.getFileUrl("src/test/resources/discovery/specification-sample-1.ttl"), url);
}

@Test
void mapUrlFail() {
assertThrows(TestHarnessInitializationException.class,
() -> pathMappings.mapUrl(new URL("https://example.org/badmapping-sample-1.ttl")));
() -> pathMappings.mapUrl(URI.create("https://example.org/badmapping-sample-1.ttl").toURL()));
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/solid/testharness/config/TestSubjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ void setupMissingTargetSingleConfig() throws Exception {
final TargetServer targetServer = testSubject.getTargetServer();

assertNotNull(targetServer);
assertEquals(new URL(testFileUrl, "default").toString(), targetServer.getSubject());
assertEquals(testFileUrl.toURI().resolve("default").toString(), targetServer.getSubject());
assertEquals(12, targetServer.size());
}

@Test
void setupTargetMultipleConfig() throws Exception {
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
final String subject = new URL(testFileUrl, "testserver").toString();
final String subject = testFileUrl.toURI().resolve("testserver").toString();
setupMockConfigMin(CONFIG_SAMPLE, subject);
testSubject.loadTestSubjectConfig();

Expand Down Expand Up @@ -359,7 +359,7 @@ void findStorageProvisionFails() {
@Test
void loadTestSubjectConfigTarget1() throws Exception {
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
final String subject = new URL(testFileUrl, "testserver").toString();
final String subject = testFileUrl.toURI().resolve("testserver").toString();
when(config.getSubjectsUrl()).thenReturn(testFileUrl);
when(config.getTestSubject()).thenReturn(iri(subject));
testSubject.loadTestSubjectConfig();
Expand All @@ -373,7 +373,7 @@ void loadTestSubjectConfigTarget1() throws Exception {
@Test
void loadTestSubjectConfigTarget2() throws Exception {
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
final String subject = new URL(testFileUrl, "testserver2").toString();
final String subject = testFileUrl.toURI().resolve("testserver2").toString();
when(config.getSubjectsUrl()).thenReturn(testFileUrl);
when(config.getTestSubject()).thenReturn(iri(subject));
testSubject.loadTestSubjectConfig();
Expand All @@ -393,7 +393,7 @@ void getTargetServerDefault() throws Exception {
final TargetServer targetServer = testSubject.getTargetServer();

assertNotNull(targetServer);
assertEquals(new URL(testFileUrl, "default").toString(), targetServer.getSubject());
assertEquals(testFileUrl.toURI().resolve("default").toString(), targetServer.getSubject());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import jakarta.inject.Inject;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -77,8 +77,8 @@ void setUp() {
@Test
void loadOneManifest() throws MalformedURLException {
testSuiteDescription.load(List.of(
new URL(NS + "test-manifest-sample-1.ttl"),
new URL(NS + "specification-sample-1.ttl")
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
URI.create(NS + "specification-sample-1.ttl").toURL()
));
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
Expand All @@ -92,10 +92,10 @@ void loadOneManifest() throws MalformedURLException {
@Test
void loadTwoManifest() throws MalformedURLException {
testSuiteDescription.load(List.of(
new URL(NS + "test-manifest-sample-1.ttl"),
new URL(NS + "test-manifest-sample-2.ttl"),
new URL(NS + "specification-sample-1.ttl"),
new URL(NS + "specification-sample-2.ttl")
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
URI.create(NS + "test-manifest-sample-2.ttl").toURL(),
URI.create(NS + "specification-sample-1.ttl").toURL(),
URI.create(NS + "specification-sample-2.ttl").toURL()
));
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
Expand All @@ -107,7 +107,7 @@ void loadTwoManifest() throws MalformedURLException {

@Test
void loadRdfa() throws MalformedURLException {
testSuiteDescription.load(List.of(new URL(NS + "specification-sample-1.html")));
testSuiteDescription.load(List.of(URI.create(NS + "specification-sample-1.html").toURL()));
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
assertTrue(ask(iri(NS, "specification1#spec1"), SPEC.statement,
literal("text of requirement 1")));
Expand All @@ -116,10 +116,10 @@ void loadRdfa() throws MalformedURLException {
@Test
void loadTwoManifestMixed() throws MalformedURLException {
testSuiteDescription.load(List.of(
new URL(NS + "test-manifest-sample-1.ttl"),
new URL(NS + "test-manifest-sample-2.ttl"),
new URL(NS + "specification-sample-1.html"),
new URL(NS + "specification-sample-2.ttl")
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
URI.create(NS + "test-manifest-sample-2.ttl").toURL(),
URI.create(NS + "specification-sample-1.html").toURL(),
URI.create(NS + "specification-sample-2.ttl").toURL()
));
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
Expand All @@ -131,7 +131,7 @@ void loadTwoManifestMixed() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsNull() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(null, null);
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(0, count(null, RDF.type, EARL.Assertion));
Expand All @@ -145,7 +145,7 @@ void setNonRunningTestAssertionsNull() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsEmptyFilters() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(Collections.emptyList(), null);
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(0, count(null, RDF.type, EARL.Assertion));
Expand All @@ -159,7 +159,7 @@ void setNonRunningTestAssertionsEmptyFilters() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsEmptyStatuses() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(null, Collections.emptyList());
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(0, count(null, RDF.type, EARL.Assertion));
Expand All @@ -173,7 +173,7 @@ void setNonRunningTestAssertionsEmptyStatuses() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsFilterGroup1() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(List.of("group1"), null);
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(3, count(null, RDF.type, EARL.Assertion));
Expand All @@ -188,7 +188,7 @@ void setNonRunningTestAssertionsFilterGroup1() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsStatuesAccepted() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(null, List.of("accepted"));
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(1, count(null, RDF.type, EARL.Assertion));
Expand All @@ -207,7 +207,7 @@ void setNonRunningTestAssertionsStatuesAccepted() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsStatusUnreviewed() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
testSuiteDescription.setNonRunningTestAssertions(null, List.of("unreviewed"));
assertEquals(6, count(null, RDF.type, TD.TestCase));
assertEquals(5, count(null, RDF.type, EARL.Assertion));
Expand All @@ -218,7 +218,7 @@ void setNonRunningTestAssertionsStatusUnreviewed() throws MalformedURLException

@Test
void setNonRunningTestAssertionsBadStatus() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
add(iri(NS, "testcase"), RDF.type, TD.TestCase);
add(iri(NS, "testcase"), TD.reviewStatus, literal("ACCEPTED"));
testSuiteDescription.setNonRunningTestAssertions(null, List.of("unreviewed"));
Expand All @@ -231,7 +231,7 @@ void setNonRunningTestAssertionsBadStatus() throws MalformedURLException {

@Test
void setNonRunningTestAssertionsBadStatusNotChecked() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of( URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
add(iri(NS, "testcase"), RDF.type, TD.TestCase);
add(iri(NS, "testcase"), TD.reviewStatus, literal("ACCEPTED"));
testSuiteDescription.setNonRunningTestAssertions(null, null);
Expand All @@ -242,7 +242,7 @@ void setNonRunningTestAssertionsBadStatusNotChecked() throws MalformedURLExcepti

@Test
void setNonRunningTestAssertionsMissingStatus() throws MalformedURLException {
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
testSuiteDescription.load(List.of( URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
add(iri(NS, "testcase"), RDF.type, TD.TestCase);
testSuiteDescription.setNonRunningTestAssertions(null, List.of("accepted", "unreviewed"));
assertEquals(7, count(null, RDF.type, TD.TestCase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -377,7 +378,7 @@ void loadTurtle() throws MalformedURLException {
void loadTurtleBadUrl() {
final DataRepository dataRepository = new DataRepository();
assertThrows(TestHarnessInitializationException.class,
() -> dataRepository.load(new URL("file:/missing.txt"))
() -> dataRepository.load(URI.create("file:/missing.txt").toURL())
);
}

Expand Down Expand Up @@ -410,7 +411,7 @@ void loadRdfa() throws Exception {
void loadRdfaBadUrl() {
final DataRepository dataRepository = new DataRepository();
assertThrows(TestHarnessInitializationException.class,
() -> dataRepository.load(new URL("file:/missing.txt"), TestUtils.SAMPLE_BASE)
() -> dataRepository.load(URI.create("file:/missing.txt").toURL(), TestUtils.SAMPLE_BASE)
);
}

Expand Down

0 comments on commit 5df7d07

Please sign in to comment.