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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Compiled files
*.class

# Build folders
target/*
!target/site/
target/site/*
!target/site/jacoco/
build/
out/

# IDE files
.idea/
*.iml
*.iws
*.ipr
.settings/
.classpath
.project
.factorypath

# VS Code
.vscode/

# Logs
*.log

# Test reports
test-output/
allure-results/
allure-report/

# OS files
.DS_Store
Thumbs.db

# Maven
dependency-reduced-pom.xml

# Backup files
*~
*.bak
39 changes: 39 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,44 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>

<!-- Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- JaCoCo -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package praktikum;

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

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(Parameterized.class)
public class BurgerMovingIngredientParameterizedTest {

private Burger burger;
private final int index;
private final int newIndex;

public BurgerMovingIngredientParameterizedTest(int index, int newIndex) {
this.index = index;
this.newIndex = newIndex;
}

@Parameterized.Parameters(name = "С {0} на {1}")
public static Object[][] data() {
return new Object[][]{
{0, 2}, // с первого на третье место
{2, 0}, // с третьего на первое
{1, 1} // оставить на месте
};
}

@Before
public void setUp() {
burger = new Burger();
burger.addIngredient(mock(Ingredient.class)); // ингр 0
burger.addIngredient(mock(Ingredient.class)); // ингр 1
burger.addIngredient(mock(Ingredient.class)); // ингр 2
}

@Test
public void testMoveIngredient() {
Ingredient toMove = burger.ingredients.get(index); //запоминаем, что мы двигаем(разное каждый раз)

burger.moveIngredient(index, newIndex); //собственно, двигаем

assertEquals(toMove, burger.ingredients.get(newIndex)); //чекаем, чтобы то, что мы сдвинули (toMove) был на новом месте
}
}
97 changes: 97 additions & 0 deletions src/test/java/praktikum/BurgerTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package praktikum;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class BurgerTests {

Burger burger;

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

@Test
public void setBunsTest() {
Bun mockBun = mock(Bun.class);
burger.setBuns(mockBun);
assertEquals(burger.bun, mockBun);
}


@Test
public void addIngredientAddsCorrectIngredientTest() {
Ingredient mockIngredient = mock(Ingredient.class);
burger.addIngredient(mockIngredient);
assertTrue(burger.ingredients.contains(mockIngredient));
}

@Test
public void removeIngredientRemovesCorrectIngredientTest() {
Ingredient firstIngredient = mock(Ingredient.class);
Ingredient secondIngredient = mock(Ingredient.class);

burger.addIngredient(firstIngredient);
burger.addIngredient(secondIngredient);
burger.removeIngredient(0);

assertFalse(burger.ingredients.contains(firstIngredient));
}

@Test
public void getPriceTest() {
//создаю кучу моков и стабов, чтобы использовать
Bun mockBun = mock(Bun.class);
when(mockBun.getPrice()).thenReturn(70f);

Ingredient firstIngredient = mock(Ingredient.class);
when(firstIngredient.getPrice()).thenReturn(40f);

Ingredient secondIngredient = mock(Ingredient.class);
when(secondIngredient.getPrice()).thenReturn(30f);

//вот тут уже собственно использую моки
burger.setBuns(mockBun);
burger.addIngredient(firstIngredient);
burger.addIngredient(secondIngredient);

//проверяю, чтобы результат совпадал с тем, который должен быть
assertEquals(210f, burger.getPrice(), 0.01);
}

@Test
public void getReceiptTest() {
//мок булки
Bun mockBun = mock(Bun.class);
when(mockBun.getName()).thenReturn("black bun");
when(mockBun.getPrice()).thenReturn(100f);

//мок для соуса (SAUCE)
Ingredient mockSauce = mock(Ingredient.class);
when(mockSauce.getType()).thenReturn(IngredientType.SAUCE);
when(mockSauce.getName()).thenReturn("hot sauce");
when(mockSauce.getPrice()).thenReturn(100f);

//мок для начинки (FILLING)
Ingredient mockFilling = mock(Ingredient.class);
when(mockFilling.getType()).thenReturn(IngredientType.FILLING);
when(mockFilling.getName()).thenReturn("cutlet");
when(mockFilling.getPrice()).thenReturn(100f);

burger.setBuns(mockBun);
burger.addIngredient(mockSauce);
burger.addIngredient(mockFilling);
String lineSeparator = System.lineSeparator();
String expected = "(==== black bun ====)" + lineSeparator +
"= sauce hot sauce =" + lineSeparator +
"= filling cutlet =" + lineSeparator +
"(==== black bun ====)" + lineSeparator +
lineSeparator +
"Price: 400.000000" + lineSeparator;

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="en"><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.11.202310140853</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