Skip to content

Commit a2cbdf0

Browse files
committed
Updated to JUnit 5
1 parent 10f6cc7 commit a2cbdf0

90 files changed

Lines changed: 750 additions & 825 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ allprojects {
2929
ext {
3030
nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
3131
spotbugsVersion = "4.5.2"
32-
junitVersion = "4.13.2"
32+
junitVersion = "5.8.2"
3333
}
3434
}
3535

extractor/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ test {
33
if (System.properties.containsKey('downloader')) {
44
systemProperty('downloader', System.getProperty('downloader'))
55
}
6+
useJUnitPlatform()
67
}
78

89
dependencies {
@@ -14,7 +15,11 @@ dependencies {
1415
implementation "com.github.spotbugs:spotbugs-annotations:$spotbugsVersion"
1516
implementation 'org.nibor.autolink:autolink:0.10.0'
1617

17-
testImplementation "junit:junit:$junitVersion"
18+
testImplementation platform("org.junit:junit-bom:$junitVersion")
19+
testImplementation 'org.junit.jupiter:junit-jupiter-api'
20+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
21+
testImplementation 'org.junit.jupiter:junit-jupiter-params'
22+
1823
testImplementation "com.squareup.okhttp3:okhttp:3.12.13"
1924
testImplementation 'com.google.code.gson:gson:2.8.9'
2025
}

extractor/src/test/java/org/schabi/newpipe/MockOnly.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

extractor/src/test/java/org/schabi/newpipe/MockOnlyRule.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

extractor/src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
import java.net.URL;
55
import java.util.ArrayList;
66
import java.util.Collections;
7-
import java.util.Comparator;
87
import java.util.List;
98

109
import javax.annotation.Nonnull;
1110
import javax.annotation.Nullable;
1211

13-
import static org.junit.Assert.assertArrayEquals;
14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertFalse;
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertFalse;
14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1917

2018
public class ExtractorAsserts {
2119
public static void assertEmptyErrors(String message, List<Throwable> errors) {
@@ -44,7 +42,7 @@ public static void assertIsValidUrl(String url) {
4442

4543
public static void assertIsSecureUrl(String urlToCheck) {
4644
URL url = urlFromString(urlToCheck);
47-
assertEquals("Protocol of URL is not secure", "https", url.getProtocol());
45+
assertEquals("https",url.getProtocol(), "Protocol of URL is not secure");
4846
}
4947

5048
public static void assertNotEmpty(String stringToCheck) {
@@ -53,7 +51,7 @@ public static void assertNotEmpty(String stringToCheck) {
5351

5452
public static void assertNotEmpty(@Nullable String message, String stringToCheck) {
5553
assertNotNull(message, stringToCheck);
56-
assertFalse(message, stringToCheck.isEmpty());
54+
assertFalse(stringToCheck.isEmpty(), message);
5755
}
5856

5957
public static void assertEmpty(String stringToCheck) {
@@ -62,12 +60,12 @@ public static void assertEmpty(String stringToCheck) {
6260

6361
public static void assertEmpty(@Nullable String message, String stringToCheck) {
6462
if (stringToCheck != null) {
65-
assertTrue(message, stringToCheck.isEmpty());
63+
assertTrue(stringToCheck.isEmpty(), message);
6664
}
6765
}
6866

6967
public static void assertAtLeast(long expected, long actual) {
70-
assertTrue(actual + " is not at least " + expected, actual >= expected);
68+
assertTrue(actual >= expected, actual + " is not at least " + expected);
7169
}
7270

7371
// this assumes that sorting a and b in-place is not an issue, so it's only intended for tests
@@ -85,4 +83,13 @@ public static void assertEqualsOrderIndependent(final List<String> expected,
8583
// using new ArrayList<> to make sure the type is the same
8684
assertEquals(new ArrayList<>(expected), new ArrayList<>(actual));
8785
}
86+
87+
public static void assertContains(
88+
final String shouldBeContained,
89+
final String container) {
90+
assertNotNull(shouldBeContained, "shouldBeContained is null");
91+
assertNotNull(container, "container is null");
92+
assertTrue(container.contains(shouldBeContained),
93+
"'" + shouldBeContained + "' should be contained inside '" + container +"'");
94+
}
8895
}

extractor/src/test/java/org/schabi/newpipe/extractor/NewPipeTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.schabi.newpipe.extractor;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.util.HashSet;
66

7-
import static org.junit.Assert.*;
7+
import static org.junit.jupiter.api.Assertions.*;
88
import static org.schabi.newpipe.extractor.NewPipe.getServiceByUrl;
99
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
1010
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -19,9 +19,11 @@ public void getAllServicesTest() throws Exception {
1919
public void testAllServicesHaveDifferentId() throws Exception {
2020
HashSet<Integer> servicesId = new HashSet<>();
2121
for (StreamingService streamingService : NewPipe.getServices()) {
22-
String errorMsg = "There are services with the same id = " + streamingService.getServiceId() + " (current service > " + streamingService.getServiceInfo().getName() + ")";
22+
final String errorMsg =
23+
"There are services with the same id = " + streamingService.getServiceId()
24+
+ " (current service > " + streamingService.getServiceInfo().getName() + ")";
2325

24-
assertTrue(errorMsg, servicesId.add(streamingService.getServiceId()));
26+
assertTrue(servicesId.add(streamingService.getServiceId()), errorMsg);
2527
}
2628
}
2729

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultExtractorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.schabi.newpipe.extractor.services;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.schabi.newpipe.extractor.Extractor;
5+
import org.schabi.newpipe.extractor.ExtractorAsserts;
56
import org.schabi.newpipe.extractor.StreamingService;
67

7-
import static org.hamcrest.CoreMatchers.*;
8-
import static org.junit.Assert.*;
8+
import static org.junit.jupiter.api.Assertions.*;
99
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1010

1111
public abstract class DefaultExtractorTest<T extends Extractor> implements BaseExtractorTest {
@@ -40,14 +40,14 @@ public void testId() throws Exception {
4040
public void testUrl() throws Exception {
4141
final String url = extractor().getUrl();
4242
assertIsSecureUrl(url);
43-
assertThat(url, containsString(expectedUrlContains()));
43+
ExtractorAsserts.assertContains(expectedUrlContains(), url);
4444
}
4545

4646
@Test
4747
@Override
4848
public void testOriginalUrl() throws Exception {
4949
final String originalUrl = extractor().getOriginalUrl();
5050
assertIsSecureUrl(originalUrl);
51-
assertThat(originalUrl, containsString(expectedOriginalUrlContains()));
51+
ExtractorAsserts.assertContains(expectedOriginalUrlContains(), originalUrl);
5252
}
5353
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultListExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.schabi.newpipe.extractor.services;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.schabi.newpipe.extractor.InfoItem;
55
import org.schabi.newpipe.extractor.ListExtractor;
66

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultSearchExtractorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.schabi.newpipe.extractor.services;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.schabi.newpipe.extractor.MetaInfo;
55
import org.schabi.newpipe.extractor.search.SearchExtractor;
66

@@ -13,8 +13,8 @@
1313
import java.util.List;
1414
import java.util.stream.Collectors;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1818
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
1919
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2020

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.schabi.newpipe.extractor.services;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.schabi.newpipe.extractor.ExtractorAsserts;
46
import org.schabi.newpipe.extractor.InfoItemsCollector;
57
import org.schabi.newpipe.extractor.MediaFormat;
68
import org.schabi.newpipe.extractor.MetaInfo;
@@ -23,13 +25,11 @@
2325
import java.util.Locale;
2426
import java.util.stream.Collectors;
2527

26-
import static org.hamcrest.CoreMatchers.containsString;
27-
import static org.hamcrest.MatcherAssert.assertThat;
28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertFalse;
30-
import static org.junit.Assert.assertNotNull;
31-
import static org.junit.Assert.assertNull;
32-
import static org.junit.Assert.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertFalse;
30+
import static org.junit.jupiter.api.Assertions.assertNotNull;
31+
import static org.junit.jupiter.api.Assertions.assertNull;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
3333
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertAtLeast;
3434
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEqualsOrderIndependent;
3535
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
@@ -149,13 +149,13 @@ public void testDescription() throws Exception {
149149
assertNotNull(description);
150150

151151
if (expectedDescriptionIsEmpty()) {
152-
assertTrue("description is not empty", description.getContent().isEmpty());
152+
assertTrue(description.getContent().isEmpty(), "description is not empty");
153153
} else {
154-
assertFalse("description is empty", description.getContent().isEmpty());
154+
assertFalse(description.getContent().isEmpty(), "description is empty");
155155
}
156156

157157
for (final String s : expectedDescriptionContains()) {
158-
assertThat(description.getContent(), containsString(s));
158+
ExtractorAsserts.assertContains(s, description.getContent());
159159
}
160160
}
161161

@@ -265,8 +265,8 @@ public void testVideoStreams() throws Exception {
265265

266266
final int formatId = stream.getFormatId();
267267
// see MediaFormat: video stream formats range from 0 to 0x100
268-
assertTrue("format id does not fit a video stream: " + formatId,
269-
0 <= formatId && formatId < 0x100);
268+
assertTrue(0 <= formatId && formatId < 0x100,
269+
"format id does not fit a video stream: " + formatId);
270270
}
271271
} else {
272272
assertTrue(videoStreams.isEmpty());
@@ -287,8 +287,8 @@ public void testAudioStreams() throws Exception {
287287

288288
final int formatId = stream.getFormatId();
289289
// see MediaFormat: video stream formats range from 0x100 to 0x1000
290-
assertTrue("format id does not fit an audio stream: " + formatId,
291-
0x100 <= formatId && formatId < 0x1000);
290+
assertTrue(0x100 <= formatId && formatId < 0x1000,
291+
"format id does not fit an audio stream: " + formatId);
292292
}
293293
} else {
294294
assertTrue(audioStreams.isEmpty());
@@ -309,8 +309,8 @@ public void testSubtitles() throws Exception {
309309

310310
final int formatId = stream.getFormatId();
311311
// see MediaFormat: video stream formats range from 0x1000 to 0x10000
312-
assertTrue("format id does not fit a subtitles stream: " + formatId,
313-
0x1000 <= formatId && formatId < 0x10000);
312+
assertTrue(0x1000 <= formatId && formatId < 0x10000,
313+
"format id does not fit a subtitles stream: " + formatId);
314314
}
315315
} else {
316316
assertTrue(subtitles.isEmpty());
@@ -333,7 +333,7 @@ public void testGetDashMpdUrl() throws Exception {
333333
assertTrue(dashMpdUrl.isEmpty());
334334
} else {
335335
assertIsSecureUrl(dashMpdUrl);
336-
assertThat(extractor().getDashMpdUrl(), containsString(expectedDashMpdUrlContains()));
336+
ExtractorAsserts.assertContains(expectedDashMpdUrlContains(), extractor().getDashMpdUrl());
337337
}
338338
}
339339

0 commit comments

Comments
 (0)