Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created May 31, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/9a2a9926739c6876e3ad292b177edaa4 to your computer and use it in GitHub Desktop.
Save jasongorman/9a2a9926739c6876e3ad292b177edaa4 to your computer and use it in GitHub Desktop.
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