Skip to content

Commit

Permalink
Merge pull request #2266 from linghengqian/junit-jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero authored Sep 18, 2023
2 parents caab1ea + 458255f commit d4f7d94
Show file tree
Hide file tree
Showing 252 changed files with 1,667 additions and 1,574 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

package org.apache.shardingsphere.elasticjob.annotation;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertArrayEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import org.apache.shardingsphere.elasticjob.annotation.job.impl.SimpleTestJob;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import org.apache.shardingsphere.elasticjob.annotation.job.impl.SimpleTestJob;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

public final class ElasticJobConfigurationTest {

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

package org.apache.shardingsphere.elasticjob.api;

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

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public final class JobConfigurationTest {

Expand Down Expand Up @@ -81,13 +82,15 @@ public void assertBuildRequiredProperties() {
assertFalse(actual.isOverwrite());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void assertBuildWithEmptyJobName() {
JobConfiguration.newBuilder("", 3).cron("0/1 * * * * ?").build();
assertThrows(IllegalArgumentException.class, () ->
JobConfiguration.newBuilder("", 3).cron("0/1 * * * * ?").build());
}
@Test(expected = IllegalArgumentException.class)

@Test
public void assertBuildWithInvalidShardingTotalCount() {
JobConfiguration.newBuilder("test_job", -1).cron("0/1 * * * * ?").build();
assertThrows(IllegalArgumentException.class, () ->
JobConfiguration.newBuilder("test_job", -1).cron("0/1 * * * * ?").build());
}
}
8 changes: 0 additions & 8 deletions elasticjob-cloud/elasticjob-cloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public final class CloudJobConfigurationPOJOTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;
import java.util.Date;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class StatisticRdbRepositoryTest {

private StatisticRdbRepository repository;

@Before
@BeforeEach
public void setup() throws SQLException {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(org.h2.Driver.class.getName());
Expand Down
8 changes: 0 additions & 8 deletions elasticjob-cloud/elasticjob-cloud-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
import org.apache.shardingsphere.elasticjob.tracing.JobTracingEventBus;
import org.apache.shardingsphere.elasticjob.tracing.event.JobExecutionEvent;
import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent.State;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class CloudJobFacadeTest {

private ShardingContexts shardingContexts;
Expand All @@ -51,7 +51,7 @@ public final class CloudJobFacadeTest {

private JobFacade jobFacade;

@Before
@BeforeEach
public void setUp() {
shardingContexts = getShardingContexts();
jobFacade = new CloudJobFacade(shardingContexts, getJobConfiguration(), jobTracingEventBus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import org.apache.shardingsphere.elasticjob.dataflow.props.DataflowJobProperties;
import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
import org.apache.shardingsphere.elasticjob.script.props.ScriptJobProperties;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

public final class LocalTaskExecutorTest {

Expand All @@ -56,8 +57,9 @@ public void assertScriptJob() {
.cron("*/2 * * * * ?").setProperty(ScriptJobProperties.SCRIPT_KEY, "echo test").build(), 1).execute();
}

@Test(expected = JobConfigurationException.class)
@Test
public void assertNotExistsJobType() {
new LocalTaskExecutor("not exist", JobConfiguration.newBuilder("not exist", 3).cron("*/2 * * * * ?").build(), 1).execute();
assertThrows(JobConfigurationException.class, () ->
new LocalTaskExecutor("not exist", JobConfiguration.newBuilder("not exist", 3).cron("*/2 * * * * ?").build(), 1).execute());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
import org.apache.shardingsphere.elasticjob.infra.context.ExecutionType;
import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
import org.apache.shardingsphere.elasticjob.script.props.ScriptJobProperties;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.quartz.JobExecutionContext;

import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentHashMap;

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

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class DaemonTaskSchedulerTest {

@Mock
Expand All @@ -69,7 +69,7 @@ public final class DaemonTaskSchedulerTest {

private DaemonJob daemonJob;

@Before
@BeforeEach
public void setUp() {
daemonJob = new DaemonJob();
daemonJob.setJobFacade(jobFacade);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
import org.apache.mesos.Protos.TaskID;
import org.apache.mesos.Protos.TaskInfo;
import org.apache.shardingsphere.elasticjob.cloud.executor.fixture.TestSimpleJob;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class TaskExecutorTest {

@Mock
Expand All @@ -60,7 +60,7 @@ public final class TaskExecutorTest {

private TaskExecutor taskExecutor;

@Before
@BeforeEach
public void setUp() {
taskExecutor = new TaskExecutor(new TestSimpleJob());
setExecutorService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
import org.apache.shardingsphere.elasticjob.script.props.ScriptJobProperties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
import java.util.LinkedHashMap;

import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class TaskExecutorThreadTest {

@Mock
Expand Down
8 changes: 0 additions & 8 deletions elasticjob-cloud/elasticjob-cloud-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
import org.apache.shardingsphere.elasticjob.restful.NettyRestfulService;
import org.apache.shardingsphere.elasticjob.restful.NettyRestfulServiceConfiguration;
import org.apache.shardingsphere.elasticjob.restful.RestfulService;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public abstract class AbstractCloudControllerTest {

@Getter(AccessLevel.PROTECTED)
Expand All @@ -56,7 +56,7 @@ public abstract class AbstractCloudControllerTest {

private static RestfulService slaveServer;

@BeforeClass
@BeforeAll
public static void setUpClass() {
initRestfulServer();
initMesosServer();
Expand Down Expand Up @@ -85,15 +85,15 @@ private static void initMesosServer() {
slaveServer.startup();
}

@AfterClass
@AfterAll
public static void tearDown() {
consoleBootstrap.stop();
masterServer.shutdown();
slaveServer.shutdown();
MesosStateService.deregister();
}

@Before
@BeforeEach
public void setUp() {
reset(regCenter);
reset(jobEventRdbSearch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.apache.shardingsphere.elasticjob.cloud.console.HttpTestUtil;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppJsonConstants;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJsonConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -34,7 +34,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class CloudAppControllerTest extends AbstractCloudControllerTest {

private static final String YAML = "appCacheEnable: true\n"
Expand Down
Loading

0 comments on commit d4f7d94

Please sign in to comment.