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
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Maven build output
target/classes/
target/test-classes/
target/generated-sources/
target/generated-test-sources/
target/maven-archiver/
target/maven-status/
target/surefire-reports/
target/site/jacoco/jacoco.exec
target/site/jacoco/jacoco.xml
target/site/jacoco/jacoco.csv
target/site/jacoco/jacoco-sessions.html
target/*.jar
target/*.war

# Keep JaCoCo HTML report for PR
!target/site/jacoco/*.html
!target/site/jacoco/**/*.html
!target/site/jacoco/jacoco-resources/

# IDE
.idea/
*.iml


97 changes: 97 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,103 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<junit.version>4.13.2</junit.version>
<mockito.version>5.12.0</mockito.version>
<jacoco.version>0.8.12</jacoco.version>
</properties>

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

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<excludes>
<exclude>praktikum/Database*</exclude>
<exclude>praktikum/Praktikum*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>praktikum/Database*</exclude>
<exclude>praktikum/Praktikum*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludes>
<exclude>praktikum/Database*</exclude>
<exclude>praktikum/Praktikum*</exclude>
</excludes>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

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

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

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class BunParameterizedTest {

@Parameterized.Parameters(name = "name={0}, price={1}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"black bun", 100f},
{"white bun", 0f},
{"sesame bun", 199.99f},
});
}

@Parameterized.Parameter(0)
public String name;

@Parameterized.Parameter(1)
public float price;

@Test
public void getName_returnsConstructorName() {
Bun bun = new Bun(name, price);
assertEquals(name, bun.getName());
}

@Test
public void getPrice_returnsConstructorPrice() {
Bun bun = new Bun(name, price);
assertEquals(price, bun.getPrice(), 0.0001f);
}
}


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

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

Choose a reason for hiding this comment

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

Импорт не используется


import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class BurgerTest {

private Burger burger;
private Bun bun;

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

@Test
public void addIngredient_appendsToList() {
Ingredient ing = mock(Ingredient.class);
burger.addIngredient(ing);
assertEquals(1, burger.ingredients.size());
assertSame(ing, burger.ingredients.get(0));
}

@Test
public void removeIngredient_removesByIndex() {
Ingredient a = mock(Ingredient.class);
Ingredient b = mock(Ingredient.class);
burger.addIngredient(a);
burger.addIngredient(b);
burger.removeIngredient(0);
assertEquals(1, burger.ingredients.size());
assertSame(b, burger.ingredients.get(0));
}

@Test
public void moveIngredient_movesElementToNewIndex() {
Ingredient a = mock(Ingredient.class);
Ingredient b = mock(Ingredient.class);
Ingredient c = mock(Ingredient.class);
burger.addIngredient(a); // 0
burger.addIngredient(b); // 1
burger.addIngredient(c); // 2
burger.moveIngredient(2, 0);
assertSame(c, burger.ingredients.get(0));
assertSame(a, burger.ingredients.get(1));
assertSame(b, burger.ingredients.get(2));
}

@Test
public void getPrice_sumsBunTwiceAndIngredients() {
Ingredient i1 = mock(Ingredient.class);
when(i1.getPrice()).thenReturn(50f);
Ingredient i2 = mock(Ingredient.class);
when(i2.getPrice()).thenReturn(25.5f);
burger.addIngredient(i1);
burger.addIngredient(i2);
float expected = 100f * 2 + 50f + 25.5f;
assertEquals(expected, burger.getPrice(), 0.0001f);
}

@Test
public void getReceipt_printsFormattedReceipt() {
Ingredient sauce = mock(Ingredient.class);
when(sauce.getType()).thenReturn(IngredientType.SAUCE);
when(sauce.getName()).thenReturn("hot sauce");
when(sauce.getPrice()).thenReturn(100f);

Ingredient filling = mock(Ingredient.class);
when(filling.getType()).thenReturn(IngredientType.FILLING);
when(filling.getName()).thenReturn("cutlet");
when(filling.getPrice()).thenReturn(200f);

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

String receipt = burger.getReceipt();

String expected = String.format(
"(==== %s ====)%n" +
"= %s %s =%n" +
"= %s %s =%n" +
"(==== %s ====)%n" +
"%nPrice: %f%n",
"black bun",
"sauce", "hot sauce",
"filling", "cutlet",
"black bun",
100f * 2 + 100f + 200f
);

assertEquals(expected, receipt);

verify(bun, atLeastOnce()).getName();
verify(bun, atLeastOnce()).getPrice();
verify(sauce, atLeastOnce()).getType();
verify(sauce, atLeastOnce()).getName();
verify(filling, atLeastOnce()).getType();
verify(filling, atLeastOnce()).getName();
}
}


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

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

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class IngredientParameterizedTest {

@Parameterized.Parameters(name = "type={0}, name={1}, price={2}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{IngredientType.SAUCE, "hot sauce", 100f},
{IngredientType.SAUCE, "sour cream", 0f},
{IngredientType.FILLING, "cutlet", 250.5f},
});
}

@Parameterized.Parameter(0)
public IngredientType type;

@Parameterized.Parameter(1)
public String name;

@Parameterized.Parameter(2)
public float price;

@Test
public void getType_returnsConstructorType() {
Ingredient ingredient = new Ingredient(type, name, price);
assertEquals(type, ingredient.getType());
}

@Test
public void getName_returnsConstructorName() {
Ingredient ingredient = new Ingredient(type, name, price);
assertEquals(name, ingredient.getName());
}

@Test
public void getPrice_returnsConstructorPrice() {
Ingredient ingredient = new Ingredient(type, name, price);
assertEquals(price, ingredient.getPrice(), 0.0001f);
}
}


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

import org.junit.Test;

import static org.junit.Assert.*;

public class IngredientTypeTest {

@Test
public void values_containsSauceAndFilling() {
IngredientType[] values = IngredientType.values();
assertArrayEquals(new IngredientType[]{IngredientType.SAUCE, IngredientType.FILLING}, values);
}

@Test
public void toString_returnsName() {
assertEquals("SAUCE", IngredientType.SAUCE.toString());
assertEquals("FILLING", IngredientType.FILLING.toString());
}
}


Binary file added target/jacoco.exec
Binary file not shown.
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="en"><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">0 of 193</td><td class="ctr2">100%</td><td class="bar">0 of 4</td><td class="ctr2">100%</td><td class="ctr1">0</td><td class="ctr2">17</td><td class="ctr1">0</td><td class="ctr2">40</td><td class="ctr1">0</td><td class="ctr2">15</td><td class="ctr1">0</td><td class="ctr2">4</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/greenbar.gif" width="120" height="10" title="193" alt="193"/></td><td class="ctr2" id="c0">100%</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">0</td><td class="ctr2" id="g0">17</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">40</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">15</td><td class="ctr1" id="l0">0</td><td class="ctr2" id="m0">4</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>
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