Skip to content

Commit

Permalink
[ISSUE #12016] upgrade to junit5 and remove junit4 (#12280)
Browse files Browse the repository at this point in the history
* clean junit4

* clean junit4

* clean some test dep; fix scope

* fix test compile
  • Loading branch information
shalk authored Jun 26, 2024
1 parent 108f510 commit 8034da8
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 209 deletions.
4 changes: 2 additions & 2 deletions address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
5 changes: 0 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -55,20 +53,20 @@ class InstanceBuilderTest {
@Test
void testBuildFullInstance() {
InstanceBuilder builder = InstanceBuilder.newBuilder();
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
.setEphemeral(EPHEMERAL).addMetadata(META_KEY, META_VALUE).build();
assertThat(actual.getServiceName(), is(SERVICE_NAME));
assertThat(actual.getClusterName(), is(CLUSTER_NAME));
assertThat(actual.getInstanceId(), is(INSTANCE_ID));
assertThat(actual.getIp(), is(IP));
assertThat(actual.getPort(), is(PORT));
assertThat(actual.getWeight(), is(WEIGHT));
assertThat(actual.isHealthy(), is(HEALTHY));
assertThat(actual.isEnabled(), is(ENABLED));
assertThat(actual.isEphemeral(), is(EPHEMERAL));
assertThat(actual.getMetadata().size(), is(1));
assertThat(actual.getMetadata().get(META_KEY), is(META_VALUE));
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID).setIp(IP)
.setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED).setEphemeral(EPHEMERAL)
.addMetadata(META_KEY, META_VALUE).build();
assertEquals(actual.getServiceName(), SERVICE_NAME);
assertEquals(actual.getClusterName(), CLUSTER_NAME);
assertEquals(actual.getInstanceId(), INSTANCE_ID);
assertEquals(actual.getIp(), IP);
assertEquals(actual.getPort(), PORT);
assertEquals(actual.getWeight(), WEIGHT);
assertEquals(actual.isHealthy(), HEALTHY);
assertEquals(actual.isEnabled(), ENABLED);
assertEquals(actual.isEphemeral(), EPHEMERAL);
assertEquals(actual.getMetadata().size(), 1);
assertEquals(actual.getMetadata().get(META_KEY), META_VALUE);
}

@Test
Expand All @@ -81,8 +79,8 @@ void testBuildInstanceWithoutNewMetadata() {
assertNull(actual.getClusterName());
assertNull(actual.getInstanceId());
assertNull(actual.getIp());
assertThat(actual.getPort(), is(0));
assertThat(actual.getWeight(), is(1.0));
assertEquals(actual.getPort(), 0);
assertEquals(actual.getWeight(), 1.0);
assertTrue(actual.isHealthy());
assertTrue(actual.isEnabled());
assertTrue(actual.isEphemeral());
Expand All @@ -97,8 +95,8 @@ void testBuildEmptyInstance() {
assertNull(actual.getClusterName());
assertNull(actual.getInstanceId());
assertNull(actual.getIp());
assertThat(actual.getPort(), is(0));
assertThat(actual.getWeight(), is(1.0));
assertEquals(actual.getPort(), 0);
assertEquals(actual.getWeight(), 1.0);
assertTrue(actual.isHealthy());
assertTrue(actual.isEnabled());
assertTrue(actual.isEphemeral());
Expand Down
6 changes: 5 additions & 1 deletion auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@

import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.builder.InstanceBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

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

public class InstancesDiffTest {

private static List<Instance> getInstanceList(int count) {
ArrayList<Instance> list = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
list.add(new Instance());
}
return list;
}

@Test
public void testGetDiff() {
String serviceName = "testService";
Expand All @@ -40,13 +51,13 @@ public void testGetDiff() {
instancesDiff.setRemovedInstances(Collections.singletonList(removedIns));
instancesDiff.setModifiedInstances(Collections.singletonList(modifiedIns));

Assert.assertTrue(instancesDiff.hasDifferent());
Assert.assertTrue(instancesDiff.isAdded());
Assert.assertTrue(instancesDiff.isRemoved());
Assert.assertTrue(instancesDiff.isModified());
Assert.assertEquals(addedIns, instancesDiff.getAddedInstances().get(0));
Assert.assertEquals(removedIns, instancesDiff.getRemovedInstances().get(0));
Assert.assertEquals(modifiedIns, instancesDiff.getModifiedInstances().get(0));
assertTrue(instancesDiff.hasDifferent());
assertTrue(instancesDiff.isAdded());
assertTrue(instancesDiff.isRemoved());
assertTrue(instancesDiff.isModified());
assertEquals(addedIns, instancesDiff.getAddedInstances().get(0));
assertEquals(removedIns, instancesDiff.getRemovedInstances().get(0));
assertEquals(modifiedIns, instancesDiff.getModifiedInstances().get(0));
}

@Test
Expand All @@ -58,21 +69,21 @@ public void testWithFullConstructor() {
InstancesDiff instancesDiff = new InstancesDiff(getInstanceList(addedCount), getInstanceList(removedCount),
getInstanceList(modifiedCount));

Assert.assertTrue(instancesDiff.hasDifferent());
Assert.assertTrue(instancesDiff.isAdded());
Assert.assertTrue(instancesDiff.isRemoved());
Assert.assertTrue(instancesDiff.isModified());
Assert.assertEquals(addedCount, instancesDiff.getAddedInstances().size());
Assert.assertEquals(removedCount, instancesDiff.getRemovedInstances().size());
Assert.assertEquals(modifiedCount, instancesDiff.getModifiedInstances().size());
assertTrue(instancesDiff.hasDifferent());
assertTrue(instancesDiff.isAdded());
assertTrue(instancesDiff.isRemoved());
assertTrue(instancesDiff.isModified());
assertEquals(addedCount, instancesDiff.getAddedInstances().size());
assertEquals(removedCount, instancesDiff.getRemovedInstances().size());
assertEquals(modifiedCount, instancesDiff.getModifiedInstances().size());
instancesDiff.getAddedInstances().clear();
instancesDiff.getRemovedInstances().clear();
instancesDiff.getModifiedInstances().clear();
Assert.assertFalse(instancesDiff.hasDifferent());
Assert.assertFalse(instancesDiff.hasDifferent());
Assert.assertFalse(instancesDiff.isAdded());
Assert.assertFalse(instancesDiff.isRemoved());
Assert.assertFalse(instancesDiff.isModified());
assertFalse(instancesDiff.hasDifferent());
assertFalse(instancesDiff.hasDifferent());
assertFalse(instancesDiff.isAdded());
assertFalse(instancesDiff.isRemoved());
assertFalse(instancesDiff.isModified());
}

@Test
Expand All @@ -86,24 +97,16 @@ public void testWithNoConstructor() {
instancesDiff.setRemovedInstances(getInstanceList(removedCount));
instancesDiff.setModifiedInstances(getInstanceList(modifiedCount));

Assert.assertTrue(instancesDiff.hasDifferent());
Assert.assertEquals(addedCount, instancesDiff.getAddedInstances().size());
Assert.assertEquals(removedCount, instancesDiff.getRemovedInstances().size());
Assert.assertEquals(modifiedCount, instancesDiff.getModifiedInstances().size());
assertTrue(instancesDiff.hasDifferent());
assertEquals(addedCount, instancesDiff.getAddedInstances().size());
assertEquals(removedCount, instancesDiff.getRemovedInstances().size());
assertEquals(modifiedCount, instancesDiff.getModifiedInstances().size());
instancesDiff.getAddedInstances().clear();
instancesDiff.getRemovedInstances().clear();
instancesDiff.getModifiedInstances().clear();
Assert.assertFalse(instancesDiff.hasDifferent());
Assert.assertFalse(instancesDiff.isAdded());
Assert.assertFalse(instancesDiff.isRemoved());
Assert.assertFalse(instancesDiff.isModified());
}

private static List<Instance> getInstanceList(int count) {
ArrayList<Instance> list = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
list.add(new Instance());
}
return list;
assertFalse(instancesDiff.hasDifferent());
assertFalse(instancesDiff.isAdded());
assertFalse(instancesDiff.isRemoved());
assertFalse(instancesDiff.isModified());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@

import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.event.InstancesDiff;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
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 static org.junit.jupiter.api.Assertions.assertFalse;

public class NamingChangeEventTest {

private MockNamingEventListener eventListener;

private InstancesDiff instancesDiff;

@Before
@BeforeEach
public void setUp() throws Exception {
eventListener = new MockNamingEventListener();
instancesDiff = new InstancesDiff();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.selector.NamingContext;
import com.alibaba.nacos.api.naming.selector.NamingResult;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

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 static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import com.alibaba.nacos.client.naming.event.InstancesDiff;
import com.alibaba.nacos.client.naming.listener.AbstractNamingChangeListener;
import com.alibaba.nacos.client.naming.listener.NamingChangeEvent;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import com.alibaba.nacos.api.naming.selector.NamingContext;
import com.alibaba.nacos.api.naming.selector.NamingResult;
import com.alibaba.nacos.api.naming.selector.NamingSelector;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
import com.alibaba.nacos.client.naming.event.InstancesChangeEvent;
import com.alibaba.nacos.client.naming.event.InstancesDiff;
import com.alibaba.nacos.client.naming.listener.NamingChangeEvent;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package com.alibaba.nacos.client.selector;

import com.alibaba.nacos.client.naming.selector.NamingSelectorWrapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

public class SelectorManagerTest {
Expand Down
5 changes: 0 additions & 5 deletions cmdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -100,13 +99,13 @@ void getStatus() throws NacosException {
traceEventPublisher.publish(new TraceTestEvent.TraceTestEvent1());
traceEventPublisher.publish(new TraceTestEvent.TraceTestEvent2());
String expectedStatus = "Publisher TraceTestEvent : shutdown=false, queue= 3/8 ";
assertThat(traceEventPublisher.getStatus(), is(expectedStatus));
assertEquals(traceEventPublisher.getStatus(), expectedStatus);
traceEventPublisher.addSubscriber(subscriber, TraceTestEvent.TraceTestEvent1.class);
ThreadUtils.sleep(2000L);
expectedStatus = "Publisher TraceTestEvent : shutdown=false, queue= 0/8 ";
assertThat(traceEventPublisher.getStatus(), is(expectedStatus));
assertEquals(traceEventPublisher.getStatus(), expectedStatus);
traceEventPublisher.shutdown();
expectedStatus = "Publisher TraceTestEvent : shutdown= true, queue= 0/8 ";
assertThat(traceEventPublisher.getStatus(), is(expectedStatus));
assertEquals(traceEventPublisher.getStatus(), expectedStatus);
}
}
Loading

0 comments on commit 8034da8

Please sign in to comment.