You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/21 11:43:55 UTC
[shardingsphere-elasticjob] branch master updated: Revise test
cases (#1228)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new f7aeabb Revise test cases (#1228)
f7aeabb is described below
commit f7aeabb1365caa57f878785b1557b8e110df0f99
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Jul 21 19:43:46 2020 +0800
Revise test cases (#1228)
---
.../dataflow/executor/DataflowJobExecutorTest.java | 13 ++++++++-----
.../elasticjob/script/ScriptJobExecutorTest.java | 13 +++++++------
.../simple/executor/SimpleJobExecutorTest.java | 11 ++++++-----
.../spring/boot/job/ElasticJobSpringBootTest.java | 21 +++++++++++----------
4 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/elasticjob-executor/elasticjob-executor-type/elasticjob-dataflow-executor/src/test/java/org/apache/shardingsphere/elasticjob/dataflow/executor/DataflowJobExecutorTest.java b/elasticjob-executor/elasticjob-executor-type/elasticjob-dataflow-executor/src/test/java/org/apache/shardingsphere/elasticjob/dataflow/executor/DataflowJobExecutorTest.java
index 64c9a14..c736961 100644
--- a/elasticjob-executor/elasticjob-executor-type/elasticjob-dataflow-executor/src/test/java/org/apache/shardingsphere/elasticjob/dataflow/executor/DataflowJobExecutorTest.java
+++ b/elasticjob-executor/elasticjob-executor-type/elasticjob-dataflow-executor/src/test/java/org/apache/shardingsphere/elasticjob/dataflow/executor/DataflowJobExecutorTest.java
@@ -32,7 +32,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Properties;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -62,8 +63,9 @@ public final class DataflowJobExecutorTest {
jobExecutor = new DataflowJobExecutor();
}
+ @SuppressWarnings("unchecked")
@Test
- public void testProcessWithStreamingExecute() {
+ public void assertProcessWithStreamingExecute() {
List<String> data = Arrays.asList("DataflowJob1", "DataflowJob2");
when(jobConfig.getProps()).thenReturn(properties);
when(properties.getOrDefault(DataflowJobProperties.STREAM_PROCESS_KEY, false)).thenReturn("true");
@@ -73,8 +75,9 @@ public final class DataflowJobExecutorTest {
verify(elasticJob, times(1)).processData(shardingContext, data);
}
+ @SuppressWarnings("unchecked")
@Test
- public void testProcessWithOneOffExecute() {
+ public void assertProcessWithOneOffExecute() {
List<String> data = Arrays.asList("DataflowJob1", "DataflowJob2");
when(jobConfig.getProps()).thenReturn(properties);
when(properties.getOrDefault(DataflowJobProperties.STREAM_PROCESS_KEY, false)).thenReturn("false");
@@ -84,7 +87,7 @@ public final class DataflowJobExecutorTest {
}
@Test
- public void testGetElasticJobClass() {
- assertEquals(DataflowJob.class, jobExecutor.getElasticJobClass());
+ public void assertGetElasticJobClass() {
+ assertThat(jobExecutor.getElasticJobClass(), is(DataflowJob.class));
}
}
diff --git a/elasticjob-executor/elasticjob-executor-type/elasticjob-script-executor/src/test/java/org/apache/shardingsphere/elasticjob/script/ScriptJobExecutorTest.java b/elasticjob-executor/elasticjob-executor-type/elasticjob-script-executor/src/test/java/org/apache/shardingsphere/elasticjob/script/ScriptJobExecutorTest.java
index eeb791f..625694c 100644
--- a/elasticjob-executor/elasticjob-executor-type/elasticjob-script-executor/src/test/java/org/apache/shardingsphere/elasticjob/script/ScriptJobExecutorTest.java
+++ b/elasticjob-executor/elasticjob-executor-type/elasticjob-script-executor/src/test/java/org/apache/shardingsphere/elasticjob/script/ScriptJobExecutorTest.java
@@ -33,7 +33,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Properties;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -62,27 +63,27 @@ public final class ScriptJobExecutorTest {
}
@Test(expected = JobConfigurationException.class)
- public void testProcessWithJobConfigurationException() {
+ public void assertProcessWithJobConfigurationException() {
when(jobConfig.getProps()).thenReturn(properties);
jobExecutor.process(elasticJob, jobConfig, jobFacade, shardingContext);
}
@Test(expected = JobSystemException.class)
- public void testProcessWithJobSystemException() {
+ public void assertProcessWithJobSystemException() {
when(jobConfig.getProps()).thenReturn(properties);
when(properties.getProperty(ScriptJobProperties.SCRIPT_KEY)).thenReturn("demo.sh");
jobExecutor.process(elasticJob, jobConfig, jobFacade, shardingContext);
}
@Test
- public void testProcess() {
+ public void assertProcess() {
when(jobConfig.getProps()).thenReturn(properties);
when(properties.getProperty(ScriptJobProperties.SCRIPT_KEY)).thenReturn("echo script-job");
jobExecutor.process(elasticJob, jobConfig, jobFacade, shardingContext);
}
@Test
- public void testGetType() {
- assertEquals("SCRIPT", jobExecutor.getType());
+ public void assertGetType() {
+ assertThat(jobExecutor.getType(), is("SCRIPT"));
}
}
diff --git a/elasticjob-executor/elasticjob-executor-type/elasticjob-simple-executor/src/test/java/org/apache/shardingsphere/elasticjob/simple/executor/SimpleJobExecutorTest.java b/elasticjob-executor/elasticjob-executor-type/elasticjob-simple-executor/src/test/java/org/apache/shardingsphere/elasticjob/simple/executor/SimpleJobExecutorTest.java
index ef952cd..5079409 100644
--- a/elasticjob-executor/elasticjob-executor-type/elasticjob-simple-executor/src/test/java/org/apache/shardingsphere/elasticjob/simple/executor/SimpleJobExecutorTest.java
+++ b/elasticjob-executor/elasticjob-executor-type/elasticjob-simple-executor/src/test/java/org/apache/shardingsphere/elasticjob/simple/executor/SimpleJobExecutorTest.java
@@ -27,13 +27,14 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
-public class SimpleJobExecutorTest {
+public final class SimpleJobExecutorTest {
@Mock
private FooSimpleJob fooSimpleJob;
@@ -52,13 +53,13 @@ public class SimpleJobExecutorTest {
}
@Test
- public void testProcess() {
+ public void assertProcess() {
jobExecutor.process(fooSimpleJob, jobConfig, jobFacade, any());
verify(fooSimpleJob, times(1)).execute(any());
}
@Test
- public void testGetElasticJobClass() {
- assertEquals(jobExecutor.getElasticJobClass(), SimpleJob.class);
+ public void assertGetElasticJobClass() {
+ assertThat(jobExecutor.getElasticJobClass(), is(SimpleJob.class));
}
}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
index 30b04ec..c75a8d8 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
@@ -35,9 +35,10 @@ import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@SpringBootTest
@@ -51,35 +52,35 @@ public class ElasticJobSpringBootTest extends AbstractJUnit4SpringContextTests {
}
@Test
- public void testZookeeperProperties() {
+ public void assertZookeeperProperties() {
assertNotNull(applicationContext);
- ZookeeperProperties zookeeperProperties = applicationContext.getBean(ZookeeperProperties.class);
- assertEquals(EmbedTestingServer.getConnectionString(), zookeeperProperties.getServerLists());
- assertEquals("elasticjob-lite-spring-boot-starter", zookeeperProperties.getNamespace());
+ ZookeeperProperties actual = applicationContext.getBean(ZookeeperProperties.class);
+ assertThat(actual.getServerLists(), is(EmbedTestingServer.getConnectionString()));
+ assertThat(actual.getNamespace(), is("elasticjob-lite-spring-boot-starter"));
}
@Test
- public void testRegistryCenterCreation() {
+ public void assertRegistryCenterCreation() {
assertNotNull(applicationContext);
ZookeeperRegistryCenter zookeeperRegistryCenter = applicationContext.getBean(ZookeeperRegistryCenter.class);
assertNotNull(zookeeperRegistryCenter);
zookeeperRegistryCenter.persist("/foo", "bar");
- assertEquals("bar", zookeeperRegistryCenter.get("/foo"));
+ assertThat(zookeeperRegistryCenter.get("/foo"), is("bar"));
}
@Test
- public void testTracingConfigurationCreation() throws SQLException {
+ public void assertTracingConfigurationCreation() throws SQLException {
assertNotNull(applicationContext);
TracingConfiguration tracingConfiguration = applicationContext.getBean(TracingConfiguration.class);
assertNotNull(tracingConfiguration);
- assertEquals("RDB", tracingConfiguration.getType());
+ assertThat(tracingConfiguration.getType(), is("RDB"));
assertTrue(tracingConfiguration.getStorage() instanceof DataSource);
DataSource dataSource = (DataSource) tracingConfiguration.getStorage();
assertNotNull(dataSource.getConnection());
}
@Test
- public void testJobScheduleCreation() {
+ public void assertJobScheduleCreation() {
assertNotNull(applicationContext);
Map<String, ElasticJob> elasticJobBeans = applicationContext.getBeansOfType(ElasticJob.class);
assertFalse(elasticJobBeans.isEmpty());