-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLionTest.java
More file actions
51 lines (41 loc) · 1.4 KB
/
LionTest.java
File metadata and controls
51 lines (41 loc) · 1.4 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
48
49
50
51
import com.example.Feline;
import com.example.Lion;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.util.List;
public class LionTest {
@Mock
Feline feline;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
@Test
public void getLionFoodTest() throws Exception {
Lion lion = new Lion("Самка", feline);
List<String> food = List.of("Животные", "Птицы", "Рыба");
Mockito.when(feline.getFood("Хищник")).thenReturn(food);
Assert.assertEquals(food, lion.getFood());
}
@Test
public void doesHaveManeMale() throws Exception {
Lion lion = new Lion("Самец", feline);
Assert.assertTrue(lion.doesHaveMane());
}
@Test
public void doesHaveManeFemale() throws Exception {
Lion lion = new Lion("Самка", feline);
Assert.assertFalse(lion.doesHaveMane());
}
@Test
public void doesHaveManeException() throws Exception {
Exception exception = Assert.assertThrows(Exception.class, () -> {
new Lion("Man", feline);
});
Assert.assertEquals("Используйте допустимые значения пола животного - самец или самка", exception.getMessage());
}
}