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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea/
target/
!target/site/
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Diplom_1
>>>>>>> origin/main

В проекте мы проводим юнит-тестирование учебного сервиса https://stellarburgers.education-services.ru/
Тестируемый класс Burger
проведена проверка покрытия кода

## Используемые библиотеки:
mockito
JUnit 4
JaCoCo


## Конфигурация проекта
| Технология | Версия |
|:----------:|:--------|
| Java | 11 |
| JUnit | 4.13.2 |
| mockito | 4.8.0 |
| Firefox | 148.0 |
| JaCoCo | 0.8.7 |


## Оценка покрытия "mvn verify" .
63 changes: 62 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,73 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>praktikum</artifactId>
<artifactId>MockProject</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<mockito.version>4.8.0</mockito.version>
<junit.version>4.13.2</junit.version>
<java.version>11</java.version>
<mvn.version>3.8.1</mvn.version>
</properties>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</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>${mvn.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
1 change: 0 additions & 1 deletion src/main/java/praktikum/Bun.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public String getName() {
public float getPrice() {
return price;
}

}
1 change: 0 additions & 1 deletion src/main/java/praktikum/Burger.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public float getPrice() {
for (Ingredient ingredient : ingredients) {
price += ingredient.getPrice();
}

return price;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/praktikum/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public Database() {
ingredients.add(new Ingredient(IngredientType.FILLING, "dinosaur", 200));
ingredients.add(new Ingredient(IngredientType.FILLING, "sausage", 300));
}

public List<Bun> availableBuns() {
return buns;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/praktikum/Ingredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public Ingredient(IngredientType type, String name, float price) {
this.name = name;
this.price = price;
}

public float getPrice() {
return price;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/praktikum/IngredientType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package praktikum;

/**
* Перечисление с типами ингредиентов.
* SAUCE – соус
Expand Down
1 change: 0 additions & 1 deletion src/main/java/praktikum/Praktikum.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public static void main(String[] args) {
// Распечатаем рецепт бургера
System.out.println(burger.getReceipt());
}

}
70 changes: 70 additions & 0 deletions src/test/java/praktikum/BurgerPriceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package praktikum;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(Parameterized.class)
public class BurgerPriceTest {


@Mock
private Bun bun;

private Burger burger;


public float bunPrice;
public List<Ingredient> ingredients;
public float expectedPrice;

public BurgerPriceTest(float bunPrice, List<Ingredient> ingredients, float expectedPrice) {
this.bunPrice = bunPrice;
this.ingredients =ingredients;
this.expectedPrice=expectedPrice;

}

@Parameterized.Parameters (name = "Булочка:{0} | Цена:{2}")
public static Collection<Object[]> burgerTestData() {
return Arrays.asList(new Object[][] {
{100f, List.of(), 200f},
{200f, List.of(new Ingredient(IngredientType.FILLING, "cutlet", 100f)), 500f},
{300f, List.of(new Ingredient(IngredientType.SAUCE, "hot sauce", 100f)), 700f},
{100f, List.of(new Ingredient(IngredientType.FILLING, "dinosaur", 200f),
new Ingredient(IngredientType.SAUCE, "sour cream", 200f)),600f},
{200f, List.of(new Ingredient(IngredientType.FILLING, "cutlet", 100f),
new Ingredient(IngredientType.FILLING, "sausage", 300f)),800f}
});
}

@Before
public void setUp() {

MockitoAnnotations.openMocks(this);
burger = new Burger();

when(bun.getPrice()).thenReturn(bunPrice);

burger.setBuns(bun);

for (Ingredient ingredient : ingredients) {
burger.addIngredient(ingredient);
}
}

@Test
public void testGetPrice() {//тест получения цены
float actualPrice = burger.getPrice();
assertEquals(expectedPrice, actualPrice, 0.001f);
}
}
90 changes: 90 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;

@RunWith(MockitoJUnitRunner.class)

public class BurgerTest {

@Mock
private Bun bun;

@Mock
private Ingredient filling;

@Mock
private Ingredient sauce;

private Burger burger;


@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
burger = new Burger();
}

@Test
public void getPriceTest() { // все тесты

Mockito.when(bun.getName()).thenReturn("Black Bun");
Mockito.when(bun.getPrice()).thenReturn(100f);

Mockito.when(filling.getName()).thenReturn("cutlet");
Mockito.when(filling.getType()).thenReturn(IngredientType.FILLING);
Mockito.when(filling.getPrice()).thenReturn(100f);

Mockito.when(sauce.getName()).thenReturn("chili sauce");
Mockito.when(sauce.getType()).thenReturn(IngredientType.SAUCE);
Mockito.when(sauce.getPrice()).thenReturn(300f);

burger.setBuns(bun);
burger.addIngredient(filling);
burger.addIngredient(sauce);

String actualReceipt = burger.getReceipt();

String expectedReceipt =
String.format("(==== %s ====)%n" , bun.getName()) +
String.format("= %s %s =%n", filling.getType().toString().toLowerCase(),
filling.getName()) +
String.format("= %s %s =%n", sauce.getType().toString().toLowerCase(),
sauce.getName())+
String.format("(==== %s ====)%n", bun.getName()) +
String.format("%nPrice: %f%n", burger.getPrice());
assertEquals(expectedReceipt, actualReceipt);
}
@Test
public void addIngredientTest () {
burger.addIngredient(filling);
assertEquals(filling, burger.ingredients.get(0));
}
@Test
public void setBunsTest() {
Bun bun = new Bun("red bun", 300);
burger.setBuns(bun);
assertEquals(bun, burger.bun);
}
@Test
public void removeIngredientTest () {
burger.addIngredient(filling);
burger.addIngredient(sauce);
burger.removeIngredient(0);
assertEquals("Должен остаться 1 ингредиента", 1, burger.ingredients.size());
}
@Test
public void moveIngredientTest () {
burger.addIngredient(filling);
burger.addIngredient(sauce);
burger.moveIngredient(1,0);
assertEquals("Первый элемент должен стать sauce",
sauce, burger.ingredients.get(0));
}
}
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>MockProject</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">MockProject</span></div><h1>MockProject</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">177 of 358</td><td class="ctr2">50 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">9</td><td class="ctr2">22</td><td class="ctr1">33</td><td class="ctr2">69</td><td class="ctr1">9</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="59" height="10" title="177" alt="177"/><img src="jacoco-resources/greenbar.gif" width="60" height="10" title="181" alt="181"/></td><td class="ctr2" id="c0">50 %</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">9</td><td class="ctr2" id="g0">22</td><td class="ctr1" id="h0">33</td><td class="ctr2" id="i0">69</td><td class="ctr1" id="j0">9</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