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 2022/04/09 03:12:27 UTC
[shardingsphere] branch master updated: Refactor H2 and File unit test. (#16662)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new eae7e4bf424 Refactor H2 and File unit test. (#16662)
eae7e4bf424 is described below
commit eae7e4bf42462740f57530c7a40f26360fc6f58c
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Apr 9 11:12:20 2022 +0800
Refactor H2 and File unit test. (#16662)
---
.../standalone/file/FileRepositoryTest.java | 36 +++++++++++++---------
.../repository/standalone/h2/H2RepositoryTest.java | 26 +++++++++-------
2 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/test/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepositoryTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provid [...]
index 9e8ad975b97..116e37b4144 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/test/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepositoryTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/test/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepositoryTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.mode.repository.standalone.file;
import com.google.common.base.Joiner;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import java.io.File;
@@ -29,35 +31,36 @@ import static org.junit.Assert.assertThat;
public final class FileRepositoryTest {
- private FileRepository fileRepository = new FileRepository();
+ private final FileRepository fileRepository = new FileRepository();
- @Test
- public void assertMethod() {
- assertThat(fileRepository.getType(), is("File"));
- assertSetProperty();
- assertPersistAndGet();
- assertPersistAndGetChildrenKeys();
- assertDelete();
- }
-
- private void assertSetProperty() {
+ @Before
+ public void setUp() {
Properties props = new Properties();
props.setProperty("path", "target");
fileRepository.setProps(props);
}
- private void assertPersistAndGet() {
+ @Test
+ public void assertType() {
+ assertThat(fileRepository.getType(), is("File"));
+ }
+
+ @Test
+ public void assertPersistAndGet() {
fileRepository.persist(getFilePath(), "test1_content");
assertThat(fileRepository.get(getFilePath()), is("test1_content"));
fileRepository.persist(getFilePath(), "modify_content");
assertThat(fileRepository.get(getFilePath()), is("modify_content"));
}
- private void assertPersistAndGetChildrenKeys() {
+ @Test
+ public void assertPersistAndGetChildrenKeys() {
+ fileRepository.persist(getFilePath(), "");
assertThat(fileRepository.getChildrenKeys("testDir").get(0), is("test1"));
}
- private void assertDelete() {
+ @Test
+ public void assertDelete() {
fileRepository.delete("testDir");
assertFalse((new File(getFilePath())).exists());
}
@@ -65,4 +68,9 @@ public final class FileRepositoryTest {
private String getFilePath() {
return Joiner.on(File.separator).join("testDir", "test1");
}
+
+ @After
+ public void stop() {
+ fileRepository.close();
+ }
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/sha [...]
index 36e0d44f146..5fc45c982bd 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2RepositoryTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.mode.repository.standalone.h2;
import org.apache.commons.lang3.StringUtils;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import java.util.List;
@@ -29,15 +31,10 @@ import static org.junit.Assert.assertTrue;
public final class H2RepositoryTest {
- private H2Repository h2Repository = new H2Repository();
+ private final H2Repository h2Repository = new H2Repository();
- @Test
- public void assertMethod() {
- assertThat(h2Repository.getType(), is("H2"));
- h2Repository.close();
- }
-
- private void assertSetProperty() {
+ @Before
+ public void setUp() {
Properties props = new Properties();
props.setProperty("jdbc_url", "jdbc:h2:~/h2_repository");
props.setProperty("user", "sa");
@@ -45,10 +42,14 @@ public final class H2RepositoryTest {
props.setProperty("driver_class", "org.h2.Driver");
h2Repository.setProps(props);
}
+
+ @Test
+ public void assertType() {
+ assertThat(h2Repository.getType(), is("H2"));
+ }
@Test
public void assertPersistAndGet() {
- assertSetProperty();
h2Repository.persist("/testPath/test1", "test1_content");
assertThat(h2Repository.get("/testPath/test1"), is("test1_content"));
h2Repository.persist("/testPath/test1", "modify_content");
@@ -57,7 +58,6 @@ public final class H2RepositoryTest {
@Test
public void assertPersistAndGetChildrenKeys() {
- assertSetProperty();
h2Repository.persist("/testPath/test1", "test1_content");
h2Repository.persist("/testPath/test2", "test2_content");
List<String> childrenKeys = h2Repository.getChildrenKeys("/testPath");
@@ -67,8 +67,12 @@ public final class H2RepositoryTest {
@Test
public void assertDelete() {
- assertSetProperty();
h2Repository.delete("/testPath");
assertTrue(StringUtils.isBlank(h2Repository.get("/testPath")));
}
+
+ @After
+ public void stop() {
+ h2Repository.close();
+ }
}