ListCountriesViewTest.java 1.4 KB
package org.legrog.web.xyz;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.Country;
import org.legrog.test.MockitoExtension;
import org.mockito.*;

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

/**
 * Classe testant ListCountriesView
 */
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Shows the country list")
public class ListCountriesViewTest {
    private ListCountriesView listCountriesView;
    private List<Country> countryList;

    @BeforeEach
    public void setup(@Mock SharedService sharedService) throws Exception {
        countryList = new ArrayList<Country>();

        listCountriesView = new ListCountriesView(sharedService);
        when(sharedService.getAllCountries()).thenReturn(countryList);
    }

    @Nested
    @DisplayName("init method")
    class initTests{

        @Test
        @DisplayName("should get all countries")
        public void getAllCountriesTest() {
            listCountriesView.init();
            assertThat(listCountriesView.getCountries()).isEqualTo(countryList);
        }
    }
}