Jean-Francois Leveque

Début de couverture de SharedServiceDefault

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.user.UserService;
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 UserService userService) {
sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository,
accountPropertyRepository, userService);
}
@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();
}
}
}