-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from szymonpoltorak/tests-and-fixes
Fixed mappings and added missing tests
- Loading branch information
Showing
10 changed files
with
195 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
corn-backend/src/test/java/dev/corn/cornbackend/api/sprint/SprintControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
corn-backend/src/test/java/dev/corn/cornbackend/api/user/UserServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dev.corn.cornbackend.api.user; | ||
|
||
import dev.corn.cornbackend.entities.user.User; | ||
import dev.corn.cornbackend.entities.user.data.UserResponse; | ||
import dev.corn.cornbackend.entities.user.interfaces.UserMapper; | ||
import dev.corn.cornbackend.entities.user.interfaces.UserMapperImpl; | ||
import dev.corn.cornbackend.entities.user.interfaces.UserRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest(classes = {UserRepository.class, UserMapper.class}) | ||
class UserServiceTest { | ||
@InjectMocks | ||
private UserServiceImpl userService; | ||
|
||
@Mock | ||
private UserRepository userRepository; | ||
|
||
@Mock | ||
private UserMapper userMapper; | ||
|
||
private static final UserMapper MAPPER = new UserMapperImpl(); | ||
|
||
@Test | ||
final void test_registerUser_shouldRegisterUser() { | ||
// given | ||
String name = "name"; | ||
String surname = "surname"; | ||
String username = "username"; | ||
User user = User.builder() | ||
.name(name) | ||
.surname(surname) | ||
.username(username) | ||
.build(); | ||
UserResponse expected = MAPPER.toUserResponse(user); | ||
|
||
// when | ||
when(userRepository.save(user)) | ||
.thenReturn(user); | ||
when(userMapper.toUserResponse(user)) | ||
.thenReturn(expected); | ||
|
||
UserResponse actual = userService.registerUser(name, surname, username); | ||
|
||
// then | ||
assertEquals(expected, actual, "UserResponse should be equal to expected"); | ||
verify(userRepository).save(user); | ||
} | ||
} |
Oops, something went wrong.