-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint 6 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Sprint 6 #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| package com.example; | ||
| import java.util.List; | ||
| public class Animal { | ||
| public List<String> getFood(String animalKind) throws Exception { | ||
| if ("Травоядное".equals(animalKind)) { | ||
| return List.of("Трава", "Различные растения"); | ||
| } else if ("Хищник".equals(animalKind)) { | ||
| return List.of("Животные", "Птицы", "Рыба"); | ||
| } else { | ||
| throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник"); | ||
| } | ||
| } | ||
| public String getFamily() { | ||
| return "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи"; | ||
| } | ||
| package com.example; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Animal { | ||
|
|
||
| public String getFamily() { | ||
| return "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи"; | ||
| } | ||
|
|
||
| public List<String> getFood(String type) throws Exception { | ||
| if ("Хищник".equals(type)) { | ||
| return List.of("Животные", "Птицы", "Рыба"); | ||
| } else if ("Травоядное".equals(type)) { | ||
| return List.of("Трава", "Различные растения"); | ||
| } else { | ||
| throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник"); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,29 +4,29 @@ | |
|
|
||
| public class Lion { | ||
|
|
||
| private boolean hasMane; | ||
| private Feline feline; | ||
| private final Predator predator; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Нужно использовать Feline feline; |
||
| private final boolean hasMane; | ||
|
|
||
| public Lion(String sex, Feline feline) throws Exception { | ||
| public Lion(String sex, Predator predator) throws Exception { | ||
| if ("Самец".equals(sex)) { | ||
| this.hasMane = true; | ||
| } else if ("Самка".equals(sex)) { | ||
| this.hasMane = false; | ||
| } else { | ||
| throw new Exception("Используйте допустимые значения пола животного - Самец или Самка"); | ||
| } | ||
| this.feline = feline; // dependency injection | ||
| } | ||
|
|
||
| public int getKittens() { | ||
| return feline.getKittens(); | ||
| this.predator = predator; | ||
| } | ||
|
|
||
| public boolean doesHaveMane() { | ||
| return hasMane; | ||
| } | ||
|
|
||
| public int getKittens() { | ||
| return predator.getKittens(); | ||
| } | ||
|
|
||
| public List<String> getFood() throws Exception { | ||
| return feline.eatMeat(); | ||
| return predator.eatMeat(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| import java.util.List; | ||
|
|
||
| public interface Predator { | ||
|
|
||
| List<String> eatMeat() throws Exception; | ||
|
|
||
| } | ||
| int getKittens(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import java.util.List; | ||
|
|
||
| class AnimalTest { | ||
|
|
||
| private Animal animal; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| animal = new Animal(); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetFamily() { | ||
| String expected = "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи"; | ||
| String actual = animal.getFamily(); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetFoodPredator() throws Exception { | ||
| List<String> expected = List.of("Животные", "Птицы", "Рыба"); | ||
| List<String> actual = animal.getFood("Хищник"); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetFoodHerbivore() throws Exception { | ||
| List<String> expected = List.of("Трава", "Различные растения"); | ||
| List<String> actual = animal.getFood("Травоядное"); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetFoodUnknown() { | ||
| Exception exception = assertThrows(Exception.class, () -> { | ||
| animal.getFood("Неизвестное"); | ||
| }); | ||
| assertTrue(exception.getMessage().contains("Неизвестный вид животного")); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Нет тестов на остальные классы. Пулл реквест создан неверное |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,47 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| public class CatTest { | ||
|
|
||
| private Feline feline; | ||
| private Cat cat; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| feline = mock(Feline.class); | ||
| cat = new Cat(feline); | ||
| } | ||
|
|
||
| @Test | ||
| public void getSoundAlwaysMiau() { | ||
| Feline felineMock = mock(Feline.class); | ||
| Cat cat = new Cat(felineMock); | ||
| void testGetSound() { | ||
| assertEquals("Мяу", cat.getSound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFoodUsesFelineMock() throws Exception { | ||
| Feline felineMock = mock(Feline.class); | ||
| when(felineMock.eatMeat()).thenReturn(List.of("Рыба", "Птицы")); | ||
| void testGetKittens() { | ||
| when(feline.getKittens()).thenReturn(1); | ||
| assertEquals(1, cat.getKittens()); | ||
| } | ||
|
|
||
| Cat cat = new Cat(felineMock); | ||
| List<String> food = cat.getFood(); | ||
| @Test | ||
| void testGetFoodReturnsExpected() throws Exception { | ||
| List<String> expected = List.of("Животные", "Птицы", "Рыба"); | ||
| when(feline.eatMeat()).thenReturn(expected); | ||
| List<String> actual = cat.getFood(); | ||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| assertEquals(List.of("Рыба", "Птицы"), food); | ||
| verify(felineMock, times(1)).eatMeat(); | ||
| @Test | ||
| void testGetFoodInvokesEatMeatOnce() throws Exception { | ||
| when(feline.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба")); | ||
| cat.getFood(); | ||
| verify(feline, times(1)).eatMeat(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛔️Нужно исправить. Папку .idea не нужно было загружать в репозиторий. Эта папка должна быть добавлена в .gitignore.