|
1
|
|
|
package com.dawn.jat.illuminati.core.convert; |
|
2
|
|
|
|
|
3
|
|
|
import static org.hamcrest.CoreMatchers.is; |
|
4
|
|
|
|
|
5
|
|
|
import static org.hamcrest.MatcherAssert.assertThat; |
|
6
|
|
|
|
|
7
|
|
|
import com.dawn.jat.illuminati.post.dto.PostDto; |
|
8
|
|
|
import com.dawn.jat.illuminati.post.entity.PostEntity; |
|
9
|
|
|
|
|
10
|
|
|
import java.util.ArrayList; |
|
11
|
|
|
import java.util.Arrays; |
|
12
|
|
|
import java.util.HashMap; |
|
13
|
|
|
|
|
14
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
15
|
|
|
import org.junit.jupiter.api.Test; |
|
16
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
17
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
18
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
19
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
@ExtendWith(MockitoExtension.class) |
|
23
|
|
|
@SpringBootTest |
|
24
|
|
|
class ConverterTest { |
|
25
|
|
|
private static PostEntity postEntity; |
|
26
|
|
|
private static PostDto postDto; |
|
27
|
|
|
@Autowired |
|
28
|
|
|
Converter converter; |
|
29
|
|
|
|
|
30
|
|
|
@BeforeAll |
|
31
|
|
|
public static void init() { |
|
32
|
|
|
postEntity = new PostEntity("how-to-apply-agile-methodology", |
|
33
|
|
|
"How to apply Agile methodology", |
|
34
|
|
|
"Guide", |
|
35
|
|
|
"01/01/2020", |
|
36
|
|
|
new ArrayList<>(Arrays.asList("Agile")), |
|
37
|
|
|
"Phat Ho"); |
|
38
|
|
|
HashMap tags = new HashMap(); |
|
39
|
|
|
tags.put("System Design", Boolean.TRUE); |
|
40
|
|
|
tags.put("OOP", Boolean.TRUE); |
|
41
|
|
|
postDto = new PostDto("5e80afe11de7a40da7f97052", |
|
42
|
|
|
"how-to-apply-agile-methodology", |
|
43
|
|
|
"How to apply Agile methodology new", |
|
44
|
|
|
"How to apply Agile methodology new", |
|
45
|
|
|
"01/01/2020 new", |
|
46
|
|
|
"Li Li new", |
|
47
|
|
|
"new content", |
|
48
|
|
|
tags); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
@Test |
|
52
|
|
|
public void convertPostDtoToEntity_givenDto_returnEntity() { |
|
53
|
|
|
PostEntity actualEntity = converter.convertPostDtoToEntity(postDto, postEntity); |
|
54
|
|
|
PostEntity expectedPostEntity = new PostEntity("how-to-apply-agile-methodology", |
|
55
|
|
|
"How to apply Agile methodology new", |
|
56
|
|
|
"How to apply Agile methodology new", |
|
57
|
|
|
"01/01/2020 new", |
|
58
|
|
|
new ArrayList<>(Arrays.asList("OOP", "System Design")), |
|
59
|
|
|
"Li Li new"); |
|
60
|
|
|
expectedPostEntity.setContent("new content"); |
|
61
|
|
|
assertThat(actualEntity, is(expectedPostEntity)); |
|
62
|
|
|
} |
|
63
|
|
|
} |