-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatTest.java
More file actions
41 lines (31 loc) · 1.02 KB
/
CatTest.java
File metadata and controls
41 lines (31 loc) · 1.02 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
import com.example.Cat;
import com.example.Feline;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class CatTest {
@Mock
Feline feline;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
@Test
public void getCatSoundTest() {
Cat cat = new Cat(feline);
String expectedSound = "Мяу";
assertEquals("Кошка должна мяукать", expectedSound, cat.getSound());
}
@Test
public void getCatFoodTest() throws Exception {
Cat cat = new Cat(feline);
List<String> expectedFood = List.of("Животные", "Птицы", "Рыба");
Mockito.when(feline.eatMeat()).thenReturn(expectedFood);
assertEquals("Кошка должна есть мясо", expectedFood, cat.getFood());
Mockito.verify(feline, Mockito.times(1)).eatMeat();
}
}