-
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.
- Loading branch information
Showing
2 changed files
with
52 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import com.movieapp.movieapp.movie.Movie; | ||
import com.movieapp.movieapp.movie.MovieDto; | ||
import com.movieapp.movieapp.user.User; | ||
import com.movieapp.movieapp.user.UserDto; | ||
|
||
public final class TestDataUtil { | ||
|
||
|
@@ -27,6 +28,18 @@ public static User createTestUserEntityA() { | |
.build(); | ||
} | ||
|
||
public static UserDto createTestUserDtoA() { | ||
final LocalDateTime dateCreated = LocalDateTime.parse("2024-10-11T18:34:14.406"); | ||
|
||
return UserDto.builder() | ||
.id(TEST_USER_ID) | ||
.name("Armin") | ||
.email("[email protected]") | ||
.created(dateCreated) | ||
.lastUpdated(dateCreated) | ||
.build(); | ||
} | ||
|
||
public static Movie createTestMovieEntityA() { | ||
final LocalDateTime dateCreated = LocalDateTime.parse("2020-01-07T11:21:12.103"); | ||
|
||
|
42 changes: 39 additions & 3 deletions
42
src/test/java/com/movieapp/movieapp/user/UserMapperTest.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 |
---|---|---|
@@ -1,16 +1,52 @@ | ||
package com.movieapp.movieapp.user; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.modelmapper.ModelMapper; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.movieapp.movieapp.TestDataUtil; | ||
import com.movieapp.movieapp.mappers.Mapper; | ||
|
||
|
||
//TODO: | ||
class UserMapperTest { | ||
|
||
private Mapper<User, UserDto> userMapper; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.userMapper = new UserMapper(new ModelMapper()); | ||
} | ||
|
||
@Test | ||
public void testMapTo() { | ||
User userB = TestDataUtil.createTestUserEntityA(); | ||
UserDto userDtoB = TestDataUtil.createTestUserDtoA(); | ||
UserDto result = this.userMapper.mapTo(userB); | ||
|
||
assertEquals(userDtoB, result); | ||
} | ||
|
||
@Test | ||
public void testMapFrom() { | ||
UserDto userDtoA = TestDataUtil.createTestUserDtoA(); | ||
User userA = TestDataUtil.createTestUserEntityA(); | ||
User result = this.userMapper.mapFrom(userDtoA); | ||
|
||
assertEquals(userA, result); | ||
} | ||
|
||
@Test | ||
void testMapTo() { | ||
public void testMapToThrowsWhenPassedNull() { | ||
NullPointerException exp = assertThrows(NullPointerException.class, () -> this.userMapper.mapTo(null)); | ||
assertEquals("user is null", exp.getMessage()); | ||
} | ||
|
||
@Test | ||
void testMapFrom() { | ||
public void testMapFromThrowsWhenPassedNull() { | ||
NullPointerException exp = assertThrows(NullPointerException.class, () -> this.userMapper.mapFrom(null)); | ||
assertEquals("userDto is null", exp.getMessage()); | ||
} | ||
|
||
} |