Skip to content

Создание тестов и изменения#5

Open
Margarissiha wants to merge 4 commits intomainfrom
develop
Open

Создание тестов и изменения#5
Margarissiha wants to merge 4 commits intomainfrom
develop

Conversation

@Margarissiha
Copy link
Copy Markdown
Owner

No description provided.

Comment thread .idea/compiler.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать

папку .idea не нужно было загружать в репозиторий. Эта папка должна быть добавлена в .gitignore

Чтобы убрать папку .idea из ветки вашего GitHub репозитория, вы можете выполнить следующие шаги:

  1. Добавьте .idea в .gitignore
  2. Удалите папку .idea из индекса Git
    git rm -r --cached .idea
    Эта команда удалит папку .idea из индекса, но не удалит её с вашего компьютера.
  3. Закоммитьте изменения:
    git commit -m "........."
  4. Запушьте изменения на GitHub

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот момент нужно доработать

Comment thread src/main/java/com/example/Predator.java Outdated
List<String> eatMeat() throws Exception;

}
int getKittens();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать:
не нужно было править этот интерфейс

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int getKittens(); -- это нужно удалить, не нужно было вносить правки в интерфейс

Comment thread src/main/java/com/example/Lion.java Outdated
boolean hasMane;

public Lion(String sex) throws Exception {
public Lion(String sex, Predator predator) throws Exception {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно исправить.

изоляцию Lion от Feline нужно было делать через инъекцию зависимостей. То есть в класс Lion должен попадать уже созданный экземпляр класса Feline.
В классе должен быть только один конструктор public Lion(String sex, Feline feline).


Predator predator;

public Cat(Feline feline) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать:

нужно вернуть исходную реализацию

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот момент нужно доработать

return getFood("Хищник");
}

@Override
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать:

нужно вернуть исходную реализацию


Feline feline = new Feline();

public int getKittens() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать:

нужно вернуть исходную реализацию

}

public List<String> getFood() throws Exception {
return feline.getFood("Хищник");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно доработать:

нужно вернуть исходную реализацию

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно вернуть исходную реализацию

public void testGetFood() throws Exception {
Feline felineMock = Mockito.mock(Feline.class);
List<String> expectedFood = Arrays.asList("Животные", "Птицы", "Рыба");
Mockito.when(felineMock.eatMeat()).thenReturn(expectedFood);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот тест падает, чтобы он заработал, нужно иначе мокать на строке 54:
Mockito.when(felineMock.getFood("Хищник")).thenReturn(expectedFood);

@Test
public void testGetFoodHasThreeItems() throws Exception {
Feline felineMock = Mockito.mock(Feline.class);
Mockito.when(felineMock.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь нужно иначе мокать:
Mockito.when(felineMock.getFood("Хищник")).thenReturn(List.of("Животные", "Птицы", "Рыба"));

@Test
public void testGetFoodContainsAnimals() throws Exception {
Feline felineMock = Mockito.mock(Feline.class);
Mockito.when(felineMock.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь такая же ошибка как и в тесте testGetFoodHasThreeItems()

@Test
public void testGetFoodContainsBirds() throws Exception {
Feline felineMock = Mockito.mock(Feline.class);
Mockito.when(felineMock.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь такая же ошибка как и в тесте testGetFoodHasThreeItems()

@Test
public void testGetFoodContainsFish() throws Exception {
Feline felineMock = Mockito.mock(Feline.class);
Mockito.when(felineMock.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь такая же ошибка как и в тесте testGetFoodHasThreeItems()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants