-
Notifications
You must be signed in to change notification settings - Fork 2k
Создание pom.xml , и покрытие тестами класса Burger #1135
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
Open
MikV37
wants to merge
7
commits into
yandex-praktikum:main
Choose a base branch
from
MikV37:develop1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be034a4
Создание pom.xml , и покрытие тестами класса Burger
MikV37 9184ef9
Исправление по замечаним
MikV37 5f3e1bf
Удалены лишние комментарии
MikV37 cd771af
Удалены лишние комментарии
MikV37 12e388d
add jacoco report
MikV37 98db8ef
add jacoco report
MikV37 36cedca
Merge remote-tracking branch 'origin/develop1' into develop1
MikV37 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package praktikum; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class BurgerPriceParameterizedTest { | ||
|
|
||
|
|
||
| private final float bunPrice; | ||
| private final float[] ingredientPrices; | ||
| private final float expectedTotalPrice; | ||
|
|
||
|
|
||
| public BurgerPriceParameterizedTest(float bunPrice, float[] ingredientPrices, float expectedTotalPrice) { | ||
| this.bunPrice = bunPrice; | ||
| this.ingredientPrices = ingredientPrices; | ||
| this.expectedTotalPrice = expectedTotalPrice; | ||
| } | ||
|
|
||
|
|
||
| @Parameterized.Parameters(name = "Цена бургера (булка: {0}, ингредиенты: {1}) = {2}") | ||
| public static Collection<Object[]> data() { | ||
| return Arrays.asList(new Object[][]{ | ||
|
|
||
| {10.0f, new float[]{}, 20.0f}, | ||
| {100.0f, new float[]{50.0f}, 250.0f}, | ||
| {125.5f, new float[]{200.0f, 25.5f}, 476.5f} | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void getPriceShouldCalculateCorrectly() { | ||
| Burger burger = new Burger(); | ||
|
|
||
|
|
||
| Bun mockBun = Mockito.mock(Bun.class); | ||
| when(mockBun.getPrice()).thenReturn(bunPrice); | ||
| burger.setBuns(mockBun); | ||
|
|
||
|
|
||
| for (float ingredientPrice : ingredientPrices) { | ||
| Ingredient mockIngredient = Mockito.mock(Ingredient.class); | ||
| when(mockIngredient.getPrice()).thenReturn(ingredientPrice); | ||
| burger.addIngredient(mockIngredient); | ||
| } | ||
|
|
||
|
|
||
| assertEquals("Расчет цены неверен", expectedTotalPrice, burger.getPrice(), 0.001f); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package praktikum; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class BurgerTest { | ||
|
|
||
| private Burger burger; | ||
|
|
||
| @Mock | ||
| private Bun mockBun; | ||
|
|
||
| @Mock | ||
| private Ingredient mockSauce; | ||
| @Mock | ||
| private Ingredient mockFilling; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| burger = new Burger(); | ||
| } | ||
|
|
||
| @Test | ||
| public void setBunsShouldSetTheBun() { | ||
| burger.setBuns(mockBun); | ||
|
|
||
| assertEquals("Булочка не была установлена", mockBun, burger.bun); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void addIngredientShouldIncreaseListSize() { | ||
| burger.addIngredient(mockSauce); | ||
|
|
||
| assertEquals("Размер списка должен быть 1", 1, burger.ingredients.size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void addIngredientShouldAddCorrectIngredient() { | ||
| burger.addIngredient(mockSauce); | ||
|
|
||
| assertSame("Добавлен неверный ингредиент", mockSauce, burger.ingredients.get(0)); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void removeIngredientShouldDecreaseListSize() { | ||
| burger.addIngredient(mockSauce); | ||
| burger.addIngredient(mockFilling); | ||
| burger.removeIngredient(0); | ||
|
|
||
| assertEquals("Размер списка должен быть 1 после удаления", 1, burger.ingredients.size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void removeIngredientShouldRemoveCorrectIngredient() { | ||
| burger.addIngredient(mockSauce); | ||
| burger.addIngredient(mockFilling); | ||
| burger.removeIngredient(0); | ||
|
|
||
| assertSame("Оставшийся ингредиент неверен", mockFilling, burger.ingredients.get(0)); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void moveIngredientShouldPlaceIngredientAtNewIndex() { | ||
| burger.addIngredient(mockSauce); | ||
| burger.addIngredient(mockFilling); | ||
| burger.moveIngredient(0, 1); | ||
|
|
||
| assertSame("Соус должен быть на новой позиции", mockSauce, burger.ingredients.get(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void moveIngredientShouldShiftOtherIngredient() { | ||
| burger.addIngredient(mockSauce); | ||
| burger.addIngredient(mockFilling); | ||
| burger.moveIngredient(0, 1); | ||
|
|
||
| assertSame("Начинка должна была сдвинуться", mockFilling, burger.ingredients.get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void getReceiptShouldReturnCorrectString() { | ||
|
|
||
| when(mockBun.getName()).thenReturn("Краторная булка"); | ||
| when(mockBun.getPrice()).thenReturn(100.0f); | ||
| when(mockSauce.getType()).thenReturn(IngredientType.SAUCE); | ||
| when(mockSauce.getName()).thenReturn("Соус галактический"); | ||
| when(mockSauce.getPrice()).thenReturn(20.5f); | ||
| when(mockFilling.getType()).thenReturn(IngredientType.FILLING); | ||
| when(mockFilling.getName()).thenReturn("Котлета"); | ||
| when(mockFilling.getPrice()).thenReturn(150.0f); | ||
|
|
||
| burger.setBuns(mockBun); | ||
| burger.addIngredient(mockSauce); | ||
| burger.addIngredient(mockFilling); | ||
|
|
||
| float expectedPrice = 100.0f * 2 + 20.5f + 150.0f; | ||
| String expectedReceipt = String.format("(==== Краторная булка ====)%n" + | ||
| "= sauce Соус галактический =%n" + | ||
| "= filling Котлета =%n" + | ||
| "(==== Краторная булка ====)%n" + | ||
| "%nPrice: %f%n", expectedPrice); | ||
|
|
||
|
|
||
| String actualReceipt = burger.getReceipt(); | ||
|
|
||
|
|
||
| assertEquals("Сгенерированный чек не соответствует ожидаемому", expectedReceipt, actualReceipt); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
⛔️Нужно исправить. нет отчета о тестировании