-
Notifications
You must be signed in to change notification settings - Fork 2k
unit tests for Burger (develop1) #1154
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,64 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.example</groupId> | ||
| <artifactId>praktikum</artifactId> | ||
| <groupId>praktikum</groupId> | ||
| <artifactId>stellar-burgers</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> | ||
| </properties> | ||
|
|
||
| </project> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.13.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>5.11.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.hamcrest</groupId> | ||
| <artifactId>hamcrest</artifactId> | ||
| <version>2.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.jacoco</groupId> | ||
| <artifactId>jacoco-maven-plugin</artifactId> | ||
| <version>0.8.11</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>prepare-agent</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>report</id> | ||
| <phase>test</phase> | ||
| <goals> | ||
| <goal>report</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package praktikum; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class BurgerTest { | ||
|
|
||
| @Test | ||
| public void emptyBurger_shouldHaveZeroIngredients() { | ||
| Burger burger = new Burger(); | ||
| assertEquals(0, burger.ingredients.size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void setBuns_shouldAssignBun() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Неверный нейминг. Не используем спецсимволы в названии методов |
||
| Bun bun = new Bun("black bun", 100.0f); | ||
| Burger burger = new Burger(); | ||
|
|
||
| burger.setBuns(bun); | ||
|
|
||
| assertEquals("black bun", burger.bun.getName()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Для юнит-тестов придерживаемся подхода: один тест, значит одна проверка. Если очень хочется несколько проверок -- тогда используем softAssertions. Поправь, пожалуйста, во всем коде |
||
| assertEquals(100.0f, burger.bun.getPrice(), 0.001f); | ||
| } | ||
|
|
||
| @Test | ||
| public void addIngredient_shouldAddToList() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("default", 50.0f)); | ||
|
|
||
| Ingredient ingredient = new Ingredient(IngredientType.SAUCE, "chili", 15.0f); | ||
| burger.addIngredient(ingredient); | ||
|
|
||
| assertEquals(1, burger.ingredients.size()); | ||
| assertEquals("chili", burger.ingredients.get(0).getName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void removeIngredient_shouldRemoveFromList() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("default", 50.0f)); | ||
| Ingredient ingredient = new Ingredient(IngredientType.FILLING, "cheese", 40.0f); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Для всех зависимостей нужно использовать моки |
||
| burger.addIngredient(ingredient); | ||
|
|
||
| burger.removeIngredient(0); | ||
|
|
||
| assertEquals(0, burger.ingredients.size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void moveIngredient_shouldChangeOrder() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("default", 50.0f)); | ||
|
|
||
| Ingredient first = new Ingredient(IngredientType.SAUCE, "bbq", 10.0f); | ||
| Ingredient second = new Ingredient(IngredientType.FILLING, "beef", 80.0f); | ||
| burger.addIngredient(first); | ||
| burger.addIngredient(second); | ||
|
|
||
| burger.moveIngredient(0, 1); | ||
|
|
||
| assertEquals("bbq", burger.ingredients.get(1).getName()); | ||
| assertEquals("beef", burger.ingredients.get(0).getName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getPrice_shouldSumBunsAndIngredients() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("white bun", 60.0f)); | ||
| burger.addIngredient(new Ingredient(IngredientType.SAUCE, "garlic", 20.0f)); | ||
| burger.addIngredient(new Ingredient(IngredientType.FILLING, "cutlet", 100.0f)); | ||
|
|
||
| float expected = 2 * 60.0f + 20.0f + 100.0f; | ||
| assertEquals(expected, burger.getPrice(), 0.001f); | ||
| } | ||
|
|
||
| @Test | ||
| public void getPrice_withoutIngredients_shouldBeDoubleBunPrice() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("black bun", 100.0f)); | ||
|
|
||
| float expected = 2 * 100.0f; | ||
| assertEquals(expected, burger.getPrice(), 0.001f); | ||
| } | ||
|
|
||
| @Test | ||
| public void getReceipt_shouldContainBunsIngredientsAndPrice() { | ||
| Burger burger = new Burger(); | ||
| burger.setBuns(new Bun("black bun", 100.0f)); | ||
| burger.addIngredient(new Ingredient(IngredientType.SAUCE, "spicy", 30.0f)); | ||
| burger.addIngredient(new Ingredient(IngredientType.FILLING, "cheese", 40.0f)); | ||
|
|
||
| String receipt = burger.getReceipt(); | ||
|
|
||
| assertTrue(receipt.contains("(==== black bun ====)")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Строку рецепта нужно проверять целиком, чтобы не пропустить ошибки форматирования |
||
| assertTrue(receipt.contains("= sauce spicy =")); | ||
| assertTrue(receipt.contains("= filling cheese =")); | ||
| assertTrue(receipt.contains("(==== black bun ====)")); | ||
|
|
||
| String expectedPriceLine = String.format("Price: %f", burger.getPrice()); | ||
| assertTrue(receipt.contains(expectedPriceLine)); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Нужно написать параметризированные тесты. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| praktikum/Bun.class | ||
| praktikum/IngredientType.class | ||
| praktikum/Database.class | ||
| praktikum/Praktikum.class | ||
| praktikum/Burger.class | ||
| praktikum/Ingredient.class |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/Bun.java | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/Burger.java | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/Database.java | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/Ingredient.java | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/IngredientType.java | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/main/java/praktikum/Praktikum.java |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| praktikum/BurgerTest.class |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /Users/kirillkovalev/Desktop/QA-java-diplom-1/src/test/java/praktikum/BurgerTest.java |
| 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>stellar-burgers</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">stellar-burgers</span></div><h1>stellar-burgers</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.11.202310140853</span></div></body></html> |
| 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; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛔️Нужно исправить. Папку .idea не нужно было загружать в репозиторий. Эта папка должна быть добавлена в .gitignore.