Revize c5787e2d
Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)
backend/src/test/java/cz/zcu/kiv/backendapi/type/TypeServiceImplTest.java | ||
---|---|---|
7 | 7 |
import org.mockito.Mock; |
8 | 8 |
import org.mockito.junit.jupiter.MockitoExtension; |
9 | 9 |
|
10 |
import java.util.Set; |
|
11 |
import java.util.stream.Collectors; |
|
12 |
import java.util.stream.Stream; |
|
10 | 13 |
|
11 | 14 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
15 |
import static org.mockito.BDDMockito.given; |
|
12 | 16 |
import static org.mockito.Mockito.verify; |
13 | 17 |
|
14 | 18 |
@ExtendWith(MockitoExtension.class) |
... | ... | |
44 | 48 |
void getTypeByName() { |
45 | 49 |
// when |
46 | 50 |
String typeName = "type"; |
51 |
|
|
52 |
// given |
|
47 | 53 |
underTest.getTypeByName(typeName); |
48 | 54 |
|
49 | 55 |
// then |
50 | 56 |
verify(typeRepository).findById(typeName); |
51 | 57 |
} |
58 |
|
|
59 |
@Test |
|
60 |
void getTypesAsString() { |
|
61 |
// when |
|
62 |
String stringType1 = "type1"; |
|
63 |
String stringType2 = "type2"; |
|
64 |
String stringType3 = "type3"; |
|
65 |
String stringType4 = "type4"; |
|
66 |
String stringType5 = "type5"; |
|
67 |
|
|
68 |
Type type1 = new Type(stringType1); |
|
69 |
Type type2 = new Type(stringType2); |
|
70 |
Type type3 = new Type(stringType3); |
|
71 |
Type type4 = new Type(stringType4); |
|
72 |
Type type5 = new Type(stringType5); |
|
73 |
|
|
74 |
// given |
|
75 |
given(typeRepository.findAll()).willReturn(Stream.of(type1, type2, type3, type4, type5).collect(Collectors.toList())); |
|
76 |
Set<String> res = underTest.getAllTypesAsString(); |
|
77 |
|
|
78 |
// then |
|
79 |
verify(typeRepository).findAll(); |
|
80 |
|
|
81 |
assertThat(res.size()).isEqualTo(5); |
|
82 |
|
|
83 |
assertThat(res.contains(stringType1)).isTrue(); |
|
84 |
assertThat(res.contains(stringType2)).isTrue(); |
|
85 |
assertThat(res.contains(stringType3)).isTrue(); |
|
86 |
assertThat(res.contains(stringType4)).isTrue(); |
|
87 |
assertThat(res.contains(stringType5)).isTrue(); |
|
88 |
} |
|
52 | 89 |
} |
Také k dispozici: Unified diff
Added test for path
re #9490