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.git
The following commit(s) were added to refs/heads/master by this push:
new 969c8d82998 Refactor test cases for mask-core module (#30586)
969c8d82998 is described below
commit 969c8d82998a4f5c0d4bf8f1c80eb5cc72df1c0a
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Mar 21 17:58:02 2024 +0800
Refactor test cases for mask-core module (#30586)
* Refactor ReadwriteSplittingRuleConfiguration
* Add test cases for MaskRuleConfiguration
* Add test cases for MaskRuleConfiguration
* Refactor test cases for mask-core module
* Refactor test cases for mask-core module
* Refactor test cases for mask-core module
* Refactor test cases for mask-core module
* Refactor test cases for mask-core module
---
.../algorithm/MaskAlgorithmPropertiesChecker.java | 8 +--
.../MaskAlgorithmPropertiesCheckerTest.java | 80 +++++++++-------------
.../cover/KeepFirstNLastMMaskAlgorithmTest.java | 30 +++++---
.../cover/KeepFromXToYMaskAlgorithmTest.java | 42 +++++++-----
.../cover/MaskAfterSpecialCharsAlgorithmTest.java | 28 +++++---
.../cover/MaskBeforeSpecialCharsAlgorithmTest.java | 22 ++++--
.../cover/MaskFirstNLastMMaskAlgorithmTest.java | 30 +++++---
.../cover/MaskFromXToYMaskAlgorithmTest.java | 42 +++++++-----
.../mask/algorithm/hash/MD5MaskAlgorithmTest.java | 14 ++--
.../GenericTableRandomReplaceAlgorithmTest.java | 19 ++---
10 files changed, 179 insertions(+), 136 deletions(-)
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
index db035b4440a..75c066d6c5c 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
@@ -39,7 +39,7 @@ public final class MaskAlgorithmPropertiesChecker {
* @param algorithm mask algorithm
*/
public static void checkSingleChar(final Properties props, final String
propKey, final MaskAlgorithm<?, ?> algorithm) {
- checkRequiredProperty(props, propKey, algorithm);
+ checkRequired(props, propKey, algorithm);
ShardingSpherePreconditions.checkState(1 ==
props.getProperty(propKey).length(), () -> new
AlgorithmInitializationException(algorithm, "%s's length must be one",
propKey));
}
@@ -51,7 +51,7 @@ public final class MaskAlgorithmPropertiesChecker {
* @param algorithm mask algorithm
*/
public static void checkAtLeastOneChar(final Properties props, final
String propKey, final MaskAlgorithm<?, ?> algorithm) {
- checkRequiredProperty(props, propKey, algorithm);
+ checkRequired(props, propKey, algorithm);
ShardingSpherePreconditions.checkState(props.getProperty(propKey).length() > 0,
() -> new AlgorithmInitializationException(algorithm, "%s's length must be at
least one", propKey));
}
@@ -64,7 +64,7 @@ public final class MaskAlgorithmPropertiesChecker {
* @throws AlgorithmInitializationException algorithm initialization
exception
*/
public static void checkPositiveInteger(final Properties props, final
String propKey, final MaskAlgorithm<?, ?> algorithm) {
- checkRequiredProperty(props, propKey, algorithm);
+ checkRequired(props, propKey, algorithm);
try {
int integerValue = Integer.parseInt(props.getProperty(propKey));
ShardingSpherePreconditions.checkState(integerValue > 0, () -> new
AlgorithmInitializationException(algorithm, "%s must be a positive integer.",
propKey));
@@ -73,7 +73,7 @@ public final class MaskAlgorithmPropertiesChecker {
}
}
- private static void checkRequiredProperty(final Properties props, final
String requiredPropKey, final MaskAlgorithm<?, ?> algorithm) {
+ private static void checkRequired(final Properties props, final String
requiredPropKey, final MaskAlgorithm<?, ?> algorithm) {
ShardingSpherePreconditions.checkState(props.containsKey(requiredPropKey), ()
-> new AlgorithmInitializationException(algorithm, "%s is required",
requiredPropKey));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesCheckerTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesCheckerTest.java
index 63b79f1bc0d..e2906f90589 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesCheckerTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesCheckerTest.java
@@ -23,85 +23,71 @@ import
org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
class MaskAlgorithmPropertiesCheckerTest {
@Test
- void assertCheckSingleCharConfigWithLengthOne() {
-
MaskAlgorithmPropertiesChecker.checkSingleChar(PropertiesBuilder.build(new
Property("singleChar", "1")), "singleChar", mock(MaskAlgorithm.class));
- }
-
- @Test
- void assertCheckSingleCharConfigWithEmptyString() {
- assertThrows(AlgorithmInitializationException.class,
- () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(PropertiesBuilder.build(new
Property("singleChar", "")), "singleChar1", mock(MaskAlgorithm.class)));
- }
-
- @Test
- void assertCheckSingleCharConfigWithDifferentKey() {
- assertThrows(AlgorithmInitializationException.class,
- () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(PropertiesBuilder.build(new
Property("singleChar", "1")), "singleChar1", mock(MaskAlgorithm.class)));
- }
-
- @Test
- void assertCheckSingleCharConfigWithLengthMoreThanOne() {
- assertThrows(AlgorithmInitializationException.class,
- () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(PropertiesBuilder.build(new
Property("singleChar", "123")), "singleChar", mock(MaskAlgorithm.class)));
- }
-
- @Test
- void assertCheckSingleCharConfigWithNull() {
- assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(PropertiesBuilder.build(),
"singleChar", mock(MaskAlgorithm.class)));
+ void assertCheckSingleCharSuccess() {
+ Properties props = PropertiesBuilder.build(new Property("key", "1"));
+ assertDoesNotThrow(() ->
MaskAlgorithmPropertiesChecker.checkSingleChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckAtLeastOneCharConfigWithLengthOne() {
-
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(PropertiesBuilder.build(new
Property("AtLeastOneChar", "1")), "AtLeastOneChar", mock(MaskAlgorithm.class));
+ void assertCheckSingleCharFailedWithoutKey() {
+ Properties props = new Properties();
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckAtLeastOneCharConfigWithLengthMoreThanOne() {
-
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(PropertiesBuilder.build(new
Property("AtLeastOneChar", "1234")), "AtLeastOneChar",
mock(MaskAlgorithm.class));
+ void assertCheckSingleCharFailedWithMultipleChars() {
+ Properties props = PropertiesBuilder.build(new Property("key", "111"));
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkSingleChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckAtLeastOneCharConfigWithEmptyString() {
- assertThrows(AlgorithmInitializationException.class,
- () ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(PropertiesBuilder.build(new
Property("AtLeastOneChar", "")), "AtLeastOneChar", mock(MaskAlgorithm.class)));
+ void assertCheckAtLeastOneCharSuccess() {
+ Properties props = PropertiesBuilder.build(new Property("key", "1"));
+ assertDoesNotThrow(() ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckAtLeastOneCharConfigWithNull() {
- assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(PropertiesBuilder.build(),
"AtLeastOneChar", mock(MaskAlgorithm.class)));
+ void assertCheckAtLeastOneCharFailedWithoutKey() {
+ Properties props = new Properties();
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckAtLeastOneCharConfigWithDifferentKey() {
- assertThrows(AlgorithmInitializationException.class,
- () ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(PropertiesBuilder.build(new
Property("singleChar", "123")), "AtLeastOneChar", mock(MaskAlgorithm.class)));
+ void assertCheckAtLeastOneCharFailedWithEmptyChar() {
+ Properties props = PropertiesBuilder.build(new Property("key", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkAtLeastOneChar(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckIntegerTypeConfigWithInteger() {
-
MaskAlgorithmPropertiesChecker.checkPositiveInteger(PropertiesBuilder.build(new
Property("integerTypeConfigKey", "123")), "integerTypeConfigKey",
mock(MaskAlgorithm.class));
+ void assertCheckPositiveIntegerSuccess() {
+ Properties props = PropertiesBuilder.build(new Property("key", "123"));
+ MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key",
mock(MaskAlgorithm.class));
}
@Test
- void assertCheckIntegerTypeConfigWithDifferentKey() {
- assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(
- PropertiesBuilder.build(new Property("integerTypeConfigKey",
"123")), "integerTypeConfigKey1", mock(MaskAlgorithm.class)));
+ void assertCheckPositiveIntegerFailedWithoutKey() {
+ Properties props = new Properties();
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckIntegerTypeConfigWithNotInteger() {
- assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(
- PropertiesBuilder.build(new Property("integerTypeConfigKey",
"123abc")), "integerTypeConfigKey", mock(MaskAlgorithm.class)));
+ void assertCheckPositiveIntegerFailedWithZero() {
+ Properties props = PropertiesBuilder.build(new Property("key", "0"));
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key",
mock(MaskAlgorithm.class)));
}
@Test
- void assertCheckIntegerTypeConfigWithNull() {
- assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(PropertiesBuilder.build(),
"integerTypeConfigKey", mock(MaskAlgorithm.class)));
+ void assertCheckPositiveIntegerFailedWithNotInteger() {
+ Properties props = PropertiesBuilder.build(new Property("key",
"123.0"));
+ assertThrows(AlgorithmInitializationException.class, () ->
MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key",
mock(MaskAlgorithm.class)));
}
}
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 7362486d137..33a58a61704 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
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class KeepFirstNLastMMaskAlgorithmTest {
@@ -35,10 +40,15 @@ class KeepFirstNLastMMaskAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new Property("first-n",
"3"), new Property("last-m", "5"), new Property("replace-char", "*")));
- sameFirstNLastMMaskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
- sameFirstNLastMMaskAlgorithm.init(PropertiesBuilder.build(new
Property("first-n", "5"), new Property("last-m", "5"), new
Property("replace-char", "*")));
+ maskAlgorithm = (KeepFirstNLastMMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FIRST_N_LAST_M",
+ PropertiesBuilder.build(new Property("first-n", "3"), new
Property("last-m", "5"), new Property("replace-char", "*")));
+ sameFirstNLastMMaskAlgorithm = (KeepFirstNLastMMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FIRST_N_LAST_M",
+ PropertiesBuilder.build(new Property("first-n", "5"), new
Property("last-m", "5"), new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -85,19 +95,19 @@ class KeepFirstNLastMMaskAlgorithmTest {
@Test
void assertInitWhenFirstNIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", ""), new Property("last-m", "5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
""), new Property("last-m", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FIRST_N_LAST_M", props));
}
@Test
void assertInitWhenLastMIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "2"), new Property("last-m", ""), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
"2"), new Property("last-m", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FIRST_N_LAST_M", props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "2"), new Property("last-m", "5"), new
Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
"2"), new Property("last-m", "5"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FIRST_N_LAST_M", props));
}
}
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 fc6fe69ac8f..3d29a4d8668 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
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class KeepFromXToYMaskAlgorithmTest {
@@ -35,10 +40,15 @@ class KeepFromXToYMaskAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new KeepFromXToYMaskAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "5"), new Property("replace-char", "*")));
- sameFromXToYMaskAlgorithm = new KeepFromXToYMaskAlgorithm();
- sameFromXToYMaskAlgorithm.init(PropertiesBuilder.build(new
Property("from-x", "5"), new Property("to-y", "5"), new
Property("replace-char", "*")));
+ maskAlgorithm = (KeepFromXToYMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y",
+ PropertiesBuilder.build(new Property("from-x", "3"), new
Property("to-y", "5"), new Property("replace-char", "*")));
+ sameFromXToYMaskAlgorithm = (KeepFromXToYMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y",
+ PropertiesBuilder.build(new Property("from-x", "5"), new
Property("to-y", "5"), new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -73,37 +83,37 @@ class KeepFromXToYMaskAlgorithmTest {
@Test
void assertInitWhenFromXIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char",
"*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x", ""),
new Property("to-y", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenToYIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "2"), new Property("to-y", ""), new Property("replace-char",
"*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"2"), new Property("to-y", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "2"), new Property("to-y", "5"), new
Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"2"), new Property("to-y", "5"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenFromXIsNotPositive() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "-3"), new Property("to-y", "5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"-3"), new Property("to-y", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenToYIsNotPositive() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "3"), new Property("to-y", "-5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "-5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenFromXGreaterThanToY() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "5"), new Property("to-y", "2"), new
Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"5"), new Property("to-y", "2"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "KEEP_FROM_X_TO_Y", props));
}
}
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 f57468b3284..c522379b166 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
@@ -18,15 +18,20 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
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.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MaskAfterSpecialCharsAlgorithmTest {
@@ -35,8 +40,13 @@ class MaskAfterSpecialCharsAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new MaskAfterSpecialCharsAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "*")));
+ maskAlgorithm = (MaskAfterSpecialCharsAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_AFTER_SPECIAL_CHARS",
+ PropertiesBuilder.build(new Property("special-chars", "d1"),
new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -66,24 +76,26 @@ class MaskAfterSpecialCharsAlgorithmTest {
@Test
void assertInitWhenSpecialCharsIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_AFTER_SPECIAL_CHARS",
props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_AFTER_SPECIAL_CHARS",
props));
}
@Test
void assertInitWhenReplaceCharIsMissing() {
- assertThrows(AlgorithmInitializationException.class, () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", "d1"))));
+ Properties props = PropertiesBuilder.build(new
Property("special-chars", "d1"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_AFTER_SPECIAL_CHARS",
props));
}
@Test
void assertInitWhenPropertiesAreEmpty() {
- assertThrows(AlgorithmInitializationException.class, () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build()));
+ Properties props = new Properties();
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_AFTER_SPECIAL_CHARS",
props));
}
@Test
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 f5212c827b5..0ef60c3ecc6 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
@@ -18,14 +18,19 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MaskBeforeSpecialCharsAlgorithmTest {
@@ -34,8 +39,13 @@ class MaskBeforeSpecialCharsAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new MaskBeforeSpecialCharsAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "*")));
+ maskAlgorithm = (MaskBeforeSpecialCharsAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_BEFORE_SPECIAL_CHARS",
+ PropertiesBuilder.build(new Property("special-chars", "d1"),
new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -65,13 +75,13 @@ class MaskBeforeSpecialCharsAlgorithmTest {
@Test
void assertInitWhenSpecialCharsIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_BEFORE_SPECIAL_CHARS",
props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_BEFORE_SPECIAL_CHARS",
props));
}
}
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 4f38f23add8..53bdac7f0f2 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
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MaskFirstNLastMMaskAlgorithmTest {
@@ -35,10 +40,15 @@ class MaskFirstNLastMMaskAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new MaskFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new Property("first-n",
"3"), new Property("last-m", "5"), new Property("replace-char", "*")));
- sameFirstNLastMMaskAlgorithm = new MaskFirstNLastMMaskAlgorithm();
- sameFirstNLastMMaskAlgorithm.init(PropertiesBuilder.build(new
Property("first-n", "5"), new Property("last-m", "5"), new
Property("replace-char", "*")));
+ maskAlgorithm = (MaskFirstNLastMMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FIRST_N_LAST_M",
+ PropertiesBuilder.build(new Property("first-n", "3"), new
Property("last-m", "5"), new Property("replace-char", "*")));
+ sameFirstNLastMMaskAlgorithm = (MaskFirstNLastMMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FIRST_N_LAST_M",
+ PropertiesBuilder.build(new Property("first-n", "5"), new
Property("last-m", "5"), new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -85,19 +95,19 @@ class MaskFirstNLastMMaskAlgorithmTest {
@Test
void assertInitWhenFirstNIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", ""), new Property("last-m", "5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
""), new Property("last-m", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FIRST_N_LAST_M", props));
}
@Test
void assertInitWhenLastMIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "3"), new Property("last-m", ""), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
"3"), new Property("last-m", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FIRST_N_LAST_M", props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "3"), new Property("last-m", "5"), new
Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("first-n",
"3"), new Property("last-m", "5"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FIRST_N_LAST_M", props));
}
}
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 ad4785d34ec..e43d5f3b66f 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
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MaskFromXToYMaskAlgorithmTest {
@@ -35,10 +40,15 @@ class MaskFromXToYMaskAlgorithmTest {
@BeforeEach
void setUp() {
- maskAlgorithm = new MaskFromXToYMaskAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "5"), new Property("replace-char", "*")));
- sameFromXToYMaskAlgorithm = new MaskFromXToYMaskAlgorithm();
- sameFromXToYMaskAlgorithm.init(PropertiesBuilder.build(new
Property("from-x", "5"), new Property("to-y", "5"), new
Property("replace-char", "*")));
+ maskAlgorithm = (MaskFromXToYMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y",
+ PropertiesBuilder.build(new Property("from-x", "3"), new
Property("to-y", "5"), new Property("replace-char", "*")));
+ sameFromXToYMaskAlgorithm = (MaskFromXToYMaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y",
+ PropertiesBuilder.build(new Property("from-x", "5"), new
Property("to-y", "5"), new Property("replace-char", "*")));
+ }
+
+ @Test
+ void assertMaskWithNullValue() {
+ assertNull(maskAlgorithm.mask(null));
}
@Test
@@ -73,37 +83,37 @@ class MaskFromXToYMaskAlgorithmTest {
@Test
void assertInitWhenFromXIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x",
""), new Property("to-y", "5"), new Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x", ""),
new Property("to-y", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenToYIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", ""), new Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", ""), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenReplaceCharIsEmpty() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "5"), new Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "5"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenFromXIsNotPositive() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "-3"), new Property("to-y", "5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"-3"), new Property("to-y", "5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenToYIsNotPositive() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "3"), new Property("to-y", "-5"), new
Property("replace-char", "*"))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "-5"), new Property("replace-char", "*"));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
@Test
void assertInitWhenFromXGreaterThanToY() {
- assertThrows(AlgorithmInitializationException.class,
- () -> new
KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "5"), new Property("to-y", "2"), new
Property("replace-char", ""))));
+ Properties props = PropertiesBuilder.build(new Property("from-x",
"5"), new Property("to-y", "2"), new Property("replace-char", ""));
+ assertThrows(AlgorithmInitializationException.class, () ->
TypedSPILoader.getService(MaskAlgorithm.class, "MASK_FROM_X_TO_Y", props));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
index 276457f5c6e..f8fcd50df6a 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.mask.algorithm.hash;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
@@ -29,22 +31,20 @@ class MD5MaskAlgorithmTest {
@Test
void assertMask() {
- assertThat(createMaskAlgorithm("").mask("abc123456"),
is("0659c7992e268962384eb17fafe88364"));
+ assertThat(createAlgorithm("").mask("abc123456"),
is("0659c7992e268962384eb17fafe88364"));
}
@Test
void assertMaskWhenPlainValueIsNull() {
- assertNull(createMaskAlgorithm("").mask(null));
+ assertNull(createAlgorithm("").mask(null));
}
@Test
void assertMaskWhenConfigSalt() {
- assertThat(createMaskAlgorithm("202cb962ac5907").mask("abc123456"),
is("02d44390e9354b72dd2aa78d55016f7f"));
+ assertThat(createAlgorithm("202cb962ac5907").mask("abc123456"),
is("02d44390e9354b72dd2aa78d55016f7f"));
}
- private MD5MaskAlgorithm createMaskAlgorithm(final String salt) {
- MD5MaskAlgorithm result = new MD5MaskAlgorithm();
- result.init(PropertiesBuilder.build(new Property("salt", salt)));
- return result;
+ private MD5MaskAlgorithm createAlgorithm(final String salt) {
+ return (MD5MaskAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "MD5",
PropertiesBuilder.build(new Property("salt", salt)));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithmTest.java
index e7bba0361b4..e8341b3f310 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithmTest.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.mask.algorithm.replace;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.hamcrest.CoreMatchers;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
@@ -33,17 +34,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
class GenericTableRandomReplaceAlgorithmTest {
- private GenericTableRandomReplaceAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- this.maskAlgorithm = new GenericTableRandomReplaceAlgorithm();
- }
-
@Test
void assertMask() {
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("uppercase-letter-codes", "A,B,C,D"), new
Property("lowercase-letter-codes", "a,b,c,d"), new Property("digital-codes",
"1,2,3,4"),
- new Property("special-codes", "~!@#")));
+ GenericTableRandomReplaceAlgorithm maskAlgorithm =
(GenericTableRandomReplaceAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "GENERIC_TABLE_RANDOM_REPLACE",
+ PropertiesBuilder.build(new Property("uppercase-letter-codes",
"A,B,C,D"),
+ new Property("lowercase-letter-codes", "a,b,c,d"), new
Property("digital-codes", "1,2,3,4"), new Property("special-codes", "~!@#")));
assertThat(maskAlgorithm.mask(""), is(""));
assertThat(maskAlgorithm.mask("Ab1!").charAt(0), anyOf(is('A'),
is('B'), is('C'), is('D')));
assertThat(maskAlgorithm.mask("Ab1!").charAt(1), anyOf(is('a'),
is('b'), is('c'), is('d')));
@@ -52,8 +47,8 @@ class GenericTableRandomReplaceAlgorithmTest {
}
@Test
- void assertInitWithEmptyProps() {
- maskAlgorithm.init(new Properties());
+ void assertMaskWithEmptyProps() {
+ GenericTableRandomReplaceAlgorithm maskAlgorithm =
(GenericTableRandomReplaceAlgorithm)
TypedSPILoader.getService(MaskAlgorithm.class, "GENERIC_TABLE_RANDOM_REPLACE",
new Properties());
assertThat(maskAlgorithm.mask("Ab1!").substring(0, 1),
anyOf(Arrays.stream("ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")).map(CoreMatchers::is).collect(Collectors.toList())));
assertThat(maskAlgorithm.mask("Ab1!").substring(1, 2),
anyOf(Arrays.stream("abcdefghijklmnopqrstuvwxyz".split("")).map(CoreMatchers::is).collect(Collectors.toList())));
assertThat(maskAlgorithm.mask("Ab1!").substring(2, 3),
anyOf(Arrays.stream("0123456789".split("")).map(CoreMatchers::is).collect(Collectors.toList())));