From 8f0d001f463b49bd07160d08fc39c689ad96e8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=BE=89?= Date: Fri, 5 Aug 2022 16:16:54 +0800 Subject: [PATCH] Add unit test for AnonymizeUtil --- .../user/auth/utils/AnonymizeUtilTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/java/org/edgegallery/user/auth/utils/AnonymizeUtilTest.java diff --git a/src/test/java/org/edgegallery/user/auth/utils/AnonymizeUtilTest.java b/src/test/java/org/edgegallery/user/auth/utils/AnonymizeUtilTest.java new file mode 100644 index 0000000..13a57ab --- /dev/null +++ b/src/test/java/org/edgegallery/user/auth/utils/AnonymizeUtilTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.user.auth.utils; + +import org.junit.Assert; +import org.junit.Test; + +public class AnonymizeUtilTest { + + @Test + public void testAnonymizePhoneNum() { + String mockPhone = "15658551365"; + String res = AnonymizeUtil.anonymizePhoneNum(mockPhone); + Assert.assertEquals("156****1365", res); + } + + @Test + public void testAnonymizePhoneNumFailed() { + String mockPhone = "1565855136512345"; + String res = AnonymizeUtil.anonymizePhoneNum(mockPhone); + Assert.assertEquals(mockPhone, res); + } + + @Test + public void testAnonymizeMail() { + String mockMail = "1111xxxx222@qq.com"; + String res = AnonymizeUtil.anonymizeMail(mockMail); + Assert.assertEquals("1****@qq.com", res); + } + + @Test + public void testAnonymizeMailFailed1() { + String mockMail = "1111xxxx222qq.com"; + String res = AnonymizeUtil.anonymizeMail(mockMail); + Assert.assertEquals(mockMail, res); + } + + @Test + public void testIsAnonymizedReturnTrue() { + String mockSign = "****"; + boolean res = AnonymizeUtil.isAnonymized(mockSign); + Assert.assertTrue(res); + } + + @Test + public void testIsAnonymizedReturnFalse() { + String mockSign = "1111"; + boolean res = AnonymizeUtil.isAnonymized(mockSign); + Assert.assertFalse(res); + } + +} -- Gitee