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
80 changes: 79 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,84 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.version>0.8.11</jacoco.version>
</properties>

</project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- JaCoCo Plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<propertyName>surefire.jacoco.args</propertyName>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<!-- Surefire Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<argLine>${surefire.jacoco.args}</argLine>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
33 changes: 33 additions & 0 deletions src/test/java/praktikum/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;

public class BunTest {

@Test
public void getNameIsSuccess() {
String bunName = "bunName";
Bun bun = new Bun(bunName, 100);

MatcherAssert.assertThat(
"Получено некорректное наименование булочки",
bun.getName(),
equalTo(bunName)
);
}

@Test
public void getPriceIsSuccess() {
float bunPrice = 100;
Bun bun = new Bun("bunName", bunPrice);

MatcherAssert.assertThat(
"Получена некорректная стоимость булочки",
bun.getPrice(),
equalTo(bunPrice)
);
}
}
118 changes: 118 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {
@Mock
private Bun bun;
@Mock
private Ingredient ingredient;
@Mock
private Ingredient ingredient2;

@Test
public void setBunsIsSuccess() {
Burger burger = new Burger();
Mockito.when(bun.getName()).thenReturn("bunName");
burger.setBuns(bun);

MatcherAssert.assertThat(
"В бургер не добавляются передаваемые булочки",
bun.getName(),
equalTo(burger.bun.getName())
);
}
@Test
public void addIngredientIsSuccess() {
Burger burger = new Burger();
burger.addIngredient(ingredient);

assertTrue(
"Ингредиент не добавлен",
burger.ingredients.contains(ingredient)
);
}
@Test
public void moveIngredientIsSuccess() {
Mockito.when(ingredient.getName()).thenReturn("ingredientName");

Burger burger = new Burger();
burger.addIngredient(ingredient);
burger.addIngredient(ingredient2);
int currentIndex = burger.ingredients.indexOf(ingredient);
int newIndex = burger.ingredients.indexOf(ingredient2);

burger.moveIngredient(currentIndex, newIndex);

MatcherAssert.assertThat(
"Ингредиент не перемещается",
ingredient.getName(),
equalTo(burger.ingredients.get(newIndex).getName())
);
}
@Test
public void removeIngredientIsSuccess() {
Burger burger = new Burger();
burger.addIngredient(ingredient);

int index = burger.ingredients.indexOf(ingredient);
burger.removeIngredient(index);

assertFalse(
"Ингредиент не удаляется",
burger.ingredients.contains(ingredient)
);
}
@Test
public void getPriceIsSuccess() {
Mockito.when(bun.getPrice()).thenReturn(100f);
Mockito.when(ingredient.getPrice()).thenReturn(250f);

Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredient);

MatcherAssert.assertThat(
"Цена расчитывается некорректно",
450f,
equalTo(burger.getPrice())
);

}
@Test
public void getReceiptIsSuccess() {
Mockito.when(bun.getName()).thenReturn("bunName");
Mockito.when(bun.getPrice()).thenReturn(80f);
Mockito.when(ingredient.getName()).thenReturn("ingredientName");
Mockito.when(ingredient.getPrice()).thenReturn(100f);
Mockito.when(ingredient.getType()).thenReturn(IngredientType.FILLING);

String lineSeparator = System.lineSeparator();
String expectedReceipt =
"(==== bunName ====)" + lineSeparator +
"= filling ingredientName =" + lineSeparator +
"(==== bunName ====)" + lineSeparator +
lineSeparator +
"Price: 260,000000" + lineSeparator;

Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredient);

MatcherAssert.assertThat(
"Возвращается некорректная строка с рецептом",
burger.getReceipt(),
equalTo(expectedReceipt)
);
}
}
48 changes: 48 additions & 0 deletions src/test/java/praktikum/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;

public class IngredientTest {
private Ingredient ingredient;
private IngredientType expectedIngredientType = IngredientType.SAUCE;
private String expectedName = "sauceName";
private float expectedPrice = 50f;
@Before
public void prepareData() {
this.ingredient = new Ingredient(
expectedIngredientType,
expectedName,
expectedPrice
);
}
@Test
public void getPriceIsSuccess() {
MatcherAssert.assertThat(
"Возвращается некорретная стоимость ингредиента",
ingredient.getPrice(),
equalTo(expectedPrice)

);

}
@Test
public void getNameIsSuccess() {
MatcherAssert.assertThat(
"Возвращается некорректное наименование ингредиента",
ingredient.getName(),
equalTo(expectedName)
);
}
@Test
public void getTypeIsSuccess() {
MatcherAssert.assertThat(
"Возвращается некорректный тип ингредиента",
ingredient.getType(),
equalTo(expectedIngredientType)
);
}
}
33 changes: 33 additions & 0 deletions src/test/java/praktikum/IngredientTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.hamcrest.CoreMatchers.equalTo;

@RunWith(Parameterized.class)
public class IngredientTypeTest {
private final String typeName;

@Parameterized.Parameters(name = "Наличие типа {0}")
public static Object[][] paramsForTest() {
return new Object[][]{
{"SAUCE"},
{"FILLING"}
};
}

public IngredientTypeTest(String typeName) {
this.typeName = typeName;
}

@Test
public void ingredientTypeIsCorrectList() {

MatcherAssert.assertThat("Отсутствует элемент " + typeName,
IngredientType.valueOf(typeName.toUpperCase()).toString(),
equalTo(typeName));
}
}
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>praktikum</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">praktikum</span></div><h1>praktikum</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">165 of 349</td><td class="ctr2">52 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">5</td><td class="ctr2">22</td><td class="ctr1">29</td><td class="ctr2">69</td><td class="ctr1">5</td><td class="ctr2">20</td><td class="ctr1">2</td><td class="ctr2">6</td></tr></tfoot><tbody><tr><td id="a0"><a href="praktikum/index.html" class="el_package">praktikum</a></td><td class="bar" id="b0"><img src="jacoco-resources/redbar.gif" width="56" height="10" title="165" alt="165"/><img src="jacoco-resources/greenbar.gif" width="63" height="10" title="184" alt="184"/></td><td class="ctr2" id="c0">52 %</td><td class="bar" id="d0"><img src="jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="e0">100 %</td><td class="ctr1" id="f0">5</td><td class="ctr2" id="g0">22</td><td class="ctr1" id="h0">29</td><td class="ctr2" id="i0">69</td><td class="ctr1" id="j0">5</td><td class="ctr2" id="k0">20</td><td class="ctr1" id="l0">2</td><td class="ctr2" id="m0">6</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.11.202310140853</span></div></body></html>
1 change: 1 addition & 0 deletions target/site/jacoco/praktikum/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>praktikum</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="index.source.html" class="el_source">Source Files</a><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <span class="el_package">praktikum</span></div><h1>praktikum</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">165 of 349</td><td class="ctr2">52 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">5</td><td class="ctr2">22</td><td class="ctr1">29</td><td class="ctr2">69</td><td class="ctr1">5</td><td class="ctr2">20</td><td class="ctr1">2</td><td class="ctr2">6</td></tr></tfoot><tbody><tr><td id="a2"><a href="Database.html" class="el_class">Database</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="95" height="10" title="106" alt="106"/></td><td class="ctr2" id="c4">0 %</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f0">3</td><td class="ctr2" id="g2">3</td><td class="ctr1" id="h0">15</td><td class="ctr2" id="i1">15</td><td class="ctr1" id="j0">3</td><td class="ctr2" id="k2">3</td><td class="ctr1" id="l0">1</td><td class="ctr2" id="m0">1</td></tr><tr><td id="a5"><a href="Praktikum.html" class="el_class">Praktikum</a></td><td class="bar" id="b1"><img src="../jacoco-resources/redbar.gif" width="53" height="10" title="59" alt="59"/></td><td class="ctr2" id="c5">0 %</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f1">2</td><td class="ctr2" id="g4">2</td><td class="ctr1" id="h1">14</td><td class="ctr2" id="i2">14</td><td class="ctr1" id="j1">2</td><td class="ctr2" id="k4">2</td><td class="ctr1" id="l1">1</td><td class="ctr2" id="m1">1</td></tr><tr><td id="a1"><a href="Burger.html" class="el_class">Burger</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="133" alt="133"/></td><td class="ctr2" id="c0">100 %</td><td class="bar" id="d0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="e0">100 %</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g0">9</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i0">23</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k0">7</td><td class="ctr1" id="l2">0</td><td class="ctr2" id="m2">1</td></tr><tr><td id="a3"><a href="Ingredient.html" class="el_class">Ingredient</a></td><td class="bar" id="b3"><img src="../jacoco-resources/greenbar.gif" width="18" height="10" title="21" alt="21"/></td><td class="ctr2" id="c1">100 %</td><td class="bar" id="d3"/><td class="ctr2" id="e3">n/a</td><td class="ctr1" id="f3">0</td><td class="ctr2" id="g1">4</td><td class="ctr1" id="h3">0</td><td class="ctr2" id="i3">8</td><td class="ctr1" id="j3">0</td><td class="ctr2" id="k1">4</td><td class="ctr1" id="l3">0</td><td class="ctr2" id="m3">1</td></tr><tr><td id="a0"><a href="Bun.html" class="el_class">Bun</a></td><td class="bar" id="b4"><img src="../jacoco-resources/greenbar.gif" width="13" height="10" title="15" alt="15"/></td><td class="ctr2" id="c2">100 %</td><td class="bar" id="d4"/><td class="ctr2" id="e4">n/a</td><td class="ctr1" id="f4">0</td><td class="ctr2" id="g3">3</td><td class="ctr1" id="h4">0</td><td class="ctr2" id="i4">6</td><td class="ctr1" id="j4">0</td><td class="ctr2" id="k3">3</td><td class="ctr1" id="l4">0</td><td class="ctr2" id="m4">1</td></tr><tr><td id="a4"><a href="IngredientType.html" class="el_class">IngredientType</a></td><td class="bar" id="b5"><img src="../jacoco-resources/greenbar.gif" width="13" height="10" title="15" alt="15"/></td><td class="ctr2" id="c3">100 %</td><td class="bar" id="d5"/><td class="ctr2" id="e5">n/a</td><td class="ctr1" id="f5">0</td><td class="ctr2" id="g5">1</td><td class="ctr1" id="h5">0</td><td class="ctr2" id="i5">3</td><td class="ctr1" id="j5">0</td><td class="ctr2" id="k5">1</td><td class="ctr1" id="l5">0</td><td class="ctr2" id="m5">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.11.202310140853</span></div></body></html>
Loading