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
24 changes: 24 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,49 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<configuration>
<excludes>
<exclude>praktikum/Database.class</exclude>
<exclude>praktikum/Praktikum.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.20.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

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

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class BunTest {

@Test
public void getNameReturnCorrectName() {
Bun bun = new Bun("white bun", 200.0f);
String actualName = bun.getName();
assertEquals("white bun", actualName);
}

@Test
public void getPriceReturnCorrectPrice() {
Bun bun = new Bun("white bun", 300.0f);
float actualPrice = bun.getPrice();
assertEquals(300.0f, actualPrice, 0.0f);
}
}
114 changes: 114 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package praktikum;

import org.junit.Before;
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.junit.Assert.*;

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {

@Mock
private Bun bun;
@Mock
private Ingredient ingredient1;
@Mock
private Ingredient ingredient2;

private Burger burger;

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

@Test
public void setsBun() {
Mockito.when(bun.getName()).thenReturn("тестовая булка");
assertTrue(burger.getReceipt().contains("тестовая булка"));
}

@Test
public void addsIngredient() {
burger.addIngredient(ingredient1);

Mockito.when(bun.getName()).thenReturn("тестовая булка");
Mockito.when(ingredient1.getType()).thenReturn(IngredientType.FILLING);
Mockito.when(ingredient1.getName()).thenReturn("тестовый ингредиент");
assertTrue(burger.getReceipt().contains("= filling тестовый ингредиент ="));
}

@Test
public void removesIngredient() {
Mockito.when(ingredient1.getName()).thenReturn("удаляемый ингредиент");
Mockito.when(ingredient1.getType()).thenReturn(IngredientType.FILLING);
Mockito.when(bun.getName()).thenReturn("тестовая булка");

burger.addIngredient(ingredient1);
assertTrue(burger.getReceipt().contains("удаляемый ингредиент"));

burger.removeIngredient(0);
assertFalse(burger.getReceipt().contains("удаляемый ингредиент"));
}

@Test
public void movesIngredient() {
Mockito.when(bun.getName()).thenReturn("тестовая булка");
Mockito.when(ingredient1.getName()).thenReturn("ингредиент A");
Mockito.when(ingredient1.getType()).thenReturn(IngredientType.SAUCE);
Mockito.when(ingredient2.getName()).thenReturn("ингредиент B");
Mockito.when(ingredient2.getType()).thenReturn(IngredientType.FILLING);

burger.addIngredient(ingredient1);
burger.addIngredient(ingredient2);

burger.moveIngredient(0, 1);

String receipt = burger.getReceipt();

assertTrue(receipt.indexOf("ингредиент B") < receipt.indexOf("ингредиент A"));
}

@Test
public void calculatesPrice() {
Mockito.when(bun.getPrice()).thenReturn(100f);
Mockito.when(ingredient1.getPrice()).thenReturn(50f);
Mockito.when(ingredient2.getPrice()).thenReturn(200f);

burger.addIngredient(ingredient1);
burger.addIngredient(ingredient2);

float actualPrice = burger.getPrice();

assertEquals(450f, actualPrice, 0.0f);
}

@Test
public void generatesFormattedReceipt() {
Mockito.when(bun.getName()).thenReturn("тестовая булка");
Mockito.when(bun.getPrice()).thenReturn(125.5f);

Mockito.when(ingredient1.getType()).thenReturn(IngredientType.SAUCE);
Mockito.when(ingredient1.getName()).thenReturn("тестовый соус");
Mockito.when(ingredient1.getPrice()).thenReturn(15.0f);

burger.addIngredient(ingredient1);

float expectedPrice = 125.5f * 2 + 15.0f;

String expectedReceipt = String.format(
"(==== тестовая булка ====)%n" +
"= sauce тестовый соус =%n" +
"(==== тестовая булка ====)%n" +
"%nPrice: %f%n", expectedPrice
);

String actualReceipt = burger.getReceipt();

assertEquals(expectedReceipt, actualReceipt);
}
}
41 changes: 41 additions & 0 deletions src/test/java/praktikum/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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;

@RunWith(Parameterized.class)
public class IngredientTest {

private final IngredientType type;
private final String name;
private final float price;

public IngredientTest(IngredientType type, String name, float price) {
this.type = type;
this.name = name;
this.price = price;
}

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{IngredientType.SAUCE, "hot sauce", 100.0f},
{IngredientType.SAUCE, "sour cream", 200.0f},
{IngredientType.FILLING, "cutlet", 100.0f},
{IngredientType.FILLING, "dinosaur", 200.0f}
});
}

@Test
public void checkIngredientProperties() {
Ingredient ingredient = new Ingredient(type, name, price);

assertEquals("Тип ингредиента не соответствует ожидаемому типу", type, ingredient.getType());
assertEquals("Название ингредиента не соответствует ожидаемому названию", name, ingredient.getName());
assertEquals("Цена ингредиента не соответствует ожидаемой цене", price, ingredient.getPrice(), 0.0f);
}
}
Binary file added target/classes/praktikum/Bun.class
Binary file not shown.
Binary file added target/classes/praktikum/Burger.class
Binary file not shown.
Binary file added target/classes/praktikum/Database.class
Binary file not shown.
Binary file added target/classes/praktikum/Ingredient.class
Binary file not shown.
Binary file added target/classes/praktikum/IngredientType.class
Binary file not shown.
Binary file added target/classes/praktikum/Praktikum.class
Binary file not shown.
Binary file added target/jacoco.exec
Binary file not shown.
3 changes: 3 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=praktikum
groupId=org.example
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
praktikum/Bun.class
praktikum/IngredientType.class
praktikum/Database.class
praktikum/Praktikum.class
praktikum/Burger.class
praktikum/Ingredient.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/Users/darina/Diplom-1/src/main/java/praktikum/Bun.java
/Users/darina/Diplom-1/src/main/java/praktikum/Burger.java
/Users/darina/Diplom-1/src/main/java/praktikum/Database.java
/Users/darina/Diplom-1/src/main/java/praktikum/Ingredient.java
/Users/darina/Diplom-1/src/main/java/praktikum/IngredientType.java
/Users/darina/Diplom-1/src/main/java/praktikum/Praktikum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
praktikum/BunTest.class
praktikum/BurgerTest.class
praktikum/IngredientTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Users/darina/Diplom-1/src/test/java/praktikum/BunTest.java
/Users/darina/Diplom-1/src/test/java/praktikum/BurgerTest.java
/Users/darina/Diplom-1/src/test/java/praktikum/IngredientTest.java
Binary file added target/praktikum-1.0-SNAPSHOT.jar
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>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">0 of 184</td><td class="ctr2">100 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">0</td><td class="ctr2">17</td><td class="ctr1">0</td><td class="ctr2">40</td><td class="ctr1">0</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="praktikum/index.html" class="el_package">praktikum</a></td><td class="bar" id="b0"><img src="jacoco-resources/greenbar.gif" width="120" height="10" title="184" alt="184"/></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="f0">0</td><td class="ctr2" id="g0">17</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">40</td><td class="ctr1" id="j0">0</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.13.202504020838</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