Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/.gitignore

Choose a reason for hiding this comment

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

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<groupId>com.example</groupId>
<modelVersion>4.0.0</modelVersion>
<groupId>ru.praktikum</groupId>
<artifactId>project_6</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<junit.jupiter.version>5.7.0</junit.jupiter.version>
<mockito.version>3.12.4</mockito.version>
<jacoco.version>0.8.13</jacoco.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>


<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>${jacoco.version}</version>
<executions>

<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
Expand All @@ -50,4 +66,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
38 changes: 19 additions & 19 deletions src/main/java/com/example/Animal.java
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("Неизвестный вид животного, используйте значение Травоядное или Хищник");
}
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/example/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

public class Cat {

private Predator predator;
private final Feline feline;

public Cat(Feline feline) {
this.predator = feline;
this.feline = feline;
}

public String getSound() {
return "Мяу";
}

public int getKittens() {
return feline.getKittens();
}

public List<String> getFood() throws Exception {
return predator.eatMeat();
return feline.eatMeat();
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/example/Lion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

public class Lion {

private boolean hasMane;
private Feline feline;
private final Predator predator;

Choose a reason for hiding this comment

The 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();
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/example/Predator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;

public interface Predator {

List<String> eatMeat() throws Exception;

}
int getKittens();
}
45 changes: 45 additions & 0 deletions src/test/java/com/example/AnimalTest.java
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("Неизвестный вид животного"));
}
}

Choose a reason for hiding this comment

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

⛔️Нужно исправить. Нет тестов на остальные классы. Пулл реквест создан неверное

39 changes: 29 additions & 10 deletions src/test/java/com/example/CatTest.java
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();
}
}
Loading