-
Notifications
You must be signed in to change notification settings - Fork 0
add tests and jacoco report #5
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
supogolik-code
wants to merge
1
commit into
main
Choose a base branch
from
develop
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
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
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,23 @@ | ||
| package com.example; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Alex extends Lion { | ||
|
|
||
| public Alex(Feline feline) throws Exception { | ||
| super("Самец", feline); | ||
| } | ||
|
|
||
| public List<String> getFriends() { | ||
| return List.of("Марти", "Глория", "Мелман"); | ||
| } | ||
|
|
||
| public String getPlaceOfLiving() { | ||
| return "Нью-Йоркский зоопарк"; | ||
| } | ||
|
|
||
| @Override | ||
| public int getKittens() { | ||
| return 0; | ||
| } | ||
| } |
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
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,40 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| public class AlexTest { | ||
|
|
||
| @Test | ||
| public void getFriendsReturnsAlexFriends() throws Exception { | ||
| Alex alex = new Alex(mock(Feline.class)); | ||
|
|
||
| assertEquals(List.of("Марти", "Глория", "Мелман"), alex.getFriends()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getPlaceOfLivingReturnsNewYorkZoo() throws Exception { | ||
| Alex alex = new Alex(mock(Feline.class)); | ||
|
|
||
| assertEquals("Нью-Йоркский зоопарк", alex.getPlaceOfLiving()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getKittensReturnsZero() throws Exception { | ||
| Alex alex = new Alex(mock(Feline.class)); | ||
|
|
||
| assertEquals(0, alex.getKittens()); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesHaveManeReturnsTrue() throws Exception { | ||
| Alex alex = new Alex(mock(Feline.class)); | ||
|
|
||
| assertTrue(alex.doesHaveMane()); | ||
| } | ||
| } | ||
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,38 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class AnimalParameterizedTest { | ||
|
|
||
| private final String animalKind; | ||
| private final List<String> expectedFood; | ||
|
|
||
| public AnimalParameterizedTest(String animalKind, List<String> expectedFood) { | ||
| this.animalKind = animalKind; | ||
| this.expectedFood = expectedFood; | ||
| } | ||
|
|
||
| @Parameterized.Parameters(name = "{0}") | ||
| public static Collection<Object[]> getFoodData() { | ||
| return Arrays.asList(new Object[][]{ | ||
| {"Травоядное", List.of("Трава", "Различные растения")}, | ||
| {"Хищник", List.of("Животные", "Птицы", "Рыба")} | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFoodReturnsFoodByAnimalKind() throws Exception { | ||
| Animal animal = new Animal(); | ||
|
|
||
| assertEquals(expectedFood, animal.getFood(animalKind)); | ||
| } | ||
| } |
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,23 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| public class AnimalTest { | ||
|
|
||
| @Test | ||
| public void getFamilyReturnsAnimalFamilies() { | ||
| Animal animal = new Animal(); | ||
|
|
||
| assertEquals("Существует несколько семейств: заячьи, беличьи, мышиные, кошачьи, псовые, медвежьи, куньи", animal.getFamily()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFoodThrowsExceptionForUnknownAnimalKind() { | ||
| Animal animal = new Animal(); | ||
|
|
||
| assertThrows(Exception.class, () -> animal.getFood("Неизвестный вид")); | ||
| } | ||
| } |
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,31 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class CatTest { | ||
|
|
||
| @Test | ||
| public void getSoundReturnsMeow() { | ||
| Cat cat = new Cat(mock(Feline.class)); | ||
|
|
||
| assertEquals("Мяу", cat.getSound()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFoodReturnsPredatorFood() throws Exception { | ||
| Feline feline = mock(Feline.class); | ||
| List<String> expectedFood = List.of("Животные", "Птицы", "Рыба"); | ||
| when(feline.eatMeat()).thenReturn(expectedFood); | ||
| Cat cat = new Cat(feline); | ||
|
|
||
| assertEquals(expectedFood, cat.getFood()); | ||
|
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. ⛔️Нужно исправить. Для юнит-тестов применим подход: один тест, значит одна проверка. В этом тесте две проверки (Mockito.verify, assertEquals), а должна быть одна. Исправь, пожалуйста, этот момент во всем коде. |
||
| verify(feline).eatMeat(); | ||
| } | ||
| } | ||
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,36 @@ | ||
| package com.example; | ||
|
|
||
| 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 FelineParameterizedTest { | ||
|
|
||
| private final int kittensCount; | ||
|
|
||
| public FelineParameterizedTest(int kittensCount) { | ||
| this.kittensCount = kittensCount; | ||
| } | ||
|
|
||
| @Parameterized.Parameters(name = "kittensCount={0}") | ||
| public static Collection<Object[]> getKittensData() { | ||
| return Arrays.asList(new Object[][]{ | ||
| {0}, | ||
| {1}, | ||
| {5} | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void getKittensReturnsKittensCount() { | ||
| Feline feline = new Feline(); | ||
|
|
||
| assertEquals(kittensCount, feline.getKittens(kittensCount)); | ||
| } | ||
| } |
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,31 @@ | ||
| package com.example; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class FelineTest { | ||
|
|
||
| @Test | ||
| public void eatMeatReturnsPredatorFood() throws Exception { | ||
| Feline feline = new Feline(); | ||
|
|
||
| assertEquals(List.of("Животные", "Птицы", "Рыба"), feline.eatMeat()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFamilyReturnsCatFamily() { | ||
| Feline feline = new Feline(); | ||
|
|
||
| assertEquals("Кошачьи", feline.getFamily()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getKittensWithoutArgumentsReturnsOne() { | ||
| Feline feline = new Feline(); | ||
|
|
||
| assertEquals(1, feline.getKittens()); | ||
| } | ||
| } |
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,38 @@ | ||
| package com.example; | ||
|
|
||
| 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; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class LionParameterizedTest { | ||
|
|
||
| private final String sex; | ||
| private final boolean hasMane; | ||
|
|
||
| public LionParameterizedTest(String sex, boolean hasMane) { | ||
| this.sex = sex; | ||
| this.hasMane = hasMane; | ||
| } | ||
|
|
||
| @Parameterized.Parameters(name = "{0}") | ||
| public static Collection<Object[]> getManeData() { | ||
| return Arrays.asList(new Object[][]{ | ||
| {"Самец", true}, | ||
| {"Самка", false} | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesHaveManeReturnsExpectedValueBySex() throws Exception { | ||
| Lion lion = new Lion(sex, mock(Feline.class)); | ||
|
|
||
| assertEquals(hasMane, lion.doesHaveMane()); | ||
| } | ||
| } |
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.