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
57 changes: 55 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
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>

<groupId>org.example</groupId>
Expand All @@ -11,6 +13,57 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.13.2</junit.version>
<mockito.version>5.12.0</mockito.version>
<jacoco.version>0.8.12</jacoco.version>
</properties>

</project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<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>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
59 changes: 59 additions & 0 deletions src/test/java/praktikum/BurgerParameterizedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package praktikum;

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

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(Parameterized.class)
public class BurgerParameterizedTest {

private final float bunPrice;
private final float ingredientOnePrice;
private final float ingredientTwoPrice;
private final float expectedPrice;

public BurgerParameterizedTest(float bunPrice,
float ingredientOnePrice,
float ingredientTwoPrice,
float expectedPrice) {
this.bunPrice = bunPrice;
this.ingredientOnePrice = ingredientOnePrice;
this.ingredientTwoPrice = ingredientTwoPrice;
this.expectedPrice = expectedPrice;
}

@Parameterized.Parameters(name = "bun={0}, ingredient1={1}, ingredient2={2}, expected={3}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{100f, 50f, 25f, 275f},
{200f, 100f, 300f, 800f},
{300f, 0f, 100f, 700f}
});
}

@Test
public void getPriceShouldReturnCorrectPrice() {
Burger burger = new Burger();

Bun bun = mock(Bun.class);
Ingredient ingredientOne = mock(Ingredient.class);
Ingredient ingredientTwo = mock(Ingredient.class);

when(bun.getPrice()).thenReturn(bunPrice);
when(ingredientOne.getPrice()).thenReturn(ingredientOnePrice);
when(ingredientTwo.getPrice()).thenReturn(ingredientTwoPrice);

burger.setBuns(bun);
burger.addIngredient(ingredientOne);
burger.addIngredient(ingredientTwo);

assertEquals(expectedPrice, burger.getPrice(), 0.0f);
}
}
138 changes: 138 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package praktikum;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {

private Burger burger;

@Mock
private Bun bun;

@Mock
private Ingredient ingredient;

@Before
public void setUp() {
burger = new Burger();
}

@Test
public void setBunsShouldSetBun() {
burger.setBuns(bun);

assertSame(bun, burger.bun);
}

@Test
public void addIngredientShouldAddIngredientToList() {
burger.addIngredient(ingredient);

assertEquals(Collections.singletonList(ingredient), burger.ingredients);
}

@Test
public void removeIngredientShouldRemoveIngredientByIndex() {
Ingredient first = mock(Ingredient.class);
Ingredient second = mock(Ingredient.class);

burger.addIngredient(first);
burger.addIngredient(second);

burger.removeIngredient(0);

assertEquals(Collections.singletonList(second), burger.ingredients);
}

@Test
public void moveIngredientShouldMoveIngredientToNewIndex() {
Ingredient first = mock(Ingredient.class);
Ingredient second = mock(Ingredient.class);
Ingredient third = mock(Ingredient.class);

burger.addIngredient(first);
burger.addIngredient(second);
burger.addIngredient(third);

burger.moveIngredient(0, 2);

assertEquals(Arrays.asList(second, third, first), burger.ingredients);
}

@Test
public void getPriceShouldReturnOnlyBunsPriceWhenNoIngredients() {
when(bun.getPrice()).thenReturn(100f);

burger.setBuns(bun);

assertEquals(200f, burger.getPrice(), 0.0f);
}

@Test
public void getReceiptShouldReturnCorrectReceiptWithoutIngredients() {
when(bun.getName()).thenReturn("white bun");
when(bun.getPrice()).thenReturn(200f);

burger.setBuns(bun);

String expected = String.format(
"(==== %s ====)%n" +
"(==== %s ====)%n" +
"%nPrice: %f%n",
"white bun",
"white bun",
400f
);

assertEquals(expected, burger.getReceipt());
}

@Test
public void getReceiptShouldReturnCorrectReceipt() {
Ingredient sauce = mock(Ingredient.class);
Ingredient filling = mock(Ingredient.class);

when(bun.getName()).thenReturn("black bun");
when(bun.getPrice()).thenReturn(100f);

when(sauce.getType()).thenReturn(IngredientType.SAUCE);
when(sauce.getName()).thenReturn("hot sauce");
when(sauce.getPrice()).thenReturn(100f);

when(filling.getType()).thenReturn(IngredientType.FILLING);
when(filling.getName()).thenReturn("cutlet");
when(filling.getPrice()).thenReturn(100f);

burger.setBuns(bun);
burger.addIngredient(sauce);
burger.addIngredient(filling);

String expected = String.format(
"(==== %s ====)%n" +
"= %s %s =%n" +
"= %s %s =%n" +
"(==== %s ====)%n" +
"%nPrice: %f%n",
"black bun",
"sauce", "hot sauce",
"filling", "cutlet",
"black bun",
400f
);

assertEquals(expected, burger.getReceipt());
}
}
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">201 of 358</td><td class="ctr2">43 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">12</td><td class="ctr2">22</td><td class="ctr1">43</td><td class="ctr2">69</td><td class="ctr1">12</td><td class="ctr2">20</td><td class="ctr1">4</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="67" height="10" title="201" alt="201"/><img src="jacoco-resources/greenbar.gif" width="52" height="10" title="157" alt="157"/></td><td class="ctr2" id="c0">43 %</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">12</td><td class="ctr2" id="g0">22</td><td class="ctr1" id="h0">43</td><td class="ctr2" id="i0">69</td><td class="ctr1" id="j0">12</td><td class="ctr2" id="k0">20</td><td class="ctr1" id="l0">4</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.12.202403310830</span></div></body></html>
Binary file added target/site/jacoco/jacoco-resources/branchfc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/branchnc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/branchpc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/bundle.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/class.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/down.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/greenbar.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/group.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/method.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/site/jacoco/jacoco-resources/package.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions target/site/jacoco/jacoco-resources/prettify.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Pretty printing styles. Used with prettify.js. */

.str { color: #2A00FF; }
.kwd { color: #7F0055; font-weight:bold; }
.com { color: #3F5FBF; }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }
Loading