You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/03/04 05:57:04 UTC

[shardingsphere] branch master updated: Refactor @Test(expected) to assert assertThrows on mask modules (#24455)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 1da67012a0d Refactor @Test(expected) to assert assertThrows on mask modules (#24455)
1da67012a0d is described below

commit 1da67012a0d29b2b9fd2b757ae86ae843a1a54ad
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Mar 4 13:56:51 2023 +0800

    Refactor @Test(expected) to assert assertThrows on mask modules (#24455)
---
 .../algorithm/MaskAlgorithmPropsCheckerTest.java   | 71 ++++++++++------------
 .../cover/KeepFirstNLastMMaskAlgorithmTest.java    | 16 +++--
 .../cover/KeepFromXToYMaskAlgorithmTest.java       | 16 +++--
 .../cover/MaskAfterSpecialCharsAlgorithmTest.java  | 11 ++--
 .../cover/MaskBeforeSpecialCharsAlgorithmTest.java | 11 ++--
 .../cover/MaskFirstNLastMMaskAlgorithmTest.java    | 16 +++--
 .../cover/MaskFromXToYMaskAlgorithmTest.java       | 16 +++--
 .../TelephoneRandomReplaceAlgorithmTest.java       |  5 +-
 ...nifiedCreditCodeRandomReplaceAlgorithmTest.java | 11 ++--
 .../update/AlterMaskRuleStatementUpdaterTest.java  | 18 +++---
 .../update/CreateMaskRuleStatementUpdaterTest.java |  9 +--
 .../update/DropMaskRuleStatementUpdaterTest.java   | 10 +--
 12 files changed, 116 insertions(+), 94 deletions(-)

diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsCheckerTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsCheckerTest.java
index 9a119afd431..327f6d09d89 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsCheckerTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsCheckerTest.java
@@ -22,91 +22,84 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Test;
 
-import java.util.Properties;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public final class MaskAlgorithmPropsCheckerTest {
     
     @Test
     public void assertCheckSingleCharConfigWithLengthOne() {
-        Properties props = PropertiesBuilder.build(new Property("singleChar", "1"));
-        MaskAlgorithmPropsChecker.checkSingleCharConfig(props, "singleChar", "maskType");
+        MaskAlgorithmPropsChecker.checkSingleCharConfig(PropertiesBuilder.build(new Property("singleChar", "1")), "singleChar", "maskType");
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckSingleCharConfigWithEmptyString() {
-        Properties props = PropertiesBuilder.build(new Property("singleChar", ""));
-        MaskAlgorithmPropsChecker.checkSingleCharConfig(props, "singleChar1", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkSingleCharConfig(PropertiesBuilder.build(new Property("singleChar", "")), "singleChar1", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckSingleCharConfigWithDifferentKey() {
-        Properties props = PropertiesBuilder.build(new Property("singleChar", "1"));
-        MaskAlgorithmPropsChecker.checkSingleCharConfig(props, "singleChar1", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkSingleCharConfig(PropertiesBuilder.build(new Property("singleChar", "1")), "singleChar1", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckSingleCharConfigWithLengthMoreThanOne() {
-        Properties props = PropertiesBuilder.build(new Property("singleChar", "123"));
-        MaskAlgorithmPropsChecker.checkSingleCharConfig(props, "singleChar", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkSingleCharConfig(PropertiesBuilder.build(new Property("singleChar", "123")), "singleChar", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckSingleCharConfigWithNull() {
-        Properties props = PropertiesBuilder.build();
-        MaskAlgorithmPropsChecker.checkSingleCharConfig(props, "singleChar", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class, () -> MaskAlgorithmPropsChecker.checkSingleCharConfig(PropertiesBuilder.build(), "singleChar", "maskType"));
     }
     
     @Test
     public void assertCheckAtLeastOneCharConfigWithLengthOne() {
-        Properties props = PropertiesBuilder.build(new Property("AtLeastOneChar", "1"));
-        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, "AtLeastOneChar", "maskType");
+        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(PropertiesBuilder.build(new Property("AtLeastOneChar", "1")), "AtLeastOneChar", "maskType");
     }
     
     @Test
     public void assertCheckAtLeastOneCharConfigWithLengthMoreThanOne() {
-        Properties props = PropertiesBuilder.build(new Property("AtLeastOneChar", "1234"));
-        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, "AtLeastOneChar", "maskType");
+        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(PropertiesBuilder.build(new Property("AtLeastOneChar", "1234")), "AtLeastOneChar", "maskType");
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckAtLeastOneCharConfigWithEmptyString() {
-        Properties props = PropertiesBuilder.build(new Property("AtLeastOneChar", ""));
-        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, "AtLeastOneChar", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(PropertiesBuilder.build(new Property("AtLeastOneChar", "")), "AtLeastOneChar", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckAtLeastOneCharConfigWithNull() {
-        Properties props = PropertiesBuilder.build();
-        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, "AtLeastOneChar", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class, () -> MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(PropertiesBuilder.build(), "AtLeastOneChar", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckAtLeastOneCharConfigWithDifferentKey() {
-        Properties props = PropertiesBuilder.build(new Property("singleChar", "123"));
-        MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, "AtLeastOneChar", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(PropertiesBuilder.build(new Property("singleChar", "123")), "AtLeastOneChar", "maskType"));
     }
     
     @Test
     public void assertCheckIntegerTypeConfigWithInteger() {
-        Properties props = PropertiesBuilder.build(new Property("integerTypeConfigKey", "123"));
-        MaskAlgorithmPropsChecker.checkIntegerTypeConfig(props, "integerTypeConfigKey", "maskType");
+        MaskAlgorithmPropsChecker.checkIntegerTypeConfig(PropertiesBuilder.build(new Property("integerTypeConfigKey", "123")), "integerTypeConfigKey", "maskType");
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckIntegerTypeConfigWithDifferentKey() {
-        Properties props = PropertiesBuilder.build(new Property("integerTypeConfigKey", "123"));
-        MaskAlgorithmPropsChecker.checkIntegerTypeConfig(props, "integerTypeConfigKey1", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkIntegerTypeConfig(PropertiesBuilder.build(new Property("integerTypeConfigKey", "123")), "integerTypeConfigKey1", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckIntegerTypeConfigWithNotInteger() {
-        Properties props = PropertiesBuilder.build(new Property("integerTypeConfigKey", "123abc"));
-        MaskAlgorithmPropsChecker.checkIntegerTypeConfig(props, "integerTypeConfigKey", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> MaskAlgorithmPropsChecker.checkIntegerTypeConfig(PropertiesBuilder.build(new Property("integerTypeConfigKey", "123abc")), "integerTypeConfigKey", "maskType"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertCheckIntegerTypeConfigWithNull() {
-        Properties props = PropertiesBuilder.build();
-        MaskAlgorithmPropsChecker.checkIntegerTypeConfig(props, "integerTypeConfigKey", "maskType");
+        assertThrows(MaskAlgorithmInitializationException.class, () -> MaskAlgorithmPropsChecker.checkIntegerTypeConfig(PropertiesBuilder.build(), "integerTypeConfigKey", "maskType"));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
index 6c2f257c9fd..e441311f664 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public final class KeepFirstNLastMMaskAlgorithmTest {
     
@@ -46,18 +47,21 @@ public final class KeepFirstNLastMMaskAlgorithmTest {
         assertThat(maskAlgorithm.mask("abc"), is("abc"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenFirstNIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", ""), new Property("last-m", "5"), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", ""), new Property("last-m", "5"), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenLastMIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "2"), new Property("last-m", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "2"), new Property("last-m", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "2"), new Property("last-m", "5"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "2"), new Property("last-m", "5"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
index f32d4be7100..205a3d17b28 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 public final class KeepFromXToYMaskAlgorithmTest {
     
@@ -51,18 +52,21 @@ public final class KeepFromXToYMaskAlgorithmTest {
         assertThat(maskAlgorithm.mask("a"), is("a"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenFromXIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenToYIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "2"), new Property("to-y", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "2"), new Property("to-y", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "2"), new Property("to-y", "5"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "2"), new Property("to-y", "5"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
index 8e749ce0dc4..70bf4adf78b 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 public final class MaskAfterSpecialCharsAlgorithmTest {
     
@@ -62,13 +63,15 @@ public final class MaskAfterSpecialCharsAlgorithmTest {
         assertThat(maskAlgorithm.mask("abcd234"), is("abcd234"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenSpecialCharsIsEmpty() {
-        new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", "d1"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", "d1"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
index 64dcd685aff..73e74b55c29 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public final class MaskBeforeSpecialCharsAlgorithmTest {
     
@@ -62,13 +63,15 @@ public final class MaskBeforeSpecialCharsAlgorithmTest {
         assertThat(maskAlgorithm.mask("abcd234"), is("abcd234"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenSpecialCharsIsEmpty() {
-        new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", "d1"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new Property("special-chars", "d1"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
index eeb6da1e093..8f5d8439d79 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public final class MaskFirstNLastMMaskAlgorithmTest {
     
@@ -46,18 +47,21 @@ public final class MaskFirstNLastMMaskAlgorithmTest {
         assertThat(maskAlgorithm.mask("ab"), is("**"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenFirstNIsEmpty() {
-        new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", ""), new Property("last-m", "5"), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", ""), new Property("last-m", "5"), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenLastMIsEmpty() {
-        new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "3"), new Property("last-m", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "3"), new Property("last-m", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "3"), new Property("last-m", "5"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new Property("first-n", "3"), new Property("last-m", "5"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
index e103a972b28..116eaafcbca 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 public final class MaskFromXToYMaskAlgorithmTest {
     
@@ -51,18 +52,21 @@ public final class MaskFromXToYMaskAlgorithmTest {
         assertThat(maskAlgorithm.mask("abc1"), is("abc*"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenFromXIsEmpty() {
-        new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenToYIsEmpty() {
-        new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "3"), new Property("to-y", ""), new Property("replace-char", "*")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "3"), new Property("to-y", ""), new Property("replace-char", "*"))));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenReplaceCharIsEmpty() {
-        new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "3"), new Property("to-y", "5"), new Property("replace-char", "")));
+        assertThrows(MaskAlgorithmInitializationException.class,
+                () -> new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x", "3"), new Property("to-y", "5"), new Property("replace-char", ""))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
index 3114954d409..75d2babba7b 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
@@ -33,6 +33,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public final class TelephoneRandomReplaceAlgorithmTest {
@@ -67,8 +68,8 @@ public final class TelephoneRandomReplaceAlgorithmTest {
         assertThat(maskAlgorithm.mask("13012345678"), not("13012345678"));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenConfigNotNumberProps() {
-        maskAlgorithm.init(PropertiesBuilder.build(new Property("network-numbers", "130, x130, 155,1702")));
+        assertThrows(MaskAlgorithmInitializationException.class, () -> maskAlgorithm.init(PropertiesBuilder.build(new Property("network-numbers", "130, x130, 155,1702"))));
     }
 }
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
index 892278dc366..ccba1125956 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
@@ -20,18 +20,19 @@ package org.apache.shardingsphere.mask.algorithm.replace;
 import org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public final class UnifiedCreditCodeRandomReplaceAlgorithmTest {
     
     private UnifiedCreditCodeRandomReplaceAlgorithm maskAlgorithm;
     
-    @Before
+    @BeforeEach
     public void setUp() {
         maskAlgorithm = new UnifiedCreditCodeRandomReplaceAlgorithm();
     }
@@ -44,8 +45,8 @@ public final class UnifiedCreditCodeRandomReplaceAlgorithmTest {
         assertThat(maskAlgorithm.mask("123456781234567890").length(), is(18));
     }
     
-    @Test(expected = MaskAlgorithmInitializationException.class)
+    @Test
     public void assertInitWhenConfigIsNull() {
-        maskAlgorithm.init(PropertiesBuilder.build(new Property("registration-department-codes", "1,2,3,4")));
+        assertThrows(MaskAlgorithmInitializationException.class, () -> maskAlgorithm.init(PropertiesBuilder.build(new Property("registration-department-codes", "1,2,3,4"))));
     }
 }
diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleStatementUpdaterTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleStatementUpdaterTest.java
index 5cb05399bd3..8e32b97872a 100644
--- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleStatementUpdaterTest.java
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleStatementUpdaterTest.java
@@ -39,6 +39,7 @@ import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -49,27 +50,28 @@ public final class AlterMaskRuleStatementUpdaterTest {
     
     private final AlterMaskRuleStatementUpdater updater = new AlterMaskRuleStatementUpdater();
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithoutCurrentRule() {
-        updater.checkSQLStatement(database, createSQLStatement("MD5"), null);
+        assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement("MD5"), null));
     }
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithoutToBeAlteredRules() {
-        updater.checkSQLStatement(database, createSQLStatement("MD5"), new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap()));
+        assertThrows(MissingRequiredRuleException.class,
+                () -> updater.checkSQLStatement(database, createSQLStatement("MD5"), new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
     }
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithoutToBeAlteredAlgorithm() {
-        updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfig());
+        assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfig()));
     }
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithIncompleteDataType() {
         MaskColumnSegment columnSegment = new MaskColumnSegment("user_id", new AlgorithmSegment("test", new Properties()));
         MaskRuleSegment ruleSegment = new MaskRuleSegment("t_mask", Collections.singleton(columnSegment));
         AlterMaskRuleStatement statement = new AlterMaskRuleStatement(Collections.singleton(ruleSegment));
-        updater.checkSQLStatement(database, statement, createCurrentRuleConfig());
+        assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, statement, createCurrentRuleConfig()));
     }
     
     @Test
diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
index 87859dea2e5..b0259ab2411 100644
--- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
@@ -40,6 +40,7 @@ import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -50,14 +51,14 @@ public final class CreateMaskRuleStatementUpdaterTest {
     
     private final CreateMaskRuleStatementUpdater updater = new CreateMaskRuleStatementUpdater();
     
-    @Test(expected = DuplicateRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithDuplicateMaskRule() {
-        updater.checkSQLStatement(database, createDuplicatedSQLStatement(false, "MD5"), getCurrentRuleConfig());
+        assertThrows(DuplicateRuleException.class, () -> updater.checkSQLStatement(database, createDuplicatedSQLStatement(false, "MD5"), getCurrentRuleConfig()));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertCheckSQLStatementWithInvalidAlgorithm() {
-        updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"), null);
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"), null));
     }
     
     @Test
diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
index cda9fcb1cbf..1fc602e7b59 100644
--- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleStatementUpdaterTest.java
@@ -36,6 +36,7 @@ import java.util.LinkedList;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
@@ -47,14 +48,15 @@ public final class DropMaskRuleStatementUpdaterTest {
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private ShardingSphereDatabase database;
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithoutCurrentRule() {
-        updater.checkSQLStatement(database, createSQLStatement(false, "t_mask"), null);
+        assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement(false, "t_mask"), null));
     }
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertCheckSQLStatementWithoutToBeDroppedRule() {
-        updater.checkSQLStatement(database, createSQLStatement(false, "t_mask"), new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap()));
+        assertThrows(MissingRequiredRuleException.class,
+                () -> updater.checkSQLStatement(database, createSQLStatement(false, "t_mask"), new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
     }
     
     @Test