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 #885

Open
wants to merge 3 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
91 changes: 90 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,95 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.13.2</junit.version>
<mockito.version>4.6.1</mockito.version>
<jacoco.version>0.8.10</jacoco.version>
</properties>

</project>
<build>
<plugins>
<!-- Surefire Plugin для запуска тестов с JUnit 4 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M9</version>
<configuration>
<argLine>-javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${project.build.directory}/jacoco.exec</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>

<!-- Jacoco Plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/site/jacoco</outputDirectory>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<formats>
<format>HTML</format>
</formats>

<includes>
<include>praktikum/Bun.class</include>
<include>praktikum/Burger.class</include>
<include>praktikum/Ingredient.class</include>
<include>praktikum/IngredientType.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

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

<!-- JUnitParams -->
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>

<!-- Зависимость Gson для работы с JSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>

</project>
28 changes: 28 additions & 0 deletions src/test/java/praktikum/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;


public class BunTest {

@Test
public void getNameIsSuccess() {
String bunName = "sweet bun";
Bun bun = new Bun(bunName, 200);
MatcherAssert.assertThat("Неверное имя булочки",
bun.getName(),
equalTo(bunName));
}

@Test
public void getPriceIsSuccess() {
float bunPrice = 250;
Bun bun = new Bun("sweet bun", bunPrice);
MatcherAssert.assertThat("Неверная цена булочки",
bun.getPrice(),
equalTo(bunPrice));
}
}
112 changes: 112 additions & 0 deletions src/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;

@RunWith(MockitoJUnitRunner.class)

public class BurgerTest {
@Mock
private Bun bun;
@Mock
private Ingredient ingredientX;
@Mock
private Ingredient ingredientY;

@Test
public void setBunsIsSuccess() {
Burger burger = new Burger();
Mockito.when(bun.getName()).thenReturn("sweet bun");
burger.setBuns(bun);

MatcherAssert.assertThat("Новая булочка не добавляется",
bun.getName(),
equalTo(burger.bun.getName()));
}

@Test
public void addIngredientIsSuccess() {
Burger burger = new Burger();
burger.addIngredient(ingredientX);

assertTrue("Ингредиент не добавляется",
burger.ingredients.contains(ingredientX));
}

@Test
public void removeIngredientIsSuccess() {
Burger burger = new Burger();
burger.addIngredient(ingredientX);

int index = burger.ingredients.indexOf(ingredientX);
burger.removeIngredient(index);

assertFalse("Ингредиент не удалён",
burger.ingredients.contains(ingredientX));

}

@Test
public void moveIngredientIsSuccess() {
Burger burger = new Burger();
Mockito.when(ingredientX.getName()).thenReturn("Salad");
Mockito.when(ingredientY.getName()).thenReturn("Meat");
burger.addIngredient(ingredientX);
burger.addIngredient(ingredientY);

burger.moveIngredient(0,1);

MatcherAssert.assertThat("Ингредиент не перемещён",
burger.ingredients.get(1).getName(),
equalTo("Salad"));

MatcherAssert.assertThat("Ингредиент не перемещён",
burger.ingredients.get(0).getName(),
equalTo("Meat"));
}

@Test
public void getPriceIsSuccess() {
Mockito.when(bun.getPrice()).thenReturn(50F);
Mockito.when(ingredientX.getPrice()).thenReturn(300F);
float totalPrice = bun.getPrice() * 2 + ingredientX.getPrice();

Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredientX);

MatcherAssert.assertThat("Стоимость расчитана неверно",
totalPrice,
equalTo(burger.getPrice()));
}

@Test
public void getReceiptIsSuccess() {
Mockito.when(bun.getName()).thenReturn("sweet bun");
Mockito.when(bun.getPrice()).thenReturn(50F);
Mockito.when(ingredientX.getName()).thenReturn("Meat");
Mockito.when(ingredientX.getPrice()).thenReturn(100F);
Mockito.when(ingredientX.getType()).thenReturn(IngredientType.FILLING);

String expectedReceipt = String.format("(==== %s ====)%n", bun.getName()) +
String.format("= %s %s =%n", ingredientX.getType().name().toLowerCase(), ingredientX.getName()) +
String.format("(==== %s ====)%n", bun.getName()) +
String.format("%nPrice: %.6f%n", (bun.getPrice() * 2) + ingredientX.getPrice());


Burger burger = new Burger();
burger.setBuns(bun);
burger.addIngredient(ingredientX);

MatcherAssert.assertThat("Неверный рецепт",
burger.getReceipt(),
equalTo(expectedReceipt));
}
}
40 changes: 40 additions & 0 deletions src/test/java/praktikum/IngredientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;

public class IngredientTest {
private Ingredient ingredient;
private IngredientType ingredientType = IngredientType.FILLING;
private String ingredientName = "Meat";
private float ingredientPrice = 200F;

@Before
public void createIngredient() {
this.ingredient = new Ingredient(ingredientType,ingredientName,ingredientPrice);
}

@Test
public void getPriceIsSuccess() {
MatcherAssert.assertThat("Неверная цена ингредиента",
ingredient.getPrice(),
equalTo(ingredientPrice));
}

@Test
public void getNameIsSuccess() {
MatcherAssert.assertThat("Неверное название ингредиента",
ingredient.getName(),
equalTo(ingredientName));
}

@Test
public void getTypeIsSuccess() {
MatcherAssert.assertThat("Неверный тип ингредиента",
ingredient.getType(),
equalTo(ingredientType));
}
}
31 changes: 31 additions & 0 deletions src/test/java/praktikum/IngredientTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package praktikum;

import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.hamcrest.CoreMatchers.equalTo;

@RunWith(Parameterized.class)

public class IngredientTypeTest {
private final String typeName;
@Parameterized.Parameters(name = "Наличие типа ингредиента {0}")
public static Object[][] typesForTest() {
return new Object[][] {
{"SAUCE"},
{"FILLING"}
};
}
public IngredientTypeTest(String typeName) {
this.typeName = typeName;
}
@Test
public void ingredientTypesIsCorrect() {

MatcherAssert.assertThat("Отсутствует тип " + typeName,
IngredientType.valueOf(typeName.toUpperCase()).toString(),
equalTo(typeName));
}
}
Binary file added target/classes/praktikum/Bun.class
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 @@
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\Database.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\Burger.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\Praktikum.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\Ingredient.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\IngredientType.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\main\java\praktikum\Bun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
praktikum\IngredientTypeTest.class
praktikum\IngredientTest.class
praktikum\BunTest.class
praktikum\BurgerTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\test\java\praktikum\IngredientTypeTest.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\test\java\praktikum\BunTest.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\test\java\praktikum\IngredientTest.java
C:\Users\ekate\IdeaProjects\QA-java-diplom-1\src\test\java\praktikum\BurgerTest.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">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