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/10 01:15:36 UTC

[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #22776: add KEEP_FIRST_N_LAST_M mask algorithm

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


##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithm.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.Optional;
+import java.util.Properties;
+
+/**
+ * KEEP_FIRST_N_LAST_M Algorithm.
+ */
+public class KeepFirstNLastMMaskAlgorithm implements MaskAlgorithm<Object, String> {
+    
+    private static final String START_INDEX = "start-index";

Review Comment:
   Can you modify the props to `n` and `m`? Just keep same with algorithm name.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/KeepFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.mask.algorithm.cover.KeepFirstNLastMMaskAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * KEEP_FIRST_N_LAST_M test.
+ */
+public class KeepFirstNLastMMaskAlgorithmTest {
+    
+    private KeepFirstNLastMMaskAlgorithm keepFirstNLastMMaskAlgorithm;
+    
+    @Before
+    public void setUp() {
+        keepFirstNLastMMaskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
+        keepFirstNLastMMaskAlgorithm.init(initProperties());
+    }
+    
+    private Properties initProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("start-index", "2");
+        properties.setProperty("stop-index", "5");
+        properties.setProperty("replace-char", "*");
+        return properties;
+    }
+    
+    @Test
+    public void testMask() {
+        String result = keepFirstNLastMMaskAlgorithm.mask("abc123456");
+        assertEquals("ab*23456", result);
+    }
+    
+    @Test
+    public void testMaskIfPlainValueIsLess() {
+        String result = keepFirstNLastMMaskAlgorithm.mask("abc");
+        assertEquals("abc", result);
+    }
+    
+    @Test
+    public void testNotSetStartIndex() {
+        KeepFirstNLastMMaskAlgorithm keepFirstNLastMMaskAlgorithm1 = new KeepFirstNLastMMaskAlgorithm();
+        Properties wrongProperties = new Properties();
+        wrongProperties.setProperty("stop-index", "5");
+        wrongProperties.setProperty("replace-char", "*");
+        assertThrows(IllegalArgumentException.class, () -> {
+            keepFirstNLastMMaskAlgorithm1.init(wrongProperties);
+        });
+    }
+    

Review Comment:
   Please remove this useless blank line.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/KeepFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.mask.algorithm.cover.KeepFirstNLastMMaskAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * KEEP_FIRST_N_LAST_M test.
+ */
+public class KeepFirstNLastMMaskAlgorithmTest {
+    
+    private KeepFirstNLastMMaskAlgorithm keepFirstNLastMMaskAlgorithm;
+    
+    @Before
+    public void setUp() {
+        keepFirstNLastMMaskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
+        keepFirstNLastMMaskAlgorithm.init(initProperties());
+    }
+    
+    private Properties initProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("start-index", "2");
+        properties.setProperty("stop-index", "5");
+        properties.setProperty("replace-char", "*");
+        return properties;

Review Comment:
   Please rename properties to result.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/KeepFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.mask.algorithm.cover.KeepFirstNLastMMaskAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * KEEP_FIRST_N_LAST_M test.
+ */
+public class KeepFirstNLastMMaskAlgorithmTest {
+    
+    private KeepFirstNLastMMaskAlgorithm keepFirstNLastMMaskAlgorithm;
+    
+    @Before
+    public void setUp() {
+        keepFirstNLastMMaskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
+        keepFirstNLastMMaskAlgorithm.init(initProperties());
+    }
+    
+    private Properties initProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("start-index", "2");
+        properties.setProperty("stop-index", "5");
+        properties.setProperty("replace-char", "*");
+        return properties;
+    }
+    
+    @Test
+    public void testMask() {
+        String result = keepFirstNLastMMaskAlgorithm.mask("abc123456");
+        assertEquals("ab*23456", result);
+    }
+    
+    @Test
+    public void testMaskIfPlainValueIsLess() {
+        String result = keepFirstNLastMMaskAlgorithm.mask("abc");
+        assertEquals("abc", result);

Review Comment:
   Hi @zzzwjZhang, you can read ShardingSphere code conduct first - https://shardingsphere.apache.org/community/en/involved/conduct/code/. We recommend using assertThat over assertEquals.



##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithm.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.Optional;
+import java.util.Properties;
+
+/**
+ * KEEP_FIRST_N_LAST_M Algorithm.
+ */
+public class KeepFirstNLastMMaskAlgorithm implements MaskAlgorithm<Object, String> {

Review Comment:
   Please add final for KeepFirstNLastMMaskAlgorithm.



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/KeepFirstNLastMMaskAlgorithmTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.mask.algorithm.cover.KeepFirstNLastMMaskAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * KEEP_FIRST_N_LAST_M test.
+ */
+public class KeepFirstNLastMMaskAlgorithmTest {

Review Comment:
   Please add final for KeepFirstNLastMMaskAlgorithmTest.



-- 
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