Skip to content

Commit 2f39534

Browse files
authored
Fix java deprecations (#702)
1 parent 2b603af commit 2f39534

6 files changed

Lines changed: 43 additions & 42 deletions

File tree

src/test/java/org/solid/testharness/ApplicationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
import jakarta.inject.Inject;
3939
import java.io.File;
40-
import java.net.URL;
40+
import java.net.URI;
4141
import java.nio.file.Files;
4242
import java.nio.file.Path;
4343
import java.util.List;
@@ -168,7 +168,7 @@ void targetBlank() throws Exception {
168168
void target() throws Exception {
169169
final TestSuiteResults results = mockResults(1, false);
170170
when(conformanceTestHarness.runTestSuites(any(), any())).thenReturn(results);
171-
when(config.getSubjectsUrl()).thenReturn(new URL("https://example.org/subjects.ttl"));
171+
when(config.getSubjectsUrl()).thenReturn(URI.create("https://example.org/subjects.ttl").toURL());
172172
assertEquals(0, application.run("--target", "test"));
173173
verify(config).setTestSubject(iri("https://example.org/test"));
174174
}
@@ -177,7 +177,7 @@ void target() throws Exception {
177177
void targetIri() throws Exception {
178178
final TestSuiteResults results = mockResults(1, false);
179179
when(conformanceTestHarness.runTestSuites(any(), any())).thenReturn(results);
180-
when(config.getSubjectsUrl()).thenReturn(new URL("https://example.org/subjects.ttl"));
180+
when(config.getSubjectsUrl()).thenReturn(URI.create("https://example.org/subjects.ttl").toURL());
181181
assertEquals(0, application.run("--target", "https://example.org/test"));
182182
verify(config).setTestSubject(iri("https://example.org/test"));
183183
}

src/test/java/org/solid/testharness/config/ConfigLogicTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ void getSubjectsUrlNoConfigException() {
6767
void getSubjectsUrlUseConfigHttp() throws MalformedURLException {
6868
final Config config = new Config();
6969
config.subjectsFile = Optional.of("http://example.org");
70-
assertEquals(new URL("http://example.org"), config.getSubjectsUrl());
70+
assertEquals(URI.create("http://example.org").toURL(), config.getSubjectsUrl());
7171
}
7272

7373
@Test
7474
void getSubjectsUrlUseConfigHttps() throws MalformedURLException {
7575
final Config config = new Config();
7676
config.subjectsFile = Optional.of(TestUtils.SAMPLE_BASE);
77-
assertEquals(new URL(TestUtils.SAMPLE_BASE), config.getSubjectsUrl());
77+
assertEquals(URI.create(TestUtils.SAMPLE_BASE).toURL(), config.getSubjectsUrl());
7878
}
7979

8080
@Test
8181
void getSubjectsUrlUseConfigFile() throws MalformedURLException {
8282
final Config config = new Config();
8383
config.subjectsFile = Optional.of("file:/subjectFile");
84-
assertEquals(new URL("file:/subjectFile"), config.getSubjectsUrl());
84+
assertEquals(URI.create("file:/subjectFile").toURL(), config.getSubjectsUrl());
8585
}
8686

8787
@Test
@@ -110,7 +110,7 @@ void getSubjectsUrlUseConfigBad() {
110110
void getSubjectsUrlUseSet() throws MalformedURLException {
111111
final Config config = new Config();
112112
config.setSubjectsUrl(TestUtils.SAMPLE_BASE);
113-
assertEquals(new URL(TestUtils.SAMPLE_BASE), config.getSubjectsUrl());
113+
assertEquals(URI.create(TestUtils.SAMPLE_BASE).toURL(), config.getSubjectsUrl());
114114
}
115115

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

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

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

173173
@Test

src/test/java/org/solid/testharness/config/PathMappingsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ void mapIriNoMapping() {
137137

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

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

150150
@Test

src/test/java/org/solid/testharness/config/TestSubjectTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ void setupMissingTargetSingleConfig() throws Exception {
9090
final TargetServer targetServer = testSubject.getTargetServer();
9191

9292
assertNotNull(targetServer);
93-
assertEquals(new URL(testFileUrl, "default").toString(), targetServer.getSubject());
93+
assertEquals(testFileUrl.toURI().resolve("default").toString(), targetServer.getSubject());
9494
assertEquals(12, targetServer.size());
9595
}
9696

9797
@Test
9898
void setupTargetMultipleConfig() throws Exception {
9999
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
100-
final String subject = new URL(testFileUrl, "testserver").toString();
100+
final String subject = testFileUrl.toURI().resolve("testserver").toString();
101101
setupMockConfigMin(CONFIG_SAMPLE, subject);
102102
testSubject.loadTestSubjectConfig();
103103

@@ -359,7 +359,7 @@ void findStorageProvisionFails() {
359359
@Test
360360
void loadTestSubjectConfigTarget1() throws Exception {
361361
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
362-
final String subject = new URL(testFileUrl, "testserver").toString();
362+
final String subject = testFileUrl.toURI().resolve("testserver").toString();
363363
when(config.getSubjectsUrl()).thenReturn(testFileUrl);
364364
when(config.getTestSubject()).thenReturn(iri(subject));
365365
testSubject.loadTestSubjectConfig();
@@ -373,7 +373,7 @@ void loadTestSubjectConfigTarget1() throws Exception {
373373
@Test
374374
void loadTestSubjectConfigTarget2() throws Exception {
375375
final URL testFileUrl = TestUtils.getFileUrl(CONFIG_SAMPLE);
376-
final String subject = new URL(testFileUrl, "testserver2").toString();
376+
final String subject = testFileUrl.toURI().resolve("testserver2").toString();
377377
when(config.getSubjectsUrl()).thenReturn(testFileUrl);
378378
when(config.getTestSubject()).thenReturn(iri(subject));
379379
testSubject.loadTestSubjectConfig();
@@ -393,7 +393,7 @@ void getTargetServerDefault() throws Exception {
393393
final TargetServer targetServer = testSubject.getTargetServer();
394394

395395
assertNotNull(targetServer);
396-
assertEquals(new URL(testFileUrl, "default").toString(), targetServer.getSubject());
396+
assertEquals(testFileUrl.toURI().resolve("default").toString(), targetServer.getSubject());
397397
}
398398

399399
@Test

src/test/java/org/solid/testharness/discovery/TestSuiteDescriptionTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import jakarta.inject.Inject;
4646
import java.net.MalformedURLException;
47-
import java.net.URL;
47+
import java.net.URI;
4848
import java.util.Collections;
4949
import java.util.List;
5050

@@ -77,8 +77,8 @@ void setUp() {
7777
@Test
7878
void loadOneManifest() throws MalformedURLException {
7979
testSuiteDescription.load(List.of(
80-
new URL(NS + "test-manifest-sample-1.ttl"),
81-
new URL(NS + "specification-sample-1.ttl")
80+
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
81+
URI.create(NS + "specification-sample-1.ttl").toURL()
8282
));
8383
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
8484
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
@@ -92,10 +92,10 @@ void loadOneManifest() throws MalformedURLException {
9292
@Test
9393
void loadTwoManifest() throws MalformedURLException {
9494
testSuiteDescription.load(List.of(
95-
new URL(NS + "test-manifest-sample-1.ttl"),
96-
new URL(NS + "test-manifest-sample-2.ttl"),
97-
new URL(NS + "specification-sample-1.ttl"),
98-
new URL(NS + "specification-sample-2.ttl")
95+
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
96+
URI.create(NS + "test-manifest-sample-2.ttl").toURL(),
97+
URI.create(NS + "specification-sample-1.ttl").toURL(),
98+
URI.create(NS + "specification-sample-2.ttl").toURL()
9999
));
100100
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
101101
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
@@ -107,7 +107,7 @@ void loadTwoManifest() throws MalformedURLException {
107107

108108
@Test
109109
void loadRdfa() throws MalformedURLException {
110-
testSuiteDescription.load(List.of(new URL(NS + "specification-sample-1.html")));
110+
testSuiteDescription.load(List.of(URI.create(NS + "specification-sample-1.html").toURL()));
111111
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
112112
assertTrue(ask(iri(NS, "specification1#spec1"), SPEC.statement,
113113
literal("text of requirement 1")));
@@ -116,10 +116,10 @@ void loadRdfa() throws MalformedURLException {
116116
@Test
117117
void loadTwoManifestMixed() throws MalformedURLException {
118118
testSuiteDescription.load(List.of(
119-
new URL(NS + "test-manifest-sample-1.ttl"),
120-
new URL(NS + "test-manifest-sample-2.ttl"),
121-
new URL(NS + "specification-sample-1.html"),
122-
new URL(NS + "specification-sample-2.ttl")
119+
URI.create(NS + "test-manifest-sample-1.ttl").toURL(),
120+
URI.create(NS + "test-manifest-sample-2.ttl").toURL(),
121+
URI.create(NS + "specification-sample-1.html").toURL(),
122+
URI.create(NS + "specification-sample-2.ttl").toURL()
123123
));
124124
assertTrue(ask(iri(NS, "specification1"), RDF.type, DOAP.Specification));
125125
assertTrue(ask(iri(NS, "test-manifest-sample-1.ttl#group1-feature1"),
@@ -131,7 +131,7 @@ void loadTwoManifestMixed() throws MalformedURLException {
131131

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

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

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

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

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

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

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

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

243243
@Test
244244
void setNonRunningTestAssertionsMissingStatus() throws MalformedURLException {
245-
testSuiteDescription.load(List.of( new URL(NS + "test-manifest-sample-1.ttl")));
245+
testSuiteDescription.load(List.of(URI.create(NS + "test-manifest-sample-1.ttl").toURL()));
246246
add(iri(NS, "testcase"), RDF.type, TD.TestCase);
247247
testSuiteDescription.setNonRunningTestAssertions(null, List.of("accepted", "unreviewed"));
248248
assertEquals(7, count(null, RDF.type, TD.TestCase));

src/test/java/org/solid/testharness/utils/DataRepositoryTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.StringWriter;
4242
import java.io.Writer;
4343
import java.net.MalformedURLException;
44+
import java.net.URI;
4445
import java.net.URL;
4546
import java.nio.file.Files;
4647
import java.nio.file.Path;
@@ -377,7 +378,7 @@ void loadTurtle() throws MalformedURLException {
377378
void loadTurtleBadUrl() {
378379
final DataRepository dataRepository = new DataRepository();
379380
assertThrows(TestHarnessInitializationException.class,
380-
() -> dataRepository.load(new URL("file:/missing.txt"))
381+
() -> dataRepository.load(URI.create("file:/missing.txt").toURL())
381382
);
382383
}
383384

@@ -410,7 +411,7 @@ void loadRdfa() throws Exception {
410411
void loadRdfaBadUrl() {
411412
final DataRepository dataRepository = new DataRepository();
412413
assertThrows(TestHarnessInitializationException.class,
413-
() -> dataRepository.load(new URL("file:/missing.txt"), TestUtils.SAMPLE_BASE)
414+
() -> dataRepository.load(URI.create("file:/missing.txt").toURL(), TestUtils.SAMPLE_BASE)
414415
);
415416
}
416417

0 commit comments

Comments
 (0)