SharedServiceDefaultTest.java
2.35 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
64
65
package org.legrog.web.xyz;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.AccountPropertyRepository;
import org.legrog.entities.AccountRoleRepository;
import org.legrog.entities.Country;
import org.legrog.entities.CountryRepository;
import org.legrog.test.MockitoExtension;
import org.legrog.web.account.AccountService;
import org.mockito.Mock;
import org.mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
/*
Classe testant SharedServiceDefault
*/
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Service layer for data that is not content")
public class SharedServiceDefaultTest {
SharedServiceDefault sharedServiceDefault;
@BeforeEach
public void setUp(@Mock CountryRepository countryRepository,
@Mock AccountRoleRepository accountRoleRepository,
@Mock AccountPropertyRepository accountPropertyRepository,
@Mock AccountService accountService) {
sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository,
accountPropertyRepository, accountService);
}
@Nested
@DisplayName("addCountry method")
class AddCountryTest {
@Captor
ArgumentCaptor<Country> countryArgumentCaptor;
@Test
@DisplayName("When adding country, should be saved to repository")
public void addSavesCountry(@Mock CountryRepository countryRepository) {
Country country = new Country();
sharedServiceDefault.addCountry(country);
Mockito.verify(countryRepository).save(countryArgumentCaptor.capture());
assertThat(countryArgumentCaptor.getValue()).isEqualTo(country);
}
}
@Nested
@DisplayName("getAllCountries method")
class GetAllCountries {
@Test
@DisplayName("When requesting all countries, should ask all from repository")
public void getAllAsksAll(@Mock CountryRepository countryRepository) {
sharedServiceDefault.getAllCountries();
Mockito.verify(countryRepository).findAll();
}
}
}