Last active
May 31, 2019 08:12
-
-
Save jasongorman/2029e078652a6ad8f697399ca845f7df 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
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; | |
Object[] item = new Object[] { | |
productCode , | |
productDescription , | |
price , | |
quantity | |
}; | |
basket.add(item); | |
double total = basket.stream() | |
.mapToDouble(i -> (double)i[PRICE] * (int)i[QUANTITY]) | |
.sum(); | |
assertEquals(100.0, total , 0.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment