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

[ISSUE #4478] Upgrade JUnit to JUnit Jupiter #4475

Merged
merged 8 commits into from
Oct 10, 2023
Merged
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: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ allprojects {
url "https://maven.aliyun.com/repository/public"
}
}
testImplementation "junit:junit:4.13.2"
testImplementation "org.junit.jupiter:junit-jupiter:5.6.0"
}

spotless {
Expand All @@ -126,6 +126,10 @@ allprojects {
}
}
spotlessJava.dependsOn(compileJava, javadoc, compileTestJava, test, processResources, processTestResources)

test {
useJUnitPlatform()
}
}

task tar(type: Tar) {
Expand Down Expand Up @@ -516,14 +520,13 @@ subprojects {
dependency "org.springframework.boot:spring-boot-starter-web:2.7.10"
dependency "io.openmessaging:registry-server:0.0.1"

dependency "junit:junit:4.13.2"
dependency "com.github.stefanbirkner:system-rules:1.16.1"
dependency "org.junit.jupiter:junit-jupiter:5.6.0"
dependency "org.junit-pioneer:junit-pioneer:1.9.1"
dependency "org.assertj:assertj-core:2.6.0"

dependency "org.mockito:mockito-core:3.8.0"
dependency "org.mockito:mockito-inline:3.8.0"
dependency "org.powermock:powermock-module-junit4:2.0.2"
dependency "org.powermock:powermock-api-mockito2:2.0.9"
dependency "org.mockito:mockito-junit-jupiter:3.8.0"

dependency "io.cloudevents:cloudevents-core:2.4.2"
dependency "io.cloudevents:cloudevents-json-jackson:2.4.2"
Expand Down
1 change: 0 additions & 1 deletion eventmesh-admin/eventmesh-admin-rocketmq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-inline'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.apache.eventmesh.admin.rocketmq.request;

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

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

import com.fasterxml.jackson.databind.ObjectMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.eventmesh.admin.rocketmq.response;

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

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

import com.fasterxml.jackson.databind.ObjectMapper;

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

package org.apache.eventmesh.admin.rocketmq.util;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -26,7 +26,7 @@
import java.net.URI;
import java.net.URISyntaxException;

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

import com.sun.net.httpserver.HttpExchange;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.eventmesh.admin.rocketmq.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -29,16 +29,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

public class UrlMappingPatternTest {

private static final String TEST_URL_MAPPING_PATTERN = "/test/{param1}/path/{param2}";

private TestUrlMappingPattern urlMappingPattern;

@Before
@BeforeEach
public void setUp() {
urlMappingPattern = new TestUrlMappingPattern(TEST_URL_MAPPING_PATTERN);
}
Expand Down
5 changes: 2 additions & 3 deletions eventmesh-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation "javax.annotation:javax.annotation-api:1.3.2"

implementation "com.github.stefanbirkner:system-rules"
testImplementation "org.junit-pioneer:junit-pioneer"
implementation "org.yaml:snakeyaml"

compileOnly 'org.projectlombok:lombok'
Expand Down Expand Up @@ -77,6 +77,5 @@ dependencies {
testImplementation "org.assertj:assertj-core"

testImplementation "org.mockito:mockito-core"
testImplementation "org.powermock:powermock-module-junit4"
testImplementation "org.powermock:powermock-api-mockito2"
testImplementation "org.mockito:mockito-junit-jupiter"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import java.util.HashMap;
import java.util.Map;

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

public class EventMeshMessageTest {

@Test
public void testGetProp() {
EventMeshMessage message = createLiteMessage();
Assert.assertEquals(2L, message.getProp().size());
Assertions.assertEquals(2L, message.getProp().size());
}

@Test
Expand All @@ -37,30 +37,30 @@ public void testSetProp() {
Map<String, String> prop = new HashMap<>();
prop.put("key3", "value3");
message.setProp(prop);
Assert.assertEquals(1L, message.getProp().size());
Assert.assertEquals("value3", message.getProp("key3"));
Assertions.assertEquals(1L, message.getProp().size());
Assertions.assertEquals("value3", message.getProp("key3"));
}

@Test
public void testAddProp() {
EventMeshMessage message = createLiteMessage();
message.addProp("key3", "value3");
Assert.assertEquals(3L, message.getProp().size());
Assert.assertEquals("value1", message.getProp("key1"));
Assertions.assertEquals(3L, message.getProp().size());
Assertions.assertEquals("value1", message.getProp("key1"));
}

@Test
public void testGetPropKey() {
EventMeshMessage message = createLiteMessage();
Assert.assertEquals("value1", message.getProp("key1"));
Assertions.assertEquals("value1", message.getProp("key1"));
}

@Test
public void testRemoveProp() {
EventMeshMessage message = createLiteMessage();
message.removePropIfPresent("key1");
Assert.assertEquals(1L, message.getProp().size());
Assert.assertNull(message.getProp("key1"));
Assertions.assertEquals(1L, message.getProp().size());
Assertions.assertNull(message.getProp("key1"));
}

private EventMeshMessage createLiteMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

package org.apache.eventmesh.common;

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

public class EventMeshThreadFactoryTest {

@Test
public void testGetThreadNamePrefix() {
final String threadNamePrefix = "threadNamePrefix";
EventMeshThreadFactory factory = new EventMeshThreadFactory(threadNamePrefix, false);
Assert.assertEquals(threadNamePrefix, factory.getThreadNamePrefix());
Assertions.assertEquals(threadNamePrefix, factory.getThreadNamePrefix());
}

@Test
Expand All @@ -36,8 +36,8 @@ public void testNewThread() {
Thread t = factory.newThread(() -> {

});
Assert.assertNotNull(t);
Assert.assertEquals(threadNamePrefix + "-1", t.getName());
Assert.assertTrue(t.isDaemon());
Assertions.assertNotNull(t);
Assertions.assertEquals(threadNamePrefix + "-1", t.getName());
Assertions.assertTrue(t.isDaemon());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

public class ResetCountDownLatchTest {

Expand All @@ -29,51 +30,52 @@ public void testConstructorParameterError() {
try {
new ResetCountDownLatch(-1);
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "count must be greater than or equal to 0");
Assertions.assertEquals(e.getMessage(), "count must be greater than or equal to 0");
}
ResetCountDownLatch resetCountDownLatch = new ResetCountDownLatch(1);
Assert.assertEquals(1, resetCountDownLatch.getCount());
Assertions.assertEquals(1, resetCountDownLatch.getCount());
}

@Test
public void testAwaitTimeout() throws InterruptedException {
ResetCountDownLatch latch = new ResetCountDownLatch(1);
boolean await = latch.await(5, TimeUnit.MILLISECONDS);
Assert.assertFalse(await);
Assertions.assertFalse(await);
latch.countDown();
await = latch.await(5, TimeUnit.MILLISECONDS);
Assert.assertTrue(await);
Assertions.assertTrue(await);
}

@Test(timeout = 1000)
@Test
@Timeout(1000)
public void testCountDownAndGetCount() throws InterruptedException {
int count = 2;
ResetCountDownLatch resetCountDownLatch = new ResetCountDownLatch(count);
Assert.assertEquals(count, resetCountDownLatch.getCount());
Assertions.assertEquals(count, resetCountDownLatch.getCount());
resetCountDownLatch.countDown();
Assert.assertEquals(count - 1, resetCountDownLatch.getCount());
Assertions.assertEquals(count - 1, resetCountDownLatch.getCount());
resetCountDownLatch.countDown();
resetCountDownLatch.await();
Assert.assertEquals(0, resetCountDownLatch.getCount());
Assertions.assertEquals(0, resetCountDownLatch.getCount());
}

@Test
public void testReset() throws InterruptedException {
int count = 2;
ResetCountDownLatch resetCountDownLatch = new ResetCountDownLatch(count);
resetCountDownLatch.countDown();
Assert.assertEquals(count - 1, resetCountDownLatch.getCount());
Assertions.assertEquals(count - 1, resetCountDownLatch.getCount());
resetCountDownLatch.reset();
Assert.assertEquals(count, resetCountDownLatch.getCount());
Assertions.assertEquals(count, resetCountDownLatch.getCount());
resetCountDownLatch.countDown();
resetCountDownLatch.countDown();
resetCountDownLatch.await();
Assert.assertEquals(0, resetCountDownLatch.getCount());
Assertions.assertEquals(0, resetCountDownLatch.getCount());
resetCountDownLatch.countDown();
Assert.assertEquals(0, resetCountDownLatch.getCount());
Assertions.assertEquals(0, resetCountDownLatch.getCount());
resetCountDownLatch.reset();
resetCountDownLatch.countDown();
Assert.assertEquals(1, resetCountDownLatch.getCount());
Assertions.assertEquals(1, resetCountDownLatch.getCount());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,37 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

public class ThreadWrapperTest {

@Test
public void getThreadName() {
ThreadWrapper wrapper = createThreadWrapper(false);
wrapper.start();
Assert.assertEquals("EventMesh-Wrapper-mxsm", wrapper.thread.getName());
Assertions.assertEquals("EventMesh-Wrapper-mxsm", wrapper.thread.getName());
}

@Test
public void start() {
ThreadWrapper wrapper = createThreadWrapper(false);
wrapper.start();
Assert.assertTrue(wrapper.isStated());
Assertions.assertTrue(wrapper.isStated());
}

@Test(timeout = 1000)
@Test
@Timeout(1000)
public void await() {
ThreadWrapper wrapper = createThreadWrapper(false);
wrapper.start();
wrapper.await(1, TimeUnit.MILLISECONDS);
Assert.assertFalse(wrapper.hasWakeup.get());
Assertions.assertFalse(wrapper.hasWakeup.get());
wrapper.wakeup();
Assert.assertTrue(wrapper.hasWakeup.get());
Assertions.assertTrue(wrapper.hasWakeup.get());
wrapper.await();
Assert.assertFalse(wrapper.hasWakeup.get());
Assertions.assertFalse(wrapper.hasWakeup.get());
wrapper.await(2, TimeUnit.MILLISECONDS);

}
Expand Down Expand Up @@ -79,7 +81,7 @@ public void run() {
};
wrapper.start();
wrapper.shutdown();
Assert.assertEquals(100, counter.get());
Assertions.assertEquals(100, counter.get());
}

@Test
Expand All @@ -104,18 +106,18 @@ public void run() {
};
wrapper.start();
wrapper.shutdownImmediately();
Assert.assertEquals(0, counter.get());
Assertions.assertEquals(0, counter.get());
}

@Test
public void setDaemon() {
ThreadWrapper threadWrapper = createThreadWrapper(true);
threadWrapper.start();
Assert.assertTrue(threadWrapper.thread.isDaemon());
Assertions.assertTrue(threadWrapper.thread.isDaemon());

ThreadWrapper threadWrapper1 = createThreadWrapper(false);
threadWrapper1.start();
Assert.assertFalse(threadWrapper1.thread.isDaemon());
Assertions.assertFalse(threadWrapper1.thread.isDaemon());
}

private ThreadWrapper createThreadWrapper(boolean daemon) {
Expand Down
Loading