You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/05/03 06:54:55 UTC
[shardingsphere] branch master updated: Refactor UserYamlSwapperTest (#17287)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 1ac586a4e4f Refactor UserYamlSwapperTest (#17287)
1ac586a4e4f is described below
commit 1ac586a4e4fc0e8512adb20e06bc45d1cfdabd6f
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue May 3 14:54:47 2022 +0800
Refactor UserYamlSwapperTest (#17287)
* Refactor UserYamlSwapperTest
* Refactor UserYamlSwapperTest
* Refactor UserYamlSwapperTest
---
.../user/yaml/swapper/UserYamlSwapperTest.java | 46 +++++++++++-----------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java
index 59c74cb8c1a..dda9b81eab3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java
@@ -21,40 +21,42 @@ import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
import org.junit.Test;
-import java.util.Objects;
-
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class UserYamlSwapperTest {
@Test
- public void assertSwapToYaml() {
- ShardingSphereUser shardingSphereUser = new ShardingSphereUser("user1", "pwd1", "127.0.0.1");
- YamlUserConfiguration yamlUser = new UserYamlSwapper().swapToYamlConfiguration(shardingSphereUser);
- assertThat(yamlUser.getPassword(), is("pwd1"));
- assertThat(yamlUser.getHostname(), is("127.0.0.1"));
- assertThat(yamlUser.getUsername(), is("user1"));
+ public void assertSwapToYamlConfiguration() {
+ YamlUserConfiguration actual = new UserYamlSwapper().swapToYamlConfiguration(new ShardingSphereUser("foo_user", "foo_pwd", "127.0.0.1"));
+ assertNotNull(actual);
+ assertThat(actual.getUsername(), is("foo_user"));
+ assertThat(actual.getPassword(), is("foo_pwd"));
+ assertThat(actual.getHostname(), is("127.0.0.1"));
+ }
+
+ @Test
+ public void assertSwapToNullYamlConfiguration() {
+ assertNull(new UserYamlSwapper().swapToYamlConfiguration(null));
}
@Test
public void assertSwapToObject() {
- YamlUserConfiguration user1 = new YamlUserConfiguration();
- user1.setUsername("user1");
- user1.setPassword("pwd1");
- user1.setHostname("127.0.0.1");
- ShardingSphereUser actualUser = new UserYamlSwapper().swapToObject(user1);
- assertThat(actualUser.getPassword(), is("pwd1"));
- assertThat(actualUser.getGrantee().getHostname(), is("127.0.0.1"));
- assertThat(actualUser.getGrantee().getUsername(), is("user1"));
+ YamlUserConfiguration user = new YamlUserConfiguration();
+ user.setUsername("foo_user");
+ user.setPassword("foo_pwd");
+ user.setHostname("127.0.0.1");
+ ShardingSphereUser actual = new UserYamlSwapper().swapToObject(user);
+ assertNotNull(actual);
+ assertThat(actual.getGrantee().getUsername(), is("foo_user"));
+ assertThat(actual.getPassword(), is("foo_pwd"));
+ assertThat(actual.getGrantee().getHostname(), is("127.0.0.1"));
}
@Test
- public void assertSwapToObjectForNull() {
- ShardingSphereUser actual = new UserYamlSwapper().swapToObject(null);
- assertTrue(Objects.isNull(actual));
- YamlUserConfiguration actualYamlUser = new UserYamlSwapper().swapToYamlConfiguration(null);
- assertTrue(Objects.isNull(actualYamlUser));
+ public void assertSwapToNullObject() {
+ assertNull(new UserYamlSwapper().swapToObject(null));
}
}