Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade JUnit4 to Junit5 #372

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ext.versions = [
junit5 : "5.4.+",
mockito : "2.0.+",
mockito3 : "3.+",
mockito4 : "4.8.+",
spectator: "1.3.+",
slf4j : "1.7.0",
vavr : "0.9.2",
Expand All @@ -59,8 +60,9 @@ ext.libraries = [
"org.apache.flink:flink-rpc-akka:${versions.flink}",
],
junit4 : [
"junit:junit:${versions.junit4}",
"junit:junit-dep:${versions.junit4}",
"junit:junit:${versions.junit4}",
"junit:junit-dep:${versions.junit4}",
"org.junit.vintage:junit-vintage-engine:${versions.junit5}",
],
hadoopCommon : "org.apache.hadoop:hadoop-common:${versions.hadoop}",
hadoopS3 : "org.apache.hadoop:hadoop-aws:${versions.hadoop}",
Expand All @@ -74,6 +76,7 @@ ext.libraries = [
mockitoAll : "org.mockito:mockito-all:${versions.mockito}",
mockitoCore : "org.mockito:mockito-core:${versions.mockito}",
mockitoCore3 : "org.mockito:mockito-core:${versions.mockito3}",
mockitoCore4 : "org.mockito:mockito-core:${versions.mockito4}",
mockneat : "net.andreinc:mockneat:0.4.8",
rxJava : "io.reactivex:rxjava:1.3.8",
rxNettyShaded : "com.netflix:mantis-rxnetty:0.4.19.1",
Expand Down Expand Up @@ -161,6 +164,12 @@ subprojects {
printReleasedArtifact.dependsOn(project.rootProject.snapshot)
printAllReleasedArtifacts.dependsOn("${project.path}:printReleasedArtifact")
}

test {
useJUnitPlatform {
includeEngines 'junit-jupiter', 'junit-vintage'
}
}
}

apply from: file('baseline.gradle')
2 changes: 1 addition & 1 deletion mantis-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {

implementation libraries.slf4jApi
implementation libraries.spectatorApi
testImplementation libraries.junit4
testImplementation libraries.junitJupiter
testImplementation libraries.mockitoCore
}

Expand Down
41 changes: 25 additions & 16 deletions mantis-client/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,14 @@
}
},
"baseline-exact-dependencies-test": {
"junit:junit": {
"locked": "4.11"
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"junit:junit-dep": {
"locked": "4.11"
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
Expand Down Expand Up @@ -681,12 +684,6 @@
],
"locked": "2.12.5"
},
"junit:junit": {
"locked": "4.11"
},
"junit:junit-dep": {
"locked": "4.11"
},
"org.apache.flink:flink-core": {
"firstLevelTransitive": [
"io.mantisrx:mantis-control-plane-core"
Expand Down Expand Up @@ -723,6 +720,15 @@
],
"locked": "20180813"
},
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
},
Expand Down Expand Up @@ -893,12 +899,6 @@
],
"locked": "2.12.5"
},
"junit:junit": {
"locked": "4.11"
},
"junit:junit-dep": {
"locked": "4.11"
},
"net.jcip:jcip-annotations": {
"firstLevelTransitive": [
"io.mantisrx:mantis-common"
Expand Down Expand Up @@ -947,6 +947,15 @@
],
"locked": "20180813"
},
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
},
Expand Down
2 changes: 1 addition & 1 deletion mantis-client/src/test/java/MantisSSEJobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

import io.mantisrx.client.MantisClient;
import io.mantisrx.client.MantisSSEJob;
Expand Down
2 changes: 1 addition & 1 deletion mantis-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ dependencies {
testImplementation libraries.spectatorApi
testImplementation libraries.commonsLang3
testImplementation "org.hamcrest:hamcrest-core:1.3"
testImplementation libraries.junit4
testImplementation libraries.junitJupiter
testImplementation libraries.mockitoCore
}
45 changes: 27 additions & 18 deletions mantis-common/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
],
"locked": "1.3.8"
},
"junit:junit": {
"locked": "4.11"
},
"junit:junit-dep": {
"locked": "4.11"
},
"org.apache.commons:commons-lang3": {
"locked": "3.5"
},
Expand All @@ -83,6 +77,15 @@
],
"locked": "1.2.1"
},
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
},
Expand Down Expand Up @@ -271,12 +274,6 @@
],
"locked": "1.3.8"
},
"junit:junit": {
"locked": "4.11"
},
"junit:junit-dep": {
"locked": "4.11"
},
"net.jcip:jcip-annotations": {
"locked": "1.0"
},
Expand All @@ -292,6 +289,15 @@
],
"locked": "1.2.1"
},
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
},
Expand Down Expand Up @@ -552,12 +558,6 @@
],
"locked": "0.9.2"
},
"junit:junit": {
"locked": "4.11"
},
"junit:junit-dep": {
"locked": "4.11"
},
"net.jcip:jcip-annotations": {
"firstLevelTransitive": [
"io.mantisrx:mantis-common"
Expand All @@ -576,6 +576,15 @@
],
"locked": "1.2.1"
},
"org.junit.jupiter:junit-jupiter-api": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-engine": {
"locked": "5.4.2"
},
"org.junit.jupiter:junit-jupiter-params": {
"locked": "5.4.2"
},
"org.mockito:mockito-core": {
"locked": "2.0.111-beta"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package com.mantisrx.common.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import io.mantisrx.common.Label;
import io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException;
import io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;


public class LabelUtilsTest {
Expand Down Expand Up @@ -189,4 +189,4 @@ public void testSerDe() {
}


}
}
4 changes: 2 additions & 2 deletions mantis-common/src/test/java/io/mantisrx/common/AckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.mantisrx.common;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AckTest {
private final JsonSerializer serializer = new JsonSerializer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package io.mantisrx.common;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class WorkerPortsTest {

Expand All @@ -29,31 +30,37 @@ public class WorkerPortsTest {
* Uses legacy constructor {@link WorkerPorts#WorkerPorts(List)} which expects
* at least 5 ports: metrics, debug, console, custom.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void shouldNotConstructWorkerPorts() {
// Not enough ports.
new WorkerPorts(Arrays.asList(1, 1, 1, 1));
assertThrows(IllegalArgumentException.class, () -> {
// Not enough ports.
new WorkerPorts(Arrays.asList(1, 1, 1, 1));
});
}

/**
* Uses legacy constructor {@link WorkerPorts#WorkerPorts(List)} which cannot construct
* a WorkerPorts object, because a worker needs a sink to be useful.
* Otherwise, other workers can't connect to it.
*/
@Test(expected = IllegalStateException.class)
@Test
public void shouldNotConstructWorkerPortsWithDuplicatePorts() {
// Enough ports, but has duplicate ports.
new WorkerPorts(Arrays.asList(1, 1, 1, 1, 1));
assertThrows(IllegalStateException.class, () -> {
// Enough ports, but has duplicate ports.
new WorkerPorts(Arrays.asList(1, 1, 1, 1, 1));
});
}

/**
* Uses legacy constructor {@link WorkerPorts#WorkerPorts(List)} but was given a port
* out of range.
*/
@Test(expected = IllegalStateException.class)
@Test
public void shouldNotConstructWorkerPortsWithInvalidPortRange() {
// Enough ports, but given an invalid port range
new WorkerPorts(Arrays.asList(1, 1, 1, 1, 65536));
assertThrows(IllegalStateException.class, () -> {
// Enough ports, but given an invalid port range
new WorkerPorts(Arrays.asList(1, 1, 1, 1, 65536));
});
}

/**
Expand Down Expand Up @@ -82,4 +89,4 @@ public void testWorkerPortsIsSerializableByJava() {
byte[] serialized = SerializationUtils.serialize(workerPorts);
assertEquals(workerPorts, SerializationUtils.deserialize(serialized));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.mantisrx.common.compression;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import io.mantisrx.common.MantisServerSentEvent;
import java.io.BufferedReader;
Expand All @@ -24,7 +24,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CompressionUtilsTest {

Expand Down Expand Up @@ -56,7 +56,7 @@ public void shouldTokenizeWithEventsContainingPartialDelimiterMatchesWithCustomD
List<MantisServerSentEvent> result = CompressionUtils.tokenize(reader, delimiter);

List<String> actual = result.stream().map(e -> e.getEventAsString()).collect(Collectors.toList());
assertEquals("Delimiter: '" + delimiter + "'", Arrays.asList(event1,event2,event3), actual);
assertEquals(Arrays.asList(event1,event2,event3), actual, "Delimiter: '" + delimiter + "'");
}

@Test
Expand All @@ -76,7 +76,7 @@ public void testDelimiterWiithPrefixMatchingEndOfMEssage() throws Exception {
List<MantisServerSentEvent> result = CompressionUtils.tokenize(reader, delimiter);

List<String> actual = result.stream().map(e -> e.getEventAsString()).collect(Collectors.toList());
assertEquals("Delimiter: '" + delimiter + "'", Arrays.asList(event1,event2,event3), actual);
assertEquals(Arrays.asList(event1,event2,event3), actual, "Delimiter: '" + delimiter + "'");
}

@Test
Expand All @@ -102,7 +102,7 @@ public void testMultiline() throws Exception {
List<MantisServerSentEvent> result = CompressionUtils.tokenize(reader, delimiter);

List<String> actual = result.stream().map(e -> e.getEventAsString()).collect(Collectors.toList());
assertEquals("Delimiter: '" + delimiter + "'", Arrays.asList(event1,event2,event3), actual);
assertEquals(Arrays.asList(event1,event2,event3), actual, "Delimiter: '" + delimiter + "'");
}

@Test
Expand Down
Loading