Created
May 31, 2019 08:19
-
-
Save jasongorman/9a2a9926739c6876e3ad292b177edaa4 to your computer and use it in GitHub Desktop.
This file contains 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
import static org.junit.Assert.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.junit.Test; | |
public class ShoppingCartTest { | |
private static final int PRICE = 2; | |
private static final int QUANTITY = 3; | |
@Test | |
public void addingItemChangesBasketTotal() { | |
List<Object[]> basket = new ArrayList<>(); | |
String productCode = "P111"; | |
String productDescription = "Widget (Large)"; | |
double price = 10.0; | |
int quantity = 10; | |
addItem(basket, productCode, productDescription, price, quantity); | |
double total = basket.stream() | |
.mapToDouble(i -> (double)i[PRICE] * (int)i[QUANTITY]) | |
.sum(); | |
assertEquals(100.0, total , 0.0); | |
} | |
private void addItem(List<Object[]> basket, | |
String productCode, | |
String productDescription, | |
double price, | |
int quantity) { | |
Object[] item = new Object[] { | |
productCode , | |
productDescription , | |
price , | |
quantity | |
}; | |
basket.add(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment