-
Notifications
You must be signed in to change notification settings - Fork 2k
final_Task1 юнит-тесты #1156
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
includingByMeAndMyself
wants to merge
1
commit into
yandex-praktikum:main
Choose a base branch
from
includingByMeAndMyself:dev_firstTask
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
final_Task1 юнит-тесты #1156
Changes from all commits
Commits
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
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
| 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 | ||
|
|
||
|
|
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,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); | ||
| } | ||
| } | ||
|
|
||
|
|
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,110 @@ | ||
| package praktikum; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| 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(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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,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); | ||
| } | ||
| } | ||
|
|
||
|
|
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,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 not shown.
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="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> |
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.
Импорт не используется