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.Country; import org.legrog.test.MockitoExtension; import org.mockito.*; import static org.assertj.core.api.Assertions.assertThat; /** * Classe testant AddCountryView */ @RunWith(JUnitPlatform.class) @ExtendWith(MockitoExtension.class) @DisplayName("Adds a country to the list") public class AddCountryViewTest { @Nested @DisplayName("add method") class AddTests { private AddCountryView addCountryView; @Captor ArgumentCaptor<Country> countryArgumentCaptor; @BeforeEach public void setup(@Mock SharedService sharedServiceMock) { addCountryView = new AddCountryView(sharedServiceMock); addCountryView.setCountryName("Zanzibar"); addCountryView.add(); } @Test @DisplayName("should use the SharedService with right argument when a country is added") public void testSharedServiceAdd(@Mock SharedService sharedServiceMock) { Mockito.verify(sharedServiceMock).addCountry(countryArgumentCaptor.capture()); Country country = countryArgumentCaptor.getValue(); assertThat(country.getCountryName()).isEqualTo("Zanzibar"); } } }