diff --git a/src/test/java/org/edgegallery/user/auth/utils/CommonUtilTest.java b/src/test/java/org/edgegallery/user/auth/utils/CommonUtilTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f2118c5de188f2428bd3598213d82a7d6d0c88e3 --- /dev/null +++ b/src/test/java/org/edgegallery/user/auth/utils/CommonUtilTest.java @@ -0,0 +1,50 @@ +/* + * 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 CommonUtilTest { + + @Test + public void testIsInnerDefaultUserSuccess1() { + boolean res = CommonUtil.isInnerDefaultUser(Consts.SUPER_ADMIN_NAME); + Assert.assertTrue(res); + } + + @Test + public void testIsInnerDefaultUserSuccess2() { + boolean res = CommonUtil.isInnerDefaultUser(Consts.GUEST_USER_NAME); + Assert.assertTrue(res); + } + + + @Test + public void testIsInnerDefaultUserFailed() { + String inner = "others"; + boolean res = CommonUtil.isInnerDefaultUser(inner); + Assert.assertFalse(res); + } + + @Test + public void testIsInnerDefaultUserWithNull() { + String inner = null; + boolean res = CommonUtil.isInnerDefaultUser(inner); + Assert.assertFalse(res); + } +} diff --git a/src/test/java/org/edgegallery/user/auth/utils/UserLockUtilTest.java b/src/test/java/org/edgegallery/user/auth/utils/UserLockUtilTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7d8be39b6ce1839adab3219fa88aaca07951f6b6 --- /dev/null +++ b/src/test/java/org/edgegallery/user/auth/utils/UserLockUtilTest.java @@ -0,0 +1,52 @@ +/* + * 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; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class UserLockUtilTest { + + @InjectMocks + private UserLockUtil userLockUtil; + + @Test + public void testIsLockedReturnFalse() { + boolean res = userLockUtil.isLocked("testFlag"); + Assert.assertFalse(res); + } + + @Test + public void testAddFailedCount() { + userLockUtil.addFailedCount("testFlag"); + boolean res = userLockUtil.isLocked("testFlag"); + Assert.assertFalse(res); + } + + @Test + public void testClearFailedCount() { + userLockUtil.addFailedCount("testFlag"); + userLockUtil.clearFailedCount("testFlag"); + boolean res = userLockUtil.isLocked("testFlag"); + Assert.assertFalse(res); + } + +}