-
Notifications
You must be signed in to change notification settings - Fork 2k
Develop1 #1138
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?
Develop1 #1138
Conversation
| when(mockbun.getPrice()).thenReturn(100.0f); | ||
| when(mockIngredient.getType()).thenReturn(ingredientType); | ||
| when(mockIngredient.getName()).thenReturn("Test Ingredient"); | ||
| when(mockIngredient.getPrice()).thenReturn(50.0f); |
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.
| private Bun mockBun; | ||
|
|
||
| @Mock | ||
| private Ingredient mockIngredient1; |
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.
⛔️Нужно исправить. При нейминге не рекомендуется использовать числа (Field2), их еще называют magicNumbers. Очень тяжело поддерживать код с magicNumbers.
| public void testAddIngredient() { | ||
| Burger burger = new Burger(); | ||
| burger.addIngredient(mockIngredient1); | ||
| assertEquals("Ingredients list should have 1 element", 1, burger.ingredients.size()); |
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.
⛔️Нужно исправить. Для юнит-тестов придерживаемся подхода: один тест, значит одна проверка. Если очень хочется несколько проверок -- тогда используем softAssertions. Поправь, пожалуйста, во всем коде
| burger.addIngredient(mockIngredient2); | ||
|
|
||
| // burger.moveIngredient(0, 1); | ||
| // |
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.
⛔️Нужно исправить. Неиспользуемый код нужно удалить
| float expectedPrice = 100.0f * 2; | ||
| float actualPrice = burger.getPrice(); | ||
|
|
||
| assertEquals("Price should be only buns price when no ingredients", expectedPrice, actualPrice, 0.001f); |
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.
⛔️Нужно исправить. Для юнит-тестов применим подход: один тест, значит одна проверка. В этом тесте две проверки (Mockito.verify, assertEquals), а должна быть одна. Исправь, пожалуйста, этот момент во всем коде.
|
|
||
| @Test | ||
| public void testGetPriceWithoutIngredients() { | ||
| Burger burger = new Burger(); |
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.
| String receipt = burger.getReceipt(); | ||
|
|
||
| assertNotNull("Receipt should not be null", receipt); | ||
| assertTrue("Receipt should contain bun name", receipt.contains("Test Bun")); |
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.
⛔️Нужно исправить. Строку рецепта нужно проверить целиком в одной проверке, чтобы не пропустить проблем с форматированием текста
Create test for the burger class - diplom 1