-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserMapperSpringTest.java
More file actions
63 lines (54 loc) · 2.2 KB
/
UserMapperSpringTest.java
File metadata and controls
63 lines (54 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.openpodcastapi.opa.user;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openpodcastapi.opa.user.dto.CreateUserDto;
import org.openpodcastapi.opa.user.dto.UserDto;
import org.openpodcastapi.opa.user.mapper.UserMapper;
import org.openpodcastapi.opa.user.mapper.UserMapperImpl;
import org.openpodcastapi.opa.user.model.User;
import org.openpodcastapi.opa.user.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.time.Instant;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = UserMapperImpl.class)
class UserMapperSpringTest {
@Autowired
private UserMapper mapper;
@MockitoBean
private UserRepository userRepository;
/// Tests that a [User] entity maps to a [UserDto] representation
@Test
void testToDto() {
final Instant timestamp = Instant.now();
final UUID uuid = UUID.randomUUID();
User user = User.builder()
.uuid(uuid)
.username("test")
.email("test@test.test")
.createdAt(timestamp)
.updatedAt(timestamp)
.build();
UserDto dto = mapper.toDto(user);
assertNotNull(dto);
assertEquals(user.getUuid(), dto.uuid());
assertEquals(user.getUsername(), dto.username());
assertEquals(user.getEmail(), dto.email());
assertEquals(user.getCreatedAt(), dto.createdAt());
assertEquals(user.getUpdatedAt(), dto.updatedAt());
}
/// Tests that a [CreateUserDto] maps to a [User] entity
@Test
void testToEntity() {
CreateUserDto dto = new CreateUserDto("test", "testPassword", "test@test.test");
User user = mapper.toEntity(dto);
assertNotNull(user);
assertEquals(dto.email(), user.getEmail());
assertEquals(dto.username(), user.getUsername());
assertNull(user.getPassword());
}
}