Skip to content
56 changes: 56 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Domain model

## User stories
### User story 1
```
As a member of the public,
So I can order a bagel before work,
I'd like to add a specific type of bagel to my basket.
```

### User story 2
```
As a member of the public,
So I can change my order,
I'd like to remove a bagel from my basket.
```

### User story 3
```
As a member of the public,
So that I can not overfill my small bagel basket
I'd like to know when my basket is full when I try adding an item beyond my basket capacity.
```

### User story 4
```
As a Bob's Bagels manager,
So that I can expand my business,
I’d like to change the capacity of baskets.
```

### User story 5
```
As a member of the public
So that I can maintain my sanity
I'd like to know if I try to remove an item that doesn't exist in my basket.
```


## Shopping Basket Class

### Variables
| Variables | Description |
|-----------------------------|----------------------------------------------------------------------|
| `List<String bagle> basket` | Container containing the bagels the customer has added to basket. |
| `Integer basketSize` | Size of the basket. |

### Methods
| Methods | Scenario | Outputs |
|--------------------------------------|------------------------------------------------------------------|-------------------------------------------|
| `String addBagel(String bagle)` | Customer successfully adds bagel to basket | `Bagel added successfully.` |
| | Customer fails to add bagel to basket as basket is full | `Basket is full.` |
| `String removeBagel(String bagle)` | Customer successfully removes bagel from basket | `Bagel successfully removed from basket.` |
| | Customer tries to remove bagel not in the basket from the basket | `This bagel is not in your basket.` |
| `Void changeBasketSize(int newSize)` | Manager changes the size of the basket | - |

28 changes: 28 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
ArrayList<String> basket = new ArrayList<>();
Integer basketSize = 1;

public String addBagel(String bagel) {

// If the size of the basket is equal to or larger
if (basket.size() == this.basketSize)
return "Basket is full.";

basket.add(bagel);
return "Bagel added successfully.";
}

public String removeBagel(String bagel) {

if (!basket.contains(bagel)) {
return "This bagel is not in your basket.";
}

basket.remove(bagel);
return "Bagel successfully removed from basket.";
}

public void changeBasketSize(Integer newBasketSize) {
this.basketSize = newBasketSize;
}
}

57 changes: 57 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,62 @@
import org.junit.jupiter.api.Test;

class BasketTest {
@Test
public void addBagelTest(){
Basket b = new Basket();
b.basketSize = 1;

// Expected return strings
String expectedSuccess = "Bagel added successfully.";
String expectedFail = "Basket is full.";

// Resulting strings from addBagel execution
String testSuccess = b.addBagel("Cream");
String testFail = b.addBagel("Chocolate");

Assertions.assertEquals(expectedSuccess, testSuccess);
Assertions.assertEquals(expectedFail, testFail);
}

@Test
public void removeBagelTest(){
Basket b = new Basket();
b.addBagel("Chocolate");

// Expected return strings
String expectedSuccess = "Bagel successfully removed from basket.";
String expectedFail = "This bagel is not in your basket.";

// Resulting strings from removeBagel execution
String testSuccess = b.removeBagel("Chocolate");
String testFail = b.removeBagel("Cream");

Assertions.assertEquals(expectedSuccess, testSuccess);
Assertions.assertEquals(expectedFail, testFail);
}

@Test
public void changeBasketSizeTest(){
Basket b = new Basket();
b.basketSize = 1;

String basketIsNotFull = "Bagel added successfully.";
String basketIsFull = "Basket is full.";

// Triggers basket is full error
b.addBagel("Cheese");
String failString = b.addBagel("Chocolate");

// Verifies basket is full error
Assertions.assertEquals(basketIsFull, failString);

// Changes size of basketSize and verifies equality
int newBasketSize = 2;
b.changeBasketSize(newBasketSize);
Assertions.assertEquals(newBasketSize, b.basketSize);

// Repeat first test to demonstrate that the basket has increased
String successString = b.addBagel("Chocolate");
Assertions.assertEquals(basketIsNotFull, successString);
}
}