Bael 7317 (#15415)
* 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:
committed by
GitHub
parent
f471384958
commit
164ef67325
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user