test: 提升Web包测试覆盖率 - 新增UrlValidator边界测试

新增测试:
- UserExperienceController: maskPhone方法测试
- UrlValidator: IPv6公网地址、0.0.0.0地址、无效主机名、URI异常处理

覆盖率提升:
- 总体分支: 63.6% → 63.8% (+1个分支)
- Web包: 78% → 79% (+1%)
- 新增测试: 5个
- 距离70%目标: 还需39个分支

累计成果(本次会话):
- 新增测试: 17个
- 分支覆盖: +8个 (404→412)
- Controller包: 73% → 89% (+16%)
- Web包: 78% → 79% (+1%)
This commit is contained in:
Your Name
2026-03-03 12:35:27 +08:00
parent bbd27dca1d
commit 11a73653aa
3 changed files with 48 additions and 1 deletions

View File

@@ -310,4 +310,21 @@ class UserExperienceControllerTest {
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data[0].type").value("points"));
}
@Test
void shouldMaskPhoneNumber_inInvitedFriends() throws Exception {
UserInviteEntity a = new UserInviteEntity();
a.setInviteeUserId(123L);
a.setStatus("registered");
when(userInviteRepository.findByActivityIdAndInviterUserId(anyLong(), anyLong())).thenReturn(List.of(a));
mockMvc.perform(get("/api/v1/me/invited-friends")
.param("activityId", "1")
.param("userId", "2")
.header("X-API-Key", TestAuthSupport.RAW_API_KEY)
.header("Authorization", "Bearer test-token"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data[0].maskedPhone").value("138****0123"));
}
}