Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop1 #935

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
70 changes: 69 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,72 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test, compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.16</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
7 changes: 7 additions & 0 deletions src/main/java/data/Names.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package data;

public class Names {
public static String BUN_NAME = "Тимати";
public static String FILLING_NAME = "БМТ";
public static String SAUCE_NAME = "Сырный";
}
8 changes: 8 additions & 0 deletions src/main/java/data/Prices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package data;

public class Prices {
public static float BUN_PRICE = 8f;
public static float FILLING_PRICE = 200f;
public static float SAUCE_PRICE = 50f;
public static float EXPECTED_BURGER_PRICE = BUN_PRICE * 2 + FILLING_PRICE + SAUCE_PRICE;
}
26 changes: 26 additions & 0 deletions src/test/java/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.junit.Before;
import org.junit.Test;
import praktikum.Bun;
import data.Names;
import data.Prices;

import static org.junit.Assert.assertEquals;

public class BunTest {
Bun bun;

@Before
public void setUp() {
bun = new Bun(Names.BUN_NAME, Prices.BUN_PRICE);
}

@Test
public void getNameCheckThatNameIsCorrect() {
assertEquals(Names.BUN_NAME, bun.getName());
}

@Test
public void getPriceCheckThatPriceIsCorrect() {
assertEquals(Prices.BUN_PRICE, bun.getPrice(), 0);
}
}
115 changes: 115 additions & 0 deletions src/test/java/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import data.Names;
import data.Prices;
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 praktikum.Bun;
import praktikum.Burger;
import praktikum.Ingredient;
import praktikum.IngredientType;

import java.util.ArrayList;
import java.util.List;

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

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {

private Burger burger;

@Mock
private Bun bun;

@Mock
private Ingredient ingredientSauce;

@Mock
private Ingredient ingredientFilling;

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

@Test
public void addIngredientOneSauceAmountIsCorrect() {
List<Ingredient> expectedIngredients = new ArrayList<>();
expectedIngredients.add(ingredientSauce);

burger.addIngredient(ingredientSauce);

assertEquals(expectedIngredients.size(), burger.ingredients.size());
}

@Test
public void removeIngredientOneSauceZeroAmount() {
burger.addIngredient(ingredientSauce);
burger.removeIngredient(0);

assertTrue(burger.ingredients.isEmpty());
}

@Test
public void moveIngredientReplaceItemsOrderIsCorrect() {
List<Ingredient> expectedOrder = new ArrayList<>();
expectedOrder.add(ingredientFilling);
expectedOrder.add(ingredientSauce);

burger.addIngredient(ingredientSauce);
burger.addIngredient(ingredientFilling);
burger.moveIngredient(0, 1);

assertEquals(expectedOrder, burger.ingredients);
}

@Test
public void getPriceThreeItemsPriceIsCorrect() {
Mockito.when(bun.getPrice()).thenReturn(Prices.BUN_PRICE);
Mockito.when(ingredientSauce.getPrice()).thenReturn(Prices.SAUCE_PRICE);
Mockito.when(ingredientFilling.getPrice()).thenReturn(Prices.FILLING_PRICE);

burger.setBuns(bun);
burger.addIngredient(ingredientFilling);
burger.addIngredient(ingredientSauce);

assertEquals(Prices.EXPECTED_BURGER_PRICE, burger.getPrice(), 0);
}

@Test
public void getReceiptThreeItemsReceiptIsCorrect() {
String formattedBurgerPrice = String.format("%f", Prices.EXPECTED_BURGER_PRICE);

String expectedReceipt = String.format("(==== %s ====)%n" +
"= %s %s =%n" +
"= %s %s =%n" +
"(==== %s ====)%n" +
"%n" +
"Price: %s%n",
Names.BUN_NAME,
IngredientType.FILLING.toString().toLowerCase(), Names.FILLING_NAME,
IngredientType.SAUCE.toString().toLowerCase(), Names.SAUCE_NAME,
Names.BUN_NAME,
formattedBurgerPrice
);

Mockito.when(bun.getName()).thenReturn(Names.BUN_NAME);
Mockito.when(ingredientFilling.getName()).thenReturn(Names.FILLING_NAME);
Mockito.when(ingredientSauce.getName()).thenReturn(Names.SAUCE_NAME);
Mockito.when(bun.getPrice()).thenReturn(Prices.BUN_PRICE);
Mockito.when(ingredientFilling.getPrice()).thenReturn(Prices.FILLING_PRICE);
Mockito.when(ingredientSauce.getPrice()).thenReturn(Prices.SAUCE_PRICE);
Mockito.when(ingredientFilling.getType()).thenReturn(IngredientType.FILLING);
Mockito.when(ingredientSauce.getType()).thenReturn(IngredientType.SAUCE);

burger.setBuns(bun);
burger.addIngredient(ingredientFilling);
burger.addIngredient(ingredientSauce);

assertEquals(expectedReceipt, burger.getReceipt());
}
}
54 changes: 54 additions & 0 deletions src/test/java/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import praktikum.Ingredient;
import praktikum.IngredientType;
import data.Names;
import data.Prices;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class IngredientTest {
Ingredient ingredient;
private final String name;
private final float price;
private final IngredientType type;

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

@Parameterized.Parameters(name = "Ингредиент: {0} {1} {2}")
public static Object[] createIngredient() {
return new Object[][]{
{IngredientType.FILLING, Names.FILLING_NAME, Prices.FILLING_PRICE},
{IngredientType.SAUCE, Names.SAUCE_NAME, Prices.SAUCE_PRICE},

};
}

@Before
public void setUp() {
ingredient = new Ingredient(type, name, price);
}

@Test
public void getNameCheckThatNameIsCorrect() {
assertEquals(name, ingredient.getName());
}

@Test
public void getPriceCheckThatPriceIsCorrect() {
assertEquals(price, ingredient.getPrice(), 0);
}

@Test
public void getTypeCheckThatTypeIsCorrect() {
assertEquals(type, ingredient.getType());
}

}
1 change: 1 addition & 0 deletions target/site/jacoco/data/Names.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>Names</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <a href="index.html" class="el_package">data</a> &gt; <span class="el_class">Names</span></div><h1>Names</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></tr></thead><tfoot><tr><td>Total</td><td class="bar">3 of 10</td><td class="ctr2">70 %</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">1</td><td class="ctr2">2</td><td class="ctr1">1</td><td class="ctr2">4</td><td class="ctr1">1</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a0"><a href="Names.java.html#L3" class="el_method">Names()</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="51" height="10" title="3" alt="3"/></td><td class="ctr2" id="c1">0 %</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">1</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">1</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="Names.java.html#L4" class="el_method">static {...}</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="7" alt="7"/></td><td class="ctr2" id="c0">100 %</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i0">3</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</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>
8 changes: 8 additions & 0 deletions target/site/jacoco/data/Names.java.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>Names.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <a href="index.source.html" class="el_package">data</a> &gt; <span class="el_source">Names.java</span></div><h1>Names.java</h1><pre class="source lang-java linenums">package data;

<span class="nc" id="L3">public class Names {</span>
<span class="fc" id="L4"> public static String BUN_NAME = &quot;Тимати&quot;;</span>
<span class="fc" id="L5"> public static String FILLING_NAME = &quot;БМТ&quot;;</span>
<span class="fc" id="L6"> public static String SAUCE_NAME = &quot;Сырный&quot;;</span>
}
</pre><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>
1 change: 1 addition & 0 deletions target/site/jacoco/data/Prices.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>Prices</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <a href="index.html" class="el_package">data</a> &gt; <span class="el_class">Prices</span></div><h1>Prices</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></tr></thead><tfoot><tr><td>Total</td><td class="bar">3 of 18</td><td class="ctr2">83 %</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">1</td><td class="ctr2">2</td><td class="ctr1">1</td><td class="ctr2">5</td><td class="ctr1">1</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a0"><a href="Prices.java.html#L3" class="el_method">Prices()</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="24" height="10" title="3" alt="3"/></td><td class="ctr2" id="c1">0 %</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">1</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">1</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="Prices.java.html#L4" class="el_method">static {...}</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="15" alt="15"/></td><td class="ctr2" id="c0">100 %</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i0">4</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</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>
9 changes: 9 additions & 0 deletions target/site/jacoco/data/Prices.java.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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>Prices.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">praktikum</a> &gt; <a href="index.source.html" class="el_package">data</a> &gt; <span class="el_source">Prices.java</span></div><h1>Prices.java</h1><pre class="source lang-java linenums">package data;

<span class="nc" id="L3">public class Prices {</span>
<span class="fc" id="L4"> public static float BUN_PRICE = 8f;</span>
<span class="fc" id="L5"> public static float FILLING_PRICE = 200f;</span>
<span class="fc" id="L6"> public static float SAUCE_PRICE = 50f;</span>
<span class="fc" id="L7"> public static float EXPECTED_BURGER_PRICE = BUN_PRICE * 2 + FILLING_PRICE + SAUCE_PRICE;</span>
}
</pre><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>
Loading