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
42 changes: 42 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,47 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.19.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<!--id выбираешь самостоятельно-->
<id>prepare-agent</id>
<!--в какой фазе maven будет выполняться цель-->
<phase>initialize</phase>
<!--цель jacoco, которую нужно выполнить-->
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
59 changes: 59 additions & 0 deletions src/test/java/praktikum/BurgerPriceParameterizedTest.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 org.mockito.Mockito;

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

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

@RunWith(Parameterized.class)
public class BurgerPriceParameterizedTest {


private final float bunPrice;
private final float[] ingredientPrices;
private final float expectedTotalPrice;


public BurgerPriceParameterizedTest(float bunPrice, float[] ingredientPrices, float expectedTotalPrice) {
this.bunPrice = bunPrice;
this.ingredientPrices = ingredientPrices;
this.expectedTotalPrice = expectedTotalPrice;
}


@Parameterized.Parameters(name = "Цена бургера (булка: {0}, ингредиенты: {1}) = {2}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{

{10.0f, new float[]{}, 20.0f},
{100.0f, new float[]{50.0f}, 250.0f},
{125.5f, new float[]{200.0f, 25.5f}, 476.5f}
});
}

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


Bun mockBun = Mockito.mock(Bun.class);
when(mockBun.getPrice()).thenReturn(bunPrice);
burger.setBuns(mockBun);


for (float ingredientPrice : ingredientPrices) {
Ingredient mockIngredient = Mockito.mock(Ingredient.class);
when(mockIngredient.getPrice()).thenReturn(ingredientPrice);
burger.addIngredient(mockIngredient);
}


assertEquals("Расчет цены неверен", expectedTotalPrice, burger.getPrice(), 0.001f);
}
}
119 changes: 119 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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 static org.junit.Assert.*;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {

private Burger burger;

@Mock
private Bun mockBun;

@Mock
private Ingredient mockSauce;
@Mock
private Ingredient mockFilling;

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

@Test
public void setBunsShouldSetTheBun() {
burger.setBuns(mockBun);

assertEquals("Булочка не была установлена", mockBun, burger.bun);
}


@Test
public void addIngredientShouldIncreaseListSize() {
burger.addIngredient(mockSauce);

assertEquals("Размер списка должен быть 1", 1, burger.ingredients.size());
}

@Test
public void addIngredientShouldAddCorrectIngredient() {
burger.addIngredient(mockSauce);

assertSame("Добавлен неверный ингредиент", mockSauce, burger.ingredients.get(0));
}


@Test
public void removeIngredientShouldDecreaseListSize() {
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);
burger.removeIngredient(0);

assertEquals("Размер списка должен быть 1 после удаления", 1, burger.ingredients.size());
}

@Test
public void removeIngredientShouldRemoveCorrectIngredient() {
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);
burger.removeIngredient(0);

assertSame("Оставшийся ингредиент неверен", mockFilling, burger.ingredients.get(0));
}


@Test
public void moveIngredientShouldPlaceIngredientAtNewIndex() {
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);
burger.moveIngredient(0, 1);

assertSame("Соус должен быть на новой позиции", mockSauce, burger.ingredients.get(1));
}

@Test
public void moveIngredientShouldShiftOtherIngredient() {
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);
burger.moveIngredient(0, 1);

assertSame("Начинка должна была сдвинуться", mockFilling, burger.ingredients.get(0));
}

@Test
public void getReceiptShouldReturnCorrectString() {

when(mockBun.getName()).thenReturn("Краторная булка");
when(mockBun.getPrice()).thenReturn(100.0f);
when(mockSauce.getType()).thenReturn(IngredientType.SAUCE);
when(mockSauce.getName()).thenReturn("Соус галактический");
when(mockSauce.getPrice()).thenReturn(20.5f);
when(mockFilling.getType()).thenReturn(IngredientType.FILLING);
when(mockFilling.getName()).thenReturn("Котлета");
when(mockFilling.getPrice()).thenReturn(150.0f);

burger.setBuns(mockBun);
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);

float expectedPrice = 100.0f * 2 + 20.5f + 150.0f;
String expectedReceipt = String.format("(==== Краторная булка ====)%n" +
"= sauce Соус галактический =%n" +
"= filling Котлета =%n" +
"(==== Краторная булка ====)%n" +
"%nPrice: %f%n", expectedPrice);


String actualReceipt = burger.getReceipt();


assertEquals("Сгенерированный чек не соответствует ожидаемому", expectedReceipt, actualReceipt);
}
}

Choose a reason for hiding this comment

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

⛔️Нужно исправить. нет отчета о тестировании

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.7.202105040129</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