AddCountryViewTest.java
1.5 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
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");
}
}
}