测试逻辑优化

This commit is contained in:
myh 2024-01-04 15:22:56 +08:00
parent aab93e0141
commit ed65fd0b36
2 changed files with 6 additions and 6 deletions

View File

@ -103,7 +103,7 @@ class UsersControllerTests {
user.setAddress("test address");
UsersPassword userPassword = new UsersPassword();
userPassword.setPassword("test1234567");
userPassword.setUsers(user);
userPassword.setUser(user);
UsersController.wrapperUserAndPassword usersAndPassword = new UsersController.wrapperUserAndPassword();
usersAndPassword.setUser(user);
@ -139,7 +139,7 @@ class UsersControllerTests {
user.setAddress("test address");
UsersPassword userPassword = new UsersPassword();
userPassword.setPassword("test1234567");
userPassword.setUsers(user);
userPassword.setUser(user);
// Convert to JSON
ObjectMapper mapper = new ObjectMapper();

View File

@ -61,7 +61,7 @@ class UsersServiceTests {
user1.setAddress("test address user1");
user1Password = new UsersPassword();
user1Password.setUsers(user1);
user1Password.setUser(user1);
user1Password.setPassword("TestPassword1");
user2 = new Users();
@ -71,7 +71,7 @@ class UsersServiceTests {
user2.setAddress("test address user2");
user2Password = new UsersPassword();
user2Password.setUsers(user2);
user2Password.setUser(user2);
user2Password.setPassword("TestPassword2");
usersList.add(user1);
@ -99,14 +99,14 @@ class UsersServiceTests {
@Rollback(value = true)
void testSaveUser() {
when(usersRepository.save(any())).thenReturn(user1);
usersService.addUser(user1, user1Password);
usersService.addUser(user1, user1Password.getPassword());
verify(usersRepository, times(1)).save(any());
}
@Test
@Rollback(value = true)
void testGetAllUsers() {
usersService.addUser(user1, user1Password);
usersService.addUser(user1, user1Password.getPassword());
when(usersRepository.findAll()).thenReturn(usersList);
List<Users> usersList1 = usersService.findAllUsers();
Assertions.assertEquals(usersList1, usersList);