Created
April 28, 2021 19:00
-
-
Save jondef/eeab4451a8b0206797b6b9aabd751890 to your computer and use it in GitHub Desktop.
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
package ch.zhaw.prog2.shoppinglist_product; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.mockito.Mockito.when; | |
/** | |
* Testen der Methode getTotalCosts aus der Klasse Shopping | |
* | |
* @author bles | |
*/ | |
class ShoppingListTest { | |
private ShoppingList shoppingList; | |
// Ansatz: Die Produkte selbst mocken (für testGetTotalCostsWithProductMock()) | |
// PriceService wird nicht mehr verwendet | |
@Mock | |
Product milkMock; | |
@Mock Product saladMock; | |
@BeforeEach | |
void setUp() { | |
MockitoAnnotations.initMocks(this); | |
when(milkMock.getPrice()).thenReturn(5.0); | |
when(milkMock.getQuantity()).thenReturn(3); | |
when(saladMock.getPrice()).thenReturn(2.0); | |
when(saladMock.getQuantity()).thenReturn(2); | |
shoppingList = new ShoppingList(); | |
shoppingList.addProduct(saladMock); | |
shoppingList.addProduct(milkMock); | |
} | |
@Test | |
void testGetTotalCostsWithProductMock() { | |
assertEquals(19.0, shoppingList.getTotalCosts()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment