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
118 changes: 116 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,122 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<mockito.version>5.13.0</mockito.version>
<byte-buddy.version>1.17.5</byte-buddy.version>
<junit.version>5.10.2</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.14</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<propertyName>argLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-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>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
<configuration>

</configuration>

</plugin>
</plugins>
</build>

</project>
27 changes: 27 additions & 0 deletions src/test/java/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import praktikum.Bun;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BunTest {

private static Stream<Arguments> bun() {
return Stream.of(
Arguments.of("Булочка с кунжутом", 490.99F),
Arguments.of("Булочка черная", 300.00F),
Arguments.of("Булочка бородинская", 342.00F)
);
}

@ParameterizedTest
@MethodSource("bun")
void BunConstructorTest(String testName, float testPrice) {
Bun bigBun = new Bun(testName, testPrice);
assertEquals(testName, bigBun.getName(), "Название булочки не совпадает с переданным");
assertEquals(testPrice, bigBun.getPrice(), "Цена булочки не совпадает с переданной");
}
}
111 changes: 111 additions & 0 deletions src/test/java/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import praktikum.*;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class BurgerTest {

@Mock
Bun bun;

Burger burger = new Burger();


private static Stream<Arguments> listDoubleIngredients() {
return Stream.of(
Arguments.of(IngredientType.SAUCE, "ketchup", 120.00F, IngredientType.FILLING, "cutlet", 400.00F),
Arguments.of(IngredientType.SAUCE, "mayonnaise", 144.56F, IngredientType.FILLING, "cheese", 55.55F)
);
}

private static Stream<Arguments> listIngredients() {
return Stream.of(
Arguments.of(IngredientType.SAUCE, "ketchup", 120.00F),
Arguments.of(IngredientType.SAUCE, "mayonnaise", 144.56F),
Arguments.of(IngredientType.FILLING, "cutlet", 400.00F),
Arguments.of(IngredientType.FILLING, "cheese", 55.55F)
);
}

@Test
void setBunsTest() {
burger.setBuns(bun);
assertEquals(bun, burger.bun);
}

@ParameterizedTest
@MethodSource("listIngredients")
void addIngredientTest(IngredientType type, String name, float price) {
Ingredient ingredientOrList = new Ingredient(type, name, price);
burger.addIngredient(ingredientOrList);
Ingredient last = burger.ingredients.get(burger.ingredients.size() - 1);
assertEquals(type, last.getType(), "Переданное значение ТИПА ингредиента не совпадает с записанным в список");
assertEquals(name, last.getName(), "Переданное значение ИМЕНИ ингредиента не совпадает с записанным в список");
assertEquals(price, last.getPrice(), "Переданное значение ЦЕНЫ ингредиента не совпадает с записанным в список");
}

@ParameterizedTest
@MethodSource("listDoubleIngredients")
void removeIngredientTest(IngredientType oneType, String oneName, float onePrice, IngredientType twoType, String twoName, float twoPrice) {
//Создаем два ингредиента
Ingredient ingredientOne = new Ingredient(oneType, oneName, onePrice);
Ingredient ingredientTwo = new Ingredient(twoType, twoName, twoPrice);
burger.addIngredient(ingredientOne);
burger.addIngredient(ingredientTwo);

int startSize = burger.ingredients.size();
int lastIngredients = burger.ingredients.size() - 1;
burger.removeIngredient(lastIngredients);
assertEquals(startSize - 1, burger.ingredients.size(), "Количество элементов не совпадает");
}

@ParameterizedTest
@MethodSource("listDoubleIngredients")
void moveIngredientTest(IngredientType oneType, String oneName, float onePrice, IngredientType twoType, String twoName, float twoPrice) {
//Создаем два ингредиента
Ingredient ingredientOne = new Ingredient(oneType, oneName, onePrice);
Ingredient ingredientTwo = new Ingredient(twoType, twoName, twoPrice);
burger.addIngredient(ingredientOne);
burger.addIngredient(ingredientTwo);
//Находим индекс второго ингредиента и меняем его индекс
int indexTwoIngredient = burger.ingredients.indexOf(ingredientTwo);
burger.moveIngredient(1, 0);
int indexTwoIngredientNew = burger.ingredients.indexOf(ingredientTwo);
assertEquals(indexTwoIngredient - 1, indexTwoIngredientNew, "Индекс элемента списка не совпадает с заданным значением");
}

@Test
void getPriceReturn() {
burger.setBuns(bun);
when(bun.getPrice()).thenReturn(300.00F);

float burgerPrice = burger.getPrice();
assertEquals(bun.getPrice() * 2, burgerPrice, "Стоимость ингредиентов не совпадает");
}

@Test
void getReceiptTest() {
Ingredient ingredient = new Ingredient(IngredientType.SAUCE, "ketchup", 100.00F);
burger.addIngredient(ingredient);

when(bun.getName()).thenReturn("Хлебная с кунжутом");
when(bun.getPrice()).thenReturn(300.00F);
burger.setBuns(bun);
String receipt = burger.getReceipt();
assertTrue(receipt.contains("(==== Хлебная с кунжутом ====)"), "Название булочки не совпадает");
assertTrue(receipt.contains("ketchup"), "Название ингредиента не совпадает");
assertTrue(receipt.contains("700"), "Общая стоимость рецепта не совпадает");
}

}
32 changes: 32 additions & 0 deletions src/test/java/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import praktikum.Ingredient;
import praktikum.IngredientType;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class IngredientTest {

private static Stream<Arguments> listIngredients() {
return Stream.of(
Arguments.of(IngredientType.SAUCE, "ketchup", 120.00F),
Arguments.of(IngredientType.FILLING, "cheese", 55.55F)
);
}

@ParameterizedTest
@MethodSource("listIngredients")
void constructorIngredientTest(IngredientType type, String name, float price) {
Ingredient ingredient = new Ingredient(type, name, price);
assertEquals(type, ingredient.type, "Тип ингредиента не совпадает с переданным");
assertEquals(name, ingredient.name, "Название ингредиента не совпадает с переданным");
assertEquals(price, ingredient.price, "Цена ингредиента не совпадает с переданным");

}
}
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.14.202510111229</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