-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathBasketTest.java
More file actions
63 lines (56 loc) · 1.68 KB
/
BasketTest.java
File metadata and controls
63 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.booleanuk.core;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
public class BasketTest {
@Test
public void canAddNewItem() {
Basket basket = new Basket();
String product = "eggs";
int price = 20;
Assertions.assertTrue(basket.add(product, price));
}
@Test
public void cannotAddExistingItem() {
Basket basket = new Basket();
String product = "eggs";
int price = 20;
basket.add(product, price);
Assertions.assertFalse(basket.add(product, price));
}
@Test
public void emptyBasketShouldHaveZeroTotal() {
Basket basket = new Basket();
Assertions.assertEquals(0, basket.total());
}
@Test
public void correctCostOfSingleItem() {
Basket basket = new Basket();
String product = "eggs";
int price = 20;
basket.add(product, price);
Assertions.assertEquals(price, basket.total());
}
@Test
public void correctCostOfSeveralItems() {
Basket basket = new Basket();
String prod1 = "eggs";
String prod2 = "milk";
String prod3 = "flour";
int price1 = 20;
int price2 = 22;
int price3 = 17;
basket.add(prod1, price1);
basket.add(prod2, price2);
basket.add(prod3, price3);
Assertions.assertEquals(59, basket.total());
}
@Test
public void addingExistingItemShouldNotIncreaseTotal() {
Basket basket = new Basket();
String product = "eggs";
int price = 20;
basket.add(product, price);
basket.add(product, price);
Assertions.assertEquals(20, basket.total());
}
}