Skip to content

Commit c73f66c

Browse files
BENCH-153 Addressed Andrews PR Comment: I would also suggest searching the codebase for any strings matching 'available' and see if there are any other ones we've missed
1 parent e29c35c commit c73f66c

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/main/java/com/answerdigital/academy/answerking/service/OrderService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Order addProductToBasket(final Long orderId, final Long productId, final
6161
final Product product = productService.findById(productId);
6262

6363
if (product.isRetired()) {
64-
throw new RetirementException(String.format("The product with ID %d is not available.", product.getId()));
64+
throw new RetirementException(String.format("The product with ID %d has been retired", product.getId()));
6565
}
6666

6767
final Optional<LineItem> existingLineItem = order.getLineItems()

src/main/resources/test-data.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ INSERT INTO category (id, name, description) values
1919
name = name,
2020
description = description;
2121

22-
INSERT INTO product (id, name, description, available, price) values
22+
INSERT INTO product (id, name, description, retired, price) values
2323
(1, 'Answer Whopper', 'The biggest burger', true, '5.99'),
2424
(2, 'Chicken Burger', 'Standard chicken burger', true, '3.99'),
2525
(3, 'Cheese Burger', 'standard cheese burger', true, '2.99')
2626
ON DUPLICATE KEY UPDATE id = id,
2727
name = name,
2828
description = description,
29-
available = available,
29+
retired = retired,
3030
price = price;
3131

3232
INSERT INTO product_category (id, product_id, category_id) values

src/test/java/com/answerdigital/academy/answerking/controller/ProductControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void getProductByIdReturnsNotFoundExceptionIfIdDoesNotExist() throws Exception {
111111
@Test
112112
void addProductWithInvalidNameThrowsException() throws Exception {
113113
//given
114-
String newProduct = "{\"name\": \"abc12\",\"description\": \"descTest\",\"price\": \"4.75\",\"available\": \"true\"}";
114+
String newProduct = "{\"name\": \"abc12\",\"description\": \"descTest\",\"price\": \"4.75\"}";
115115
//when
116116
final String error = mvc.perform(post("/products")
117117
.content(newProduct)
@@ -128,7 +128,7 @@ void addProductWithInvalidNameThrowsException() throws Exception {
128128
@Test
129129
void addProductWithValidObjectReturnsProductAndOkStatus() throws Exception {
130130
//given
131-
String newProduct = "{\"name\": \"test\",\"description\": \"descTest\",\"price\": \"4.75\",\"available\": \"true\"}";
131+
String newProduct = "{\"name\": \"test\",\"description\": \"descTest\",\"price\": \"4.75\"}";
132132
given(productService.addNewProduct(any())).willReturn(product);
133133

134134
//when
@@ -146,7 +146,7 @@ void addProductWithValidObjectReturnsProductAndOkStatus() throws Exception {
146146
@Test
147147
void updateProductWithInvalidPriceThrowsException() throws Exception {
148148
//given
149-
String newProduct = "{\"name\": \"abc\",\"description\": \"descTest\",\"price\": \"4.7587\",\"available\": \"true\"}";
149+
String newProduct = "{\"name\": \"abc\",\"description\": \"descTest\",\"price\": \"4.7587\"}";
150150
//when
151151
final String error = mvc.perform(MockMvcRequestBuilders.put("/products/{id}", 55L)
152152
.content(newProduct)
@@ -164,7 +164,7 @@ void updateProductWithInvalidPriceThrowsException() throws Exception {
164164
@Test
165165
void updateProductWithValidObjectReturnsProductAndOkStatus() throws Exception {
166166
//given
167-
String newProduct = "{\"name\": \"test\",\"description\": \"descTest\",\"price\": \"4.75\",\"available\": \"true\"}";
167+
String newProduct = "{\"name\": \"test\",\"description\": \"descTest\",\"price\": \"4.75\"}";
168168
given(productService.updateProduct(eq(55L), any())).willReturn(product);
169169
//when
170170

src/test/java/com/answerdigital/academy/answerking/service/OrderServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void testAddProductToBasketWhenOrderDoesNotExistThrowsNotFoundException() {
234234
}
235235

236236
@Test
237-
void testAddProductToBasketWhenProductIsUnavailableThrowsProductUnavailableException() {
237+
void testAddProductToBasketWhenProductIsRetiredThrowsRetirementException() {
238238
// Given
239239
Order order = Order.builder()
240240
.lineItems(new HashSet<>())

0 commit comments

Comments
 (0)