|
|
@@ -486,8 +486,6 @@ class UserControllerTest {
|
|
|
verify(userGateway, times(1)).loginBySmsCode(request);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Test
|
|
|
void getUserPhone_Success() {
|
|
|
// 准备测试数据
|
|
|
@@ -530,10 +528,10 @@ class UserControllerTest {
|
|
|
assertEquals(ErrorEnum.WECHAT_CODE_ISNULL.getErrorCode(), exception.getErrCode());
|
|
|
assertEquals(ErrorEnum.WECHAT_CODE_ISNULL.getErrorMessage(), exception.getMessage());
|
|
|
|
|
|
-
|
|
|
// 验证交互
|
|
|
verify(userGateway, times(1)).getUserPhone(invalidCode);
|
|
|
}
|
|
|
+
|
|
|
@Test
|
|
|
void getUserPhone_Exception() {
|
|
|
// 准备测试数据
|
|
|
@@ -549,6 +547,67 @@ class UserControllerTest {
|
|
|
verify(userGateway, times(1)).getUserPhone(code);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void checkPhone_EmptyPhone() {
|
|
|
+ // 准备测试数据
|
|
|
+ String phone = "";
|
|
|
+ String openid = "test_openid";
|
|
|
+
|
|
|
+ // 模拟UserGateway抛出异常
|
|
|
+ when(userGateway.checkPhone(phone, openid))
|
|
|
+ .thenThrow(new BizException(ErrorEnum.PHONE_IS_NULL.getErrorCode(), ErrorEnum.PHONE_IS_NULL.getErrorMessage()));
|
|
|
+
|
|
|
+ // 执行测试并验证异常
|
|
|
+ BizException exception = assertThrows(BizException.class,
|
|
|
+ () -> userController.checkPhone(phone, openid));
|
|
|
+
|
|
|
+ // 验证异常内容
|
|
|
+ assertEquals(ErrorEnum.PHONE_IS_NULL.getErrorCode(), exception.getErrCode());
|
|
|
+ assertEquals(ErrorEnum.PHONE_IS_NULL.getErrorMessage(), exception.getMessage());
|
|
|
+
|
|
|
+ // 验证交互
|
|
|
+ verify(userGateway, times(1)).checkPhone(phone, openid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void checkPhone_PhoneExists() {
|
|
|
+ // 准备测试数据
|
|
|
+ String phone = "13800138000";
|
|
|
+ String openid = "test_openid";
|
|
|
+
|
|
|
+ // 模拟UserGateway返回true表示手机号存在
|
|
|
+ when(userGateway.checkPhone(phone, openid)).thenReturn(true);
|
|
|
+
|
|
|
+ // 执行测试
|
|
|
+ ApiResult<Boolean> result = userController.checkPhone(phone, openid);
|
|
|
+
|
|
|
+ // 验证结果
|
|
|
+ assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+ assertEquals(true, result.getData());
|
|
|
+
|
|
|
+ // 验证交互
|
|
|
+ verify(userGateway, times(1)).checkPhone(phone, openid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void checkPhone_PhoneNotExists() {
|
|
|
+ // 准备测试数据
|
|
|
+ String phone = "13800138000";
|
|
|
+ String openid = "test_openid";
|
|
|
+
|
|
|
+ // 模拟UserGateway返回false表示手机号不存在
|
|
|
+ when(userGateway.checkPhone(phone, openid)).thenReturn(false);
|
|
|
+
|
|
|
+ // 执行测试
|
|
|
+ ApiResult<Boolean> result = userController.checkPhone(phone, openid);
|
|
|
+
|
|
|
+ // 验证结果
|
|
|
+ assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+ assertEquals(false, result.getData());
|
|
|
+
|
|
|
+ // 验证交互
|
|
|
+ verify(userGateway, times(1)).checkPhone(phone, openid);
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
void updatePassword_Success() {
|
|
|
@@ -617,8 +676,6 @@ class UserControllerTest {
|
|
|
verify(userGateway, times(1)).logout(request);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 辅助方法
|
|
|
private PhoneLoginParams createTestPhoneLoginParams(String phone, String openId, String unionId) {
|
|
|
PhoneLoginParams params = new PhoneLoginParams();
|