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
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.

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.

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>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!-- Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</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.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>

<!-- Jacoco -->
<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>
94 changes: 94 additions & 0 deletions src/test/java/praktikum/BurgerParamTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package praktikum;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.List;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(Parameterized.class)
public class BurgerParamTest {

@Parameterized.Parameters(name = "bun={0}, ingredients={1}, expectedPrice={2}")
public static Iterable<Object[]> data() {
return BurgerTestData.data();
}

private final float bunPrice;
private final List<Float> ingredientPrices;
private final float expectedPrice;

public BurgerParamTest(float bunPrice, List<Float> ingredientPrices, float expectedPrice) {
this.bunPrice = bunPrice;
this.ingredientPrices = ingredientPrices;
this.expectedPrice = expectedPrice;
}

private Burger burger;
private Bun bunMock;

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

bunMock = mock(Bun.class);
when(bunMock.getName()).thenReturn("Test Bun");
when(bunMock.getPrice()).thenReturn(bunPrice);

burger.setBuns(bunMock);

for (int i = 0; i < ingredientPrices.size(); i++) {
Ingredient ing = mock(Ingredient.class, "ing-" + i);
IngredientType type = (i % 2 == 0) ? IngredientType.SAUCE : IngredientType.FILLING;
when(ing.getType()).thenReturn(type);
when(ing.getName()).thenReturn((type == IngredientType.SAUCE ? "bbq" : "cutlet") + "-" + i);
when(ing.getPrice()).thenReturn(ingredientPrices.get(i));
burger.addIngredient(ing);
}
}

@After
public void tearDown() {
burger = null;
bunMock = null;
}

@Test
public void getPrice() {
float price = burger.getPrice();
assertEquals(expectedPrice, price, 0.0001f);
}

@Test
public void getReceiptInFooter() {
String receipt = burger.getReceipt();

String footer = String.format("(==== %s ====)%n", "Test Bun");
assertThat("В чеке должен быть нижний разделитель", receipt, containsString(footer));
}

@Test
public void getReceiptInHeader() {
String receipt = burger.getReceipt();

String header = String.format("(==== %s ====)%n", "Test Bun");
assertTrue("В чеке должен быть заголовок с названием булочки", receipt.startsWith(header));
}

@Test
public void getReceiptContainAllIngredientLines() {
String receipt = burger.getReceipt();

for (int i = 0; i < burger.ingredients.size(); i++) {
Ingredient ing = burger.ingredients.get(i);
String expectedLine = String.format("= %s %s =%n",
ing.getType().toString().toLowerCase(), ing.getName());
assertThat("Должна присутствовать строка ингредиента " + i, receipt, containsString(expectedLine));
}
}
}
106 changes: 106 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package praktikum;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class BurgerTest {

private Burger burger;
private Bun bunMock;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Должно быть два класса

  1. Класс с параметризированными тестами для burger. Я его ее вижу
  2. Класс с обычными тестами

@Before
public void setUp() {
burger = new Burger();
bunMock = mock(Bun.class);
when(bunMock.getName()).thenReturn("Test Bun");
when(bunMock.getPrice()).thenReturn(100f);
burger.setBuns(bunMock);
}

@After
public void tearDown() {
burger = null;
bunMock = null;
}

@Test
public void setBuns() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Если в тестах не нужна параметризация, их нужно вынести в отдельный класс

assertSame("Поле bun должно ссылаться на установленную булочку", bunMock, burger.bun);
}

@Test
public void addIngredient() {
int before = burger.ingredients.size();

Ingredient extra = mock(Ingredient.class);
when(extra.getType()).thenReturn(IngredientType.SAUCE);
when(extra.getName()).thenReturn("extra-sauce");
when(extra.getPrice()).thenReturn(10f);

burger.addIngredient(extra);

assertEquals(before + 1, burger.ingredients.size());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Для юнит-тестов придерживаемся подхода: один тест, значит одна проверка. Если очень хочется несколько проверок -- тогда используем softAssertions. Поправь, пожалуйста, во всем коде

}

@Test
public void removeIngredient() {
Ingredient toRemove = mock(Ingredient.class);
when(toRemove.getType()).thenReturn(IngredientType.FILLING);
when(toRemove.getName()).thenReturn("delete-me");
when(toRemove.getPrice()).thenReturn(123f);
burger.addIngredient(toRemove);

int initial = burger.ingredients.size();
int index = burger.ingredients.indexOf(toRemove);

burger.removeIngredient(index);

assertEquals("Размер должен уменьшиться на 1", initial - 1, burger.ingredients.size());
}

@Test
public void removeIngredientFromList() {
Ingredient toRemove = mock(Ingredient.class);
when(toRemove.getType()).thenReturn(IngredientType.FILLING);
when(toRemove.getName()).thenReturn("delete-me");
when(toRemove.getPrice()).thenReturn(123f);
burger.addIngredient(toRemove);

int index = burger.ingredients.indexOf(toRemove);

burger.removeIngredient(index);

assertFalse("Элемент должен быть удалён", burger.ingredients.contains(toRemove));
}

@Test
public void moveIngredient() {
Ingredient i0 = mock(Ingredient.class, "i0");
when(i0.getType()).thenReturn(IngredientType.SAUCE);
when(i0.getName()).thenReturn("i0");
when(i0.getPrice()).thenReturn(1f);

Ingredient i1 = mock(Ingredient.class, "i1");
when(i1.getType()).thenReturn(IngredientType.FILLING);
when(i1.getName()).thenReturn("i1");
when(i1.getPrice()).thenReturn(2f);

Ingredient i2 = mock(Ingredient.class, "i2");
when(i2.getType()).thenReturn(IngredientType.SAUCE);
when(i2.getName()).thenReturn("i2");
when(i2.getPrice()).thenReturn(3f);

burger.ingredients.clear();
burger.addIngredient(i0);
burger.addIngredient(i1);
burger.addIngredient(i2);

burger.moveIngredient(0, 2);
assertThat(burger.ingredients.get(2), is(i0));
}
}
15 changes: 15 additions & 0 deletions src/test/java/praktikum/BurgerTestData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package praktikum;

import java.util.Arrays;
import java.util.Collections;

public class BurgerTestData {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️Можно улучшить. данные можно не отделять от тестов

public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{100f, Collections.<Float>emptyList(), 200f},
{100f, Arrays.asList(50f), 250f},
{100f, Arrays.asList(50f, 25f), 275f},
{199.99f, Arrays.asList(0.01f, 1000f), 199.99f * 2 + 0.01f + 1000f},
});
}
}
Binary file added target/classes/praktikum/Bun.class

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. В папке target нужно оставить только отчет

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
praktikum\Bun.class
praktikum\Praktikum.class
praktikum\IngredientType.class
praktikum\Burger.class
praktikum\Database.class
praktikum\Ingredient.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\IngredientType.java
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\Burger.java
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\Database.java
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\Praktikum.java
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\Ingredient.java
H:\IdeaProjects\QA-java-diplom\src\main\java\praktikum\Bun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
praktikum\BurgerParamTest.class
praktikum\BurgerTestData.class
praktikum\BurgerTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
H:\IdeaProjects\QA-java-diplom\src\test\java\praktikum\BurgerTestData.java
H:\IdeaProjects\QA-java-diplom\src\test\java\praktikum\BurgerTest.java
H:\IdeaProjects\QA-java-diplom\src\test\java\praktikum\BurgerParamTest.java
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">201 of 358</td><td class="ctr2">43 %</td><td class="bar">0 of 4</td><td class="ctr2">100 %</td><td class="ctr1">12</td><td class="ctr2">22</td><td class="ctr1">43</td><td class="ctr2">69</td><td class="ctr1">12</td><td class="ctr2">20</td><td class="ctr1">4</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="67" height="10" title="201" alt="201"/><img src="jacoco-resources/greenbar.gif" width="52" height="10" title="157" alt="157"/></td><td class="ctr2" id="c0">43 %</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">12</td><td class="ctr2" id="g0">22</td><td class="ctr1" id="h0">43</td><td class="ctr2" id="i0">69</td><td class="ctr1" id="j0">12</td><td class="ctr2" id="k0">20</td><td class="ctr1" id="l0">4</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