Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
459c8e5
Updates pom.xml with newer versions
fredrikmohlen Feb 2, 2026
ff5af72
Creates Test whenMakingCorrectBookingBookRoomReturnTrue. And test green
fredrikmohlen Feb 2, 2026
b579046
Creates and completes test: shouldThrowExceptionForInvalidInput
fredrikmohlen Feb 2, 2026
8f1c12f
Creates and completes test: shouldThrowExceptionForInvalidInput
fredrikmohlen Feb 2, 2026
019e726
Creates test: whenRoomDoesNotExistBookRoomReturnException.
fredrikmohlen Feb 2, 2026
70a280a
Creates two tests for method bookRoom, for occupiedRoom and failed no…
fredrikmohlen Feb 2, 2026
7e840a9
Creates test invalid input for method getAvailableRooms
fredrikmohlen Feb 2, 2026
aa8d3f5
Creates test for getAvailableRooms, and pass
fredrikmohlen Feb 2, 2026
e3b265f
Write 4 tests for method cancelBooking and pass.
fredrikmohlen Feb 3, 2026
c94af23
First test written, first red then make needed class, get test green.…
fredrikmohlen Feb 6, 2026
0517be7
Test with totalPrice. Made new method in ShoppingCart
fredrikmohlen Feb 6, 2026
fc7426f
Test with remove item from the ShoppingCart list.
fredrikmohlen Feb 6, 2026
305d38e
Remove comments in BookingSystemTest
fredrikmohlen Feb 6, 2026
9d37aae
Test and method, dealing with quantity increasing
fredrikmohlen Feb 6, 2026
f5e35c4
Write test for discounts, with changes to methods in shoppingcart and…
fredrikmohlen Feb 6, 2026
ac894cf
rearrange som written code
fredrikmohlen Feb 6, 2026
4c94f96
small changes and test to check for zero price when cart is empty
fredrikmohlen Feb 6, 2026
314a244
Two more zero-checks
fredrikmohlen Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.4</version>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.3</version>
<version>3.27.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.15.2</version>
<version>5.21.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -37,17 +37,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.14.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.4</version>
<executions>
<execution>
<goals>
Expand All @@ -60,7 +60,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<version>0.8.14</version>
<configuration>
<skip>true</skip>
</configuration>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/example/shop/DiscountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.shop;

import java.math.BigDecimal;

public interface DiscountService {
BigDecimal getDiscountMultiplier(String itemName);
}
45 changes: 45 additions & 0 deletions src/main/java/com/example/shop/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.shop;

import java.math.BigDecimal;
import java.util.Objects;

public class Item {

private final String name;
private final BigDecimal price;
private int quantity;
private final BigDecimal discountPercentage;
public Item(String name, BigDecimal price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
this.discountPercentage = BigDecimal.ZERO;
}

public String getName() {
return name;
}

public BigDecimal getPrice() {
return price;
}

public int getQuantity() {
return quantity;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Item item)) return false;
return quantity == item.quantity && Objects.equals(name, item.name) && Objects.equals(price, item.price) && Objects.equals(discountPercentage, item.discountPercentage);
}

@Override
public int hashCode() {
return Objects.hash(name, price, quantity, discountPercentage);
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/example/shop/ShoppingCart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.shop;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class ShoppingCart {
private final List<Item> items = new ArrayList<>();
private final DiscountService discountService;

ShoppingCart(DiscountService discountService) {
this.discountService = discountService;
}
ShoppingCart() {
this.discountService = itemName -> BigDecimal.ONE;
}

public void addItem(Item newItem) {
items.stream()
.filter(item -> item.getName().equals(newItem.getName()))
.findFirst()
.ifPresentOrElse(
existing -> existing.setQuantity(existing.getQuantity() + newItem.getQuantity()),
() -> items.add(newItem)
);
}

public List<Item> getItems() {
return items;
}

public BigDecimal getTotalPrice() {
BigDecimal totalPrice = BigDecimal.ZERO;
for(Item item : items) {
BigDecimal multiplier = discountService.getDiscountMultiplier(item.getName());
if (multiplier == null) {
multiplier = BigDecimal.ONE;
}
BigDecimal itemTotal = item.getPrice()
.multiply(BigDecimal.valueOf(item.getQuantity()))
.multiply(multiplier);

totalPrice = totalPrice.add(itemTotal);
}
return totalPrice;
}

public void removeItem(Item item) {
items.remove(item);
}
}
Loading