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
55 changes: 51 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,73 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>untitled</artifactId>
<artifactId>MockProject</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<mockito.version>4.8.0</mockito.version>
<junit.version>4.13.2</junit.version>
<java.version>11</java.version>
<mvn.version>3.8.1</mvn.version>
</properties>

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

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>${mvn.version}</version>
<configuration>
<source>11</source>
<target>11</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Cat {

Predator predator;

public Cat(Feline feline) {
public Cat(Feline feline) { // Feline реализует интерфейс Predator
this.predator = feline;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/example/Feline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public int getKittens() {
public int getKittens(int kittensCount) {
return kittensCount;
}

}
9 changes: 5 additions & 4 deletions src/main/java/com/example/Lion.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
public class Lion {

boolean hasMane;
private final Feline feline;

public Lion(String sex) throws Exception {
public Lion(String sex, Feline feline) throws Exception {
if ("Самец".equals(sex)) {
hasMane = true;
} else if ("Самка".equals(sex)) {
hasMane = false;
} else {
throw new Exception("Используйте допустимые значения пола животного - самей или самка");
throw new Exception("Используйте допустимые значения пола животного - самец или самка");
}
}
this.feline = feline;

Feline feline = new Feline();

}
public int getKittens() {
return feline.getKittens();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/example/Predator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
public interface Predator {

List<String> eatMeat() throws Exception;

}
34 changes: 34 additions & 0 deletions src/test/java/CatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.example.Cat;
import com.example.Feline;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.List;
import static org.junit.Assert.assertEquals;

@RunWith(MockitoJUnitRunner.class)

public class CatTest {
@Mock

private Feline feline;

@Test
public void getSoundTest () {

Cat cat = new Cat(feline);
String sound = cat.getSound();
assertEquals("Мяу", sound);

}
@Test
public void getFoodTest () throws Exception {
Cat cat = new Cat(feline);
Mockito.when(feline.eatMeat()).thenReturn(List.of("Животные", "Птицы", "Рыба"));
List<String> expectedResult = List.of("Животные", "Птицы", "Рыба");
List<String> actualResult = cat.getFood();
assertEquals("Некорректный результат вызова метода", expectedResult, actualResult);
}
}
31 changes: 31 additions & 0 deletions src/test/java/FelineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


import com.example.Feline;
import org.junit.Test;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class FelineTest {
private Feline feline;

@Test
public void getFamilyTest() {
Feline feline = new Feline();
String family = feline.getFamily();
assertEquals("Кошачьи",family);

}
@Test
public void getKittensDefaultTest () {
Feline feline = new Feline();
assertEquals (1, feline.getKittens());
}
@Test
public void getEatMeat () throws Exception {
Feline feline = new Feline();
List<String> expectedFood = List.of("Животные", "Птицы", "Рыба");
List<String> actualFood= feline.eatMeat();
assertEquals("Некорректный результат вызова метода", expectedFood, actualFood);
}
}
39 changes: 39 additions & 0 deletions src/test/java/LionSexTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import com.example.Feline;
import com.example.Lion;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@RunWith(Parameterized.class)
public class LionSexTest {

@Mock
private Feline feline;

private final String invalidSex;

public LionSexTest(String invalidSex) {
this.invalidSex = invalidSex;
}
@Parameterized.Parameters (name = "Пол: {0}")
public static Object[][] getSex() {
return new Object[][]{
{"123"},
{null},
{"Львенок"},

};
}
@Before
public void init () {
MockitoAnnotations.initMocks(this);
}

@Test(expected = Exception.class)
public void throwExceptionForInvalidSex () throws Exception {
new Lion(invalidSex, feline);
}
}
46 changes: 46 additions & 0 deletions src/test/java/LionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import com.example.Feline;
import com.example.Lion;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;

import static org.junit.Assert.*;

@RunWith(MockitoJUnitRunner.class)

public class LionTest {
@Mock

private Feline feline;


@Test
public void getKittensTest () throws Exception {
Lion lion = new Lion("Самка", feline);
Mockito.when(feline.getKittens()).thenReturn(1);
int actualKittens = lion.getKittens();
assertEquals (1, actualKittens);
}

@Test
public void getFoodTest () throws Exception {
Lion lion = new Lion("Самец", feline);
List<String> expectedFood = List.of("Животные", "Птицы", "Рыба");
Mockito.when(feline.getFood("Хищник")).thenReturn(expectedFood);
List<String> actualResult = lion.getFood();
assertEquals("Некорректный результат вызова метода", expectedFood, actualResult);
}

@Test
public void doesHaveManeTest () throws Exception {
Lion lion = new Lion("Самец",feline);
boolean expectedMane = true;
boolean actualMane = lion.doesHaveMane();
assertEquals(expectedMane, actualMane);
}
}

Binary file added target/jacoco.exec
Binary file not shown.
1 change: 1 addition & 0 deletions target/site/jacoco/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="jacoco-resources/report.gif" type="image/gif"/><title>MockProject</title><script type="text/javascript" src="jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb', 'coveragetable'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="jacoco-sessions.html" class="el_session">Sessions</a></span><span class="el_report">MockProject</span></div><h1>MockProject</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td><td class="sortable ctr1" id="l" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="m" onclick="toggleSort(this)">Classes</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">11 of 93</td><td class="ctr2">88 %</td><td class="bar">2 of 8</td><td class="ctr2">75 %</td><td class="ctr1">3</td><td class="ctr2">19</td><td class="ctr1">3</td><td class="ctr2">28</td><td class="ctr1">1</td><td class="ctr2">15</td><td class="ctr1">0</td><td class="ctr2">4</td></tr></tfoot><tbody><tr><td id="a0"><a href="com.example/index.html" class="el_package">com.example</a></td><td class="bar" id="b0"><img src="jacoco-resources/redbar.gif" width="14" height="10" title="11" alt="11"/><img src="jacoco-resources/greenbar.gif" width="105" height="10" title="82" alt="82"/></td><td class="ctr2" id="c0">88 %</td><td class="bar" id="d0"><img src="jacoco-resources/redbar.gif" width="30" height="10" title="2" alt="2"/><img src="jacoco-resources/greenbar.gif" width="90" height="10" title="6" alt="6"/></td><td class="ctr2" id="e0">75 %</td><td class="ctr1" id="f0">3</td><td class="ctr2" id="g0">19</td><td class="ctr1" id="h0">3</td><td class="ctr2" id="i0">28</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">15</td><td class="ctr1" id="l0">0</td><td class="ctr2" id="m0">4</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>
1 change: 1 addition & 0 deletions target/site/jacoco/jacoco-sessions.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions target/site/jacoco/jacoco.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
MockProject,com.example,Feline,0,15,0,0,0,5,0,5,0,5
MockProject,com.example,Animal,11,16,2,2,3,4,3,2,1,2
MockProject,com.example,Lion,0,39,0,4,0,11,0,6,0,4
MockProject,com.example,Cat,0,12,0,0,0,5,0,3,0,3
Loading