Apply eclipse code format
This commit is contained in:
parent
9935885d3b
commit
c1b36b3bb0
@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
class ItemTransportObject {
|
||||
private String name;
|
||||
private Integer quantity;
|
||||
private String category;
|
||||
private String name;
|
||||
private Integer quantity;
|
||||
private String category;
|
||||
}
|
||||
|
@ -12,15 +12,15 @@ import lombok.Data;
|
||||
@Data
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
public final Integer id;
|
||||
@Column
|
||||
public final String name;
|
||||
@Column
|
||||
public final Float price;
|
||||
@Id
|
||||
public final Integer id;
|
||||
@Column
|
||||
public final String name;
|
||||
@Column
|
||||
public final Float price;
|
||||
|
||||
public CartItem toItem() {
|
||||
return new CartItem(name, price);
|
||||
}
|
||||
public CartItem toItem() {
|
||||
return new CartItem(name, price);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ import com.baeldung.hexagonal.domain.ports.ProductRepository;
|
||||
@Repository
|
||||
public interface ProductCrudRepository extends CrudRepository<Product, Integer>, ProductRepository {
|
||||
|
||||
Product findByName(String name);
|
||||
Product findByName(String name);
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import lombok.NonNull;
|
||||
@Data
|
||||
public class CartItem {
|
||||
|
||||
@NonNull
|
||||
private final String name;
|
||||
private final Float price;
|
||||
@NonNull
|
||||
private final String name;
|
||||
private final Float price;
|
||||
|
||||
}
|
||||
|
@ -7,16 +7,19 @@ import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
class ShoppingCart {
|
||||
|
||||
private final Map<CartItem, Integer> itemToQuantity;
|
||||
private final Map<CartItem, Integer> itemToQuantity;
|
||||
|
||||
Float getTotalCartValue() {
|
||||
return itemToQuantity.entrySet().stream()
|
||||
.map(item -> item.getKey().getPrice() * item.getValue()).reduce(0f, Float::sum);
|
||||
}
|
||||
Float getTotalCartValue() {
|
||||
return itemToQuantity.entrySet()
|
||||
.stream()
|
||||
.map(item -> item.getKey()
|
||||
.getPrice() * item.getValue())
|
||||
.reduce(0f, Float::sum);
|
||||
}
|
||||
|
||||
void addItem(CartItem cartItem, Integer quantity) {
|
||||
if (quantity < 0)
|
||||
throw new IllegalArgumentException("Quantity should not be negative.");
|
||||
itemToQuantity.put(cartItem, itemToQuantity.getOrDefault(cartItem, 0) + quantity);
|
||||
}
|
||||
void addItem(CartItem cartItem, Integer quantity) {
|
||||
if (quantity < 0)
|
||||
throw new IllegalArgumentException("Quantity should not be negative.");
|
||||
itemToQuantity.put(cartItem, itemToQuantity.getOrDefault(cartItem, 0) + quantity);
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ import com.baeldung.hexagonal.adapter.out.Product;
|
||||
|
||||
public interface ProductRepository {
|
||||
|
||||
Product findByName(String name);
|
||||
Product findByName(String name);
|
||||
}
|
||||
|
@ -7,23 +7,22 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
class ShoppingCartTest {
|
||||
|
||||
@Test
|
||||
void givenNonemptyShoppingCart_whenGetTotalCartValueCalled_thenShouldCalculateCorrectly() {
|
||||
@Test
|
||||
void givenNonemptyShoppingCart_whenGetTotalCartValueCalled_thenShouldCalculateCorrectly() {
|
||||
|
||||
// given
|
||||
Map<CartItem, Integer> items = new HashMap<>();
|
||||
items.put(new CartItem("Cheese", 1.5f), 2);
|
||||
items.put(new CartItem("Lemon", 2f), 5);
|
||||
// given
|
||||
Map<CartItem, Integer> items = new HashMap<>();
|
||||
items.put(new CartItem("Cheese", 1.5f), 2);
|
||||
items.put(new CartItem("Lemon", 2f), 5);
|
||||
|
||||
ShoppingCart cart = new ShoppingCart(items);
|
||||
ShoppingCart cart = new ShoppingCart(items);
|
||||
|
||||
// when
|
||||
Float totalCartValue = cart.getTotalCartValue();
|
||||
// when
|
||||
Float totalCartValue = cart.getTotalCartValue();
|
||||
|
||||
// then
|
||||
assertEquals(totalCartValue, 13f, 0);
|
||||
}
|
||||
// then
|
||||
assertEquals(totalCartValue, 13f, 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user