Skip to content
Open

Develop #1137

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
57 changes: 57 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,61 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.18.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.18.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</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>
</plugins>
</build>

</project>
20 changes: 20 additions & 0 deletions src/test/java/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.junit.jupiter.api.Test;
import praktikum.Bun;

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

public class BunTest {


@Test
public void shouldGetName(){
Bun bun = new Bun("булка", 21.1F);
assertEquals("булка",bun.getName(),"Неправильно возвращает имя");
}

@Test
public void shouldGetPrice(){
Bun bun = new Bun("bulka", 21.1F);
assertEquals(21.1F, bun.getPrice(),"Неправильно возвращает цену");
}
}
97 changes: 97 additions & 0 deletions src/test/java/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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.CsvSource;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import praktikum.Bun;
import praktikum.Burger;
import praktikum.Ingredient;
import praktikum.IngredientType;

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


@ExtendWith(MockitoExtension.class)
public class BurgerTest {
@Mock
Ingredient ingredient;
@Mock
Ingredient ingredient2;
@Mock
Bun bun;

@Test
public void shouldSetBun(){
Burger burger = new Burger();
Bun bun = new Bun("bulka", 21F);
burger.setBuns(bun);
assertEquals(bun, burger.bun,"Сеттер неправильно работает");

}
@Test
public void shouldAddIngredient(){
Burger burger = new Burger();
burger.addIngredient(ingredient);
assertTrue(burger.ingredients.contains(ingredient),"Неправильно добавляется ингредиент");
}
@Test
public void shouldRemoveIngredient(){
Burger burger = new Burger();
burger.addIngredient(ingredient);
burger.removeIngredient(0);
assertFalse(burger.ingredients.contains(ingredient));
}
@Test
public void shouldMoveIngredient(){
Burger burger = new Burger();
burger.addIngredient(ingredient);
burger.addIngredient(ingredient2);
burger.moveIngredient(0,1);
assertEquals(ingredient, burger.ingredients.get(1),"Неправильно перемещает ингредиенты");
}
@ParameterizedTest
@CsvSource({
"48.2F, 512F, 322F",
"36.5F, 145F, 444F"
})
public void shouldGetPrice(float bunPrice, float ingPrice1, float ingPrice2){
Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredient);
burger.addIngredient(ingredient2);
Mockito.when(bun.getPrice()).thenReturn(bunPrice);
Mockito.when(ingredient.getPrice()).thenReturn(ingPrice1);
Mockito.when(ingredient2.getPrice()).thenReturn(ingPrice2);
float expectedTotalPrice = bunPrice*2+ingPrice1+ingPrice2;
assertEquals(expectedTotalPrice,burger.getPrice(),"Неправильно считает цену");
}
@ParameterizedTest
@CsvSource({
"татар, грязный носок, булка ,SAUCE, FILLING, 600F",
"karama, shaa, багет ,FILLING, SAUCE, 400.41F"
})
public void shouldGetReceipt(String ingName1, String ingName2, String bunName, IngredientType ingType1, IngredientType ingType2, float price){
Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredient);
burger.addIngredient(ingredient2);
Mockito.when(bun.getName()).thenReturn(bunName);
Mockito.when(ingredient.getType()).thenReturn(ingType1);
Mockito.when(ingredient.getName()).thenReturn(ingName1);
Mockito.when(ingredient2.getType()).thenReturn(ingType2);
Mockito.when(ingredient2.getName()).thenReturn(ingName2);
Mockito.when(burger.getPrice()).thenReturn(price);

String expectedReceipt =
String.format("(==== %s ====)%n", bunName) +
String.format("= %s %s =%n", ingType1.toString().toLowerCase(), ingName1) +
String.format("= %s %s =%n", ingType2.toString().toLowerCase(), ingName2) +
String.format("(==== %s ====)%n", bunName) +
String.format("%nPrice: %f%n", price);

assertEquals(expectedReceipt, burger.getReceipt(),"Неправильно печатает рецепт");

}
}
24 changes: 24 additions & 0 deletions src/test/java/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import org.junit.jupiter.api.Test;
import praktikum.Ingredient;
import praktikum.IngredientType;

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

public class IngredientTest {
@Test
public void shouldGetName(){
Ingredient ingredient = new Ingredient(IngredientType.FILLING,"1000 островов",200F);
assertEquals("1000 островов",ingredient.getName(),"Неправильно возвращает имя");
}

@Test
public void shouldGetPrice(){
Ingredient ingredient = new Ingredient(IngredientType.FILLING,"1000 островов",200F);
assertEquals(200F,ingredient.getPrice(),"Неправильно возвращает стоимость");
}
@Test
public void shouldGetType(){
Ingredient ingredient = new Ingredient(IngredientType.FILLING,"1000 островов",200F);
assertEquals(IngredientType.FILLING, ingredient.getType(),"Неправильно возвращает тип");
}
}
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 358</td><td class="ctr2">53 %</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="55" height="10" title="165" alt="165"/><img src="jacoco-resources/greenbar.gif" width="64" height="10" title="193" alt="193"/></td><td class="ctr2" id="c0">53 %</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.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