diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..a0ccf77
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Environment-dependent path to Maven home directory
+/mavenHomeManager.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..8c0aa20
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..4a2da3c
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..90fdf05
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 21b508c..1beaa58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,47 +1,63 @@
- 4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
- com.example
+ 4.0.0
+ ru.praktikum
project_6
1.0-SNAPSHOT
+
+ UTF-8
+ UTF-8
11
11
+ 5.7.0
+ 3.12.4
+ 0.8.13
org.junit.jupiter
junit-jupiter
- 5.10.0
+ ${junit.jupiter.version}
test
org.mockito
mockito-core
- 5.5.0
+ ${mockito.version}
test
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.5
+
+
+
org.jacoco
jacoco-maven-plugin
- 0.8.10
+ ${jacoco.version}
+
+ prepare-agent
prepare-agent
report
- test
+ verify
report
@@ -50,4 +66,4 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/com/example/Animal.java b/src/main/java/com/example/Animal.java
index 6792db6..91dd06a 100644
--- a/src/main/java/com/example/Animal.java
+++ b/src/main/java/com/example/Animal.java
@@ -1,20 +1,20 @@
-package com.example;
-
-import java.util.List;
-
-public class Animal {
-
- public List 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 getFood(String type) throws Exception {
+ if ("Хищник".equals(type)) {
+ return List.of("Животные", "Птицы", "Рыба");
+ } else if ("Травоядное".equals(type)) {
+ return List.of("Трава", "Различные растения");
+ } else {
+ throw new Exception("Неизвестный вид животного, используйте значение Травоядное или Хищник");
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/example/Cat.java b/src/main/java/com/example/Cat.java
index cc0dd35..8f21ad2 100644
--- a/src/main/java/com/example/Cat.java
+++ b/src/main/java/com/example/Cat.java
@@ -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 getFood() throws Exception {
- return predator.eatMeat();
+ return feline.eatMeat();
}
}
\ No newline at end of file
diff --git a/src/main/java/com/example/Lion.java b/src/main/java/com/example/Lion.java
index 1ad6354..af282b1 100644
--- a/src/main/java/com/example/Lion.java
+++ b/src/main/java/com/example/Lion.java
@@ -4,10 +4,10 @@
public class Lion {
- private boolean hasMane;
- private Feline feline;
+ private final Predator predator;
+ 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)) {
@@ -15,18 +15,18 @@ public Lion(String sex, Feline feline) throws Exception {
} 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 getFood() throws Exception {
- return feline.eatMeat();
+ return predator.eatMeat();
}
}
\ No newline at end of file
diff --git a/src/main/java/com/example/Predator.java b/src/main/java/com/example/Predator.java
index 02e6cfd..c0ea86d 100644
--- a/src/main/java/com/example/Predator.java
+++ b/src/main/java/com/example/Predator.java
@@ -3,7 +3,6 @@
import java.util.List;
public interface Predator {
-
List eatMeat() throws Exception;
-
-}
+ int getKittens();
+}
\ No newline at end of file
diff --git a/src/test/java/com/example/AnimalTest.java b/src/test/java/com/example/AnimalTest.java
new file mode 100644
index 0000000..979af1f
--- /dev/null
+++ b/src/test/java/com/example/AnimalTest.java
@@ -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 expected = List.of("Животные", "Птицы", "Рыба");
+ List actual = animal.getFood("Хищник");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetFoodHerbivore() throws Exception {
+ List expected = List.of("Трава", "Различные растения");
+ List actual = animal.getFood("Травоядное");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetFoodUnknown() {
+ Exception exception = assertThrows(Exception.class, () -> {
+ animal.getFood("Неизвестное");
+ });
+ assertTrue(exception.getMessage().contains("Неизвестный вид животного"));
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/example/CatTest.java b/src/test/java/com/example/CatTest.java
index 304d6c7..1f76986 100644
--- a/src/test/java/com/example/CatTest.java
+++ b/src/test/java/com/example/CatTest.java
@@ -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 food = cat.getFood();
+ @Test
+ void testGetFoodReturnsExpected() throws Exception {
+ List expected = List.of("Животные", "Птицы", "Рыба");
+ when(feline.eatMeat()).thenReturn(expected);
+ List 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();
}
}
\ No newline at end of file
diff --git a/src/test/java/com/example/LionTest.java b/src/test/java/com/example/LionTest.java
index f8fc6ed..df5fa3a 100644
--- a/src/test/java/com/example/LionTest.java
+++ b/src/test/java/com/example/LionTest.java
@@ -1,54 +1,56 @@
package com.example;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
import java.util.List;
+
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.when;
-class LionTest {
+public class LionTest {
- @Test
- void doesHaveManeReturnsTrueForMale() throws Exception {
- Feline felineMock = mock(Feline.class);
- Lion lion = new Lion("Самец", felineMock);
- assertTrue(lion.doesHaveMane());
+ private Predator predator;
+
+ @BeforeEach
+ void setUp() {
+ predator = Mockito.mock(Predator.class);
}
@Test
- void doesHaveManeReturnsFalseForFemale() throws Exception {
- Feline felineMock = mock(Feline.class);
- Lion lion = new Lion("Самка", felineMock);
- assertFalse(lion.doesHaveMane());
+ void testDoesHaveManeMale() throws Exception {
+ Lion male = new Lion("Самец", predator);
+ assertTrue(male.doesHaveMane());
}
@Test
- void getFoodCallsFelineEatMeat() throws Exception {
- Feline felineMock = mock(Feline.class);
- when(felineMock.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
-
- Lion lion = new Lion("Самец", felineMock);
- List food = lion.getFood();
-
- assertEquals(List.of("Животные", "Птицы", "Рыба"), food);
- verify(felineMock, times(1)).eatMeat();
+ void testDoesHaveManeFemale() throws Exception {
+ Lion female = new Lion("Самка", predator);
+ assertFalse(female.doesHaveMane());
}
@Test
- void getKittensCallsFeline() throws Exception {
- Feline felineMock = mock(Feline.class);
- when(felineMock.getKittens()).thenReturn(3);
+ void testGetKittens() throws Exception {
+ when(predator.getKittens()).thenReturn(2);
+ Lion lion = new Lion("Самец", predator);
+ assertEquals(2, lion.getKittens());
+ }
- Lion lion = new Lion("Самец", felineMock);
- int kittens = lion.getKittens();
+ @Test
+ void testGetFood() throws Exception {
+ List expected = List.of("Животные", "Птицы", "Рыба");
+ when(predator.eatMeat()).thenReturn(expected);
- assertEquals(3, kittens);
- verify(felineMock, times(1)).getKittens();
+ Lion lion = new Lion("Самец", predator);
+ assertEquals(expected, lion.getFood());
}
@Test
- void constructorThrowsExceptionForInvalidSex() {
- Feline felineMock = mock(Feline.class);
- Exception exception = assertThrows(Exception.class, () -> new Lion("Неизвестно", felineMock));
+ void testInvalidSexThrowsException() {
+ Exception exception = assertThrows(Exception.class, () -> {
+ new Lion("Неизвестно", predator);
+ });
assertEquals("Используйте допустимые значения пола животного - Самец или Самка", exception.getMessage());
}
}
\ No newline at end of file
diff --git a/target/classes/read.me b/target/classes/read.me
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/target/classes/read.me
@@ -0,0 +1 @@
+
diff --git a/target/jacoco.exec b/target/jacoco.exec
new file mode 100644
index 0000000..e48c209
Binary files /dev/null and b/target/jacoco.exec differ
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..58eb05d
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1,5 @@
+com\example\Predator.class
+com\example\Animal.class
+com\example\Cat.class
+com\example\Lion.class
+com\example\Feline.class
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..0efdd2a
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,5 @@
+C:\Users\SiberiaSOFT\qa_java\src\main\java\com\example\Animal.java
+C:\Users\SiberiaSOFT\qa_java\src\main\java\com\example\Cat.java
+C:\Users\SiberiaSOFT\qa_java\src\main\java\com\example\Feline.java
+C:\Users\SiberiaSOFT\qa_java\src\main\java\com\example\Lion.java
+C:\Users\SiberiaSOFT\qa_java\src\main\java\com\example\Predator.java
diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
new file mode 100644
index 0000000..4d81623
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
@@ -0,0 +1,5 @@
+com\example\FelineTest.class
+com\example\CatTest.class
+com\example\AnimalTest.class
+com\example\LionParameterizedTest.class
+com\example\LionTest.class
diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
new file mode 100644
index 0000000..75f9f9a
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
@@ -0,0 +1,5 @@
+C:\Users\SiberiaSOFT\qa_java\src\test\java\com\example\AnimalTest.java
+C:\Users\SiberiaSOFT\qa_java\src\test\java\com\example\CatTest.java
+C:\Users\SiberiaSOFT\qa_java\src\test\java\com\example\FelineTest.java
+C:\Users\SiberiaSOFT\qa_java\src\test\java\com\example\LionParameterizedTest.java
+C:\Users\SiberiaSOFT\qa_java\src\test\java\com\example\LionTest.java
diff --git a/target/site/jacoco/com.example/Animal.html b/target/site/jacoco/com.example/Animal.html
index 8f0d449..83c4ac7 100644
--- a/target/site/jacoco/com.example/Animal.html
+++ b/target/site/jacoco/com.example/Animal.html
@@ -1 +1 @@
-AnimalAnimal
| Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods |
| Total | 2 of 27 | 92 % | 0 of 4 | 100 % | 1 | 5 | 1 | 7 | 1 | 3 |
| getFamily() |  | 0 % | | n/a | 1 | 1 | 1 | 1 | 1 | 1 |
| getFood(String) |  | 100 % |  | 100 % | 0 | 3 | 0 | 5 | 0 | 1 |
| Animal() |  | 100 % | | n/a | 0 | 1 | 0 | 1 | 0 | 1 |
\ No newline at end of file
+AnimalAnimal
| Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods |
| Total | 0 of 27 | 100 % | 0 of 4 | 100 % | 0 | 5 | 0 | 7 | 0 | 3 |
| getFood(String) |  | 100 % |  | 100 % | 0 | 3 | 0 | 5 | 0 | 1 |
| Animal() |  | 100 % | | n/a | 0 | 1 | 0 | 1 | 0 | 1 |
| getFamily() |  | 100 % | | n/a | 0 | 1 | 0 | 1 | 0 | 1 |
\ No newline at end of file
diff --git a/target/site/jacoco/com.example/Animal.java.html b/target/site/jacoco/com.example/Animal.java.html
index daaf287..113fe1f 100644
--- a/target/site/jacoco/com.example/Animal.java.html
+++ b/target/site/jacoco/com.example/Animal.java.html
@@ -4,18 +4,18 @@
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 "Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи";
}
- 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("Неизвестный вид животного, используйте значение Травоядное или Хищник");
+ }
}
}
-