* BAEL-7226: Code for the improvements of the Percentages article.

* BAEL-7226: Rename Test to follow the convention

* BAEL-7317: Update the code to the latest versions of Spock, Groovy and the maven matching configuration

* BAEL-7317: Add code for the article improvements
This commit is contained in:
Oscar Mauricio Forero Carrillo
2023-12-30 09:42:21 +01:00
committed by GitHub
parent f471384958
commit 164ef67325
10 changed files with 166 additions and 8 deletions
@@ -0,0 +1,11 @@
package mocks;
public class Book {
private String title;
private String author;
Book(String title, String author) {
this.title = title;
this.author = author;
}
}
@@ -0,0 +1,5 @@
package mocks;
public interface BookRepository {
Book findById(Long id);
}
@@ -0,0 +1,13 @@
package mocks;
public class BookService {
private final BookRepository repository;
public BookService(BookRepository repository) {
this.repository = repository;
}
public Book getBookDetails(Long id) {
return repository.findById(id);
}
}
@@ -0,0 +1,7 @@
package mocks;
public class MessageService {
public String fetchMessage() {
return UtilityClass.getMessage();
}
}
@@ -0,0 +1,26 @@
package mocks;
import java.util.HashMap;
import java.util.Map;
public class ShoppingCart {
private final Map<String, Integer> items = new HashMap<>();
private double totalPrice = 0.0;
public void addItem(String item, int quantity) {
items.put(item, items.getOrDefault(item, 0) + quantity);
totalPrice += quantity * 2.00; // Example pricing
}
public int getTotalItems() {
return items.values().stream().mapToInt(Integer::intValue).sum();
}
public double getTotalPrice() {
return totalPrice;
}
public boolean containsItem(String item) {
return items.containsKey(item);
}
}
@@ -0,0 +1,7 @@
package mocks;
public class UtilityClass {
public static String getMessage() {
return "Original Message";
}
}