You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/12/12 05:56:01 UTC

[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #22808: Implement MASK_FIRST_N_LAST_M and MASK_FROM_X_TO_Y

strongduanmu commented on code in PR #22808:
URL: https://github.com/apache/shardingsphere/pull/22808#discussion_r1045426527


##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithm.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * MASK_FIRST_N_LAST_M.

Review Comment:
   Please modify java doc to `Mask first n last m mask algorithm`.



##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithm.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
+
+import java.util.Properties;
+
+/**

Review Comment:
   Please modify javadoc to `Mask from x to y mask algorithm`.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * MASK_FIRST_N_LAST_M.
+ */
+public final class MaskFirstNLastMMaskAlgorithmTest {
+    
+    private MaskFirstNLastMMaskAlgorithm algorithm;
+    
+    @Before
+    public void setUp() {
+        algorithm = new MaskFirstNLastMMaskAlgorithm();
+        algorithm.init(createProperties());
+    }
+    
+    private Properties createProperties() {
+        Properties props = new Properties();
+        props.setProperty("n", "3");
+        props.setProperty("m", "5");
+        props.setProperty("replace-char", "*");
+        return props;
+    }
+    
+    @Test
+    public void assertMask() {
+        assertThat(algorithm.mask("abc12345678"), is("***123*****"));
+    }
+    
+    @Test
+    public void assertMaskWithShortPlainValue() {
+        assertThat(algorithm.mask("ab"), is("**"));
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void assertMaskWithInvalidProperties() {
+        algorithm.init(createInvalidProperties());
+    }
+    
+    private Properties createInvalidProperties() {
+        Properties props = new Properties();
+        props.setProperty("m", "5");
+        props.setProperty("replace-char", "*");
+        return props;

Review Comment:
   Please use result instead of props.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**

Review Comment:
   Please remove javadoc in unit test.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * MASK_FIRST_N_LAST_M.
+ */
+public final class MaskFirstNLastMMaskAlgorithmTest {
+    
+    private MaskFirstNLastMMaskAlgorithm algorithm;
+    
+    @Before
+    public void setUp() {
+        algorithm = new MaskFirstNLastMMaskAlgorithm();
+        algorithm.init(createProperties());
+    }
+    
+    private Properties createProperties() {
+        Properties props = new Properties();
+        props.setProperty("n", "3");
+        props.setProperty("m", "5");
+        props.setProperty("replace-char", "*");
+        return props;

Review Comment:
   Please use result instead of props.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**

Review Comment:
   Please remove javadoc in unit test.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * MASK_FROM_X_TO_Y.
+ */
+public final class MaskFromXToYMaskAlgorithmTest {
+    
+    private MaskFromXToYMaskAlgorithm algorithm;
+    
+    @Before
+    public void setUp() {
+        algorithm = new MaskFromXToYMaskAlgorithm();
+        algorithm.init(createProperties());
+    }
+    
+    private Properties createProperties() {
+        Properties props = new Properties();
+        props.setProperty("x", "3");
+        props.setProperty("y", "5");
+        props.setProperty("replace-char", "*");
+        return props;
+    }
+    
+    @Test
+    public void assertMask() {
+        assertThat(algorithm.mask("abc12345"), is("abc***45"));
+    }
+    
+    @Test
+    public void assertMaskWithShortPlainValue() {
+        assertThat(algorithm.mask("ab"), is("ab"));
+        assertThat(algorithm.mask("abc1"), is("abc*"));
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void assertMaskWithInvalidProperties() {
+        algorithm.init(createInvalidProperties());
+    }
+    
+    private Properties createInvalidProperties() {
+        Properties props = new Properties();
+        props.setProperty("x", "5");
+        props.setProperty("replace-char", "*");
+        return props;

Review Comment:
   Please use result instead of props.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.algorithm.cover;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * MASK_FROM_X_TO_Y.
+ */
+public final class MaskFromXToYMaskAlgorithmTest {
+    
+    private MaskFromXToYMaskAlgorithm algorithm;
+    
+    @Before
+    public void setUp() {
+        algorithm = new MaskFromXToYMaskAlgorithm();
+        algorithm.init(createProperties());
+    }
+    
+    private Properties createProperties() {
+        Properties props = new Properties();
+        props.setProperty("x", "3");
+        props.setProperty("y", "5");
+        props.setProperty("replace-char", "*");
+        return props;

Review Comment:
   Please use result instead of props.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org