Add unit tests

pull/1188/head
shikaibin 2 years ago
parent f59bef0a0d
commit 0c05ee6903

@ -131,9 +131,9 @@ public class UserServiceImpl implements UserService {
return result;
}
private void checkPasswordLength(String password) {
protected void checkPasswordLength(String password) {
if (StringUtil.isBlank(password)) {
return;
throw new RuntimeException("密码不可为空");
}
if (password.length() < MINI_PASSWORD_LENGTH) {
throw new RuntimeException("密码最少为6个字符");

@ -0,0 +1,20 @@
package cn.hippo4j.auth.service.impl;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
class UserServiceImplTest {
@Test
void checkPasswordLength() {
//密码为null、空串、过短、过长都会抛出异常
UserServiceImpl userService = new UserServiceImpl(null, null, null);
Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(null));
Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(""));
String shortPassword = "12345";
Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(shortPassword));
String LongPassword = "fjhdjfghdsgahfgajdhsgafghdsbvhbervjdsvhdsbhfbhsdbhfbhsdbavbsbdhjfbhjsdbhfbsdbf";
Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(LongPassword));
}
}
Loading…
Cancel
Save