Showing
1 changed file
with
65 additions
and
0 deletions
1 | +package org.legrog.web.xyz; | ||
2 | + | ||
3 | +import org.junit.jupiter.api.BeforeEach; | ||
4 | +import org.junit.jupiter.api.DisplayName; | ||
5 | +import org.junit.jupiter.api.Nested; | ||
6 | +import org.junit.jupiter.api.Test; | ||
7 | +import org.junit.jupiter.api.extension.ExtendWith; | ||
8 | +import org.junit.platform.runner.JUnitPlatform; | ||
9 | +import org.junit.runner.RunWith; | ||
10 | +import org.legrog.entities.AccountPropertyRepository; | ||
11 | +import org.legrog.entities.AccountRoleRepository; | ||
12 | +import org.legrog.entities.Country; | ||
13 | +import org.legrog.entities.CountryRepository; | ||
14 | +import org.legrog.test.MockitoExtension; | ||
15 | +import org.legrog.web.user.UserService; | ||
16 | +import org.mockito.Mock; | ||
17 | +import org.mockito.*; | ||
18 | + | ||
19 | +import static org.assertj.core.api.Assertions.assertThat; | ||
20 | + | ||
21 | +/* | ||
22 | + Classe testant SharedServiceDefault | ||
23 | + */ | ||
24 | +@RunWith(JUnitPlatform.class) | ||
25 | +@ExtendWith(MockitoExtension.class) | ||
26 | +@DisplayName("Service layer for data that is not content") | ||
27 | +public class SharedServiceDefaultTest { | ||
28 | + SharedServiceDefault sharedServiceDefault; | ||
29 | + | ||
30 | + @BeforeEach | ||
31 | + public void setUp(@Mock CountryRepository countryRepository, | ||
32 | + @Mock AccountRoleRepository accountRoleRepository, | ||
33 | + @Mock AccountPropertyRepository accountPropertyRepository, | ||
34 | + @Mock UserService userService) { | ||
35 | + sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository, | ||
36 | + accountPropertyRepository, userService); | ||
37 | + } | ||
38 | + | ||
39 | + @Nested | ||
40 | + @DisplayName("addCountry method") | ||
41 | + class AddCountryTest { | ||
42 | + @Captor | ||
43 | + ArgumentCaptor<Country> countryArgumentCaptor; | ||
44 | + | ||
45 | + @Test | ||
46 | + @DisplayName("When adding country, should be saved to repository") | ||
47 | + public void addSavesCountry(@Mock CountryRepository countryRepository) { | ||
48 | + Country country = new Country(); | ||
49 | + sharedServiceDefault.addCountry(country); | ||
50 | + Mockito.verify(countryRepository).save(countryArgumentCaptor.capture()); | ||
51 | + assertThat(countryArgumentCaptor.getValue()).isEqualTo(country); | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + @Nested | ||
56 | + @DisplayName("getAllCountries method") | ||
57 | + class GetAllCountries { | ||
58 | + @Test | ||
59 | + @DisplayName("When requesting all countries, should ask all from repository") | ||
60 | + public void getAllAsksAll(@Mock CountryRepository countryRepository) { | ||
61 | + sharedServiceDefault.getAllCountries(); | ||
62 | + Mockito.verify(countryRepository).findAll(); | ||
63 | + } | ||
64 | + } | ||
65 | +} |
-
Please register or login to post a comment