Skip to content

Commit d6ebb86

Browse files
committed
Merge branch 'main' into BENCH-182-TEST
# Conflicts: # src/main/java/com/answerdigital/answerking/controller/CategoryController.java # src/main/java/com/answerdigital/answerking/controller/OrderController.java # src/main/java/com/answerdigital/answerking/mapper/ProductMapper.java # src/main/java/com/answerdigital/answerking/response/ProductResponse.java # src/main/java/com/answerdigital/answerking/service/CategoryService.java # src/main/java/com/answerdigital/answerking/service/OrderService.java # src/test/java/com/answerdigital/answerking/service/CategoryServiceTest.java # src/test/java/com/answerdigital/answerking/service/OrderServiceTest.java
2 parents 70647f4 + ee53527 commit d6ebb86

File tree

9 files changed

+23
-29
lines changed

9 files changed

+23
-29
lines changed

.github/workflows/build_docker_package.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- main
77
- master
88
- develop
9-
- v1.0.0-preview.1
109
types:
1110
- completed
1211

.github/workflows/build_integration_and_code_analysis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- main
77
- master
88
- develop
9-
- v1.0.0-preview.1
109
pull_request:
1110
types: [opened, synchronize, reopened]
1211
schedule:
@@ -77,7 +76,7 @@ jobs:
7776

7877
- name: Publish test coverage results
7978
id: jacoco_reporter
80-
uses: PavanMudigonda/jacoco-reporter@v4.7
79+
uses: PavanMudigonda/jacoco-reporter@v4.8
8180
with:
8281
coverage_results_path: 'target/site/jacoco/jacoco.xml'
8382
coverage_report_title: 'Test coverage results'

src/main/java/com/answerdigital/answerking/controller/CategoryController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public ResponseEntity<CategoryResponse> updateCategory(@Valid @RequestBody final
137137
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)) })
138138
})
139139
@DeleteMapping("/{categoryId}")
140-
public ResponseEntity<CategoryResponse> retireCategory(@PathVariable @NotNull final Long categoryId) {
141-
return new ResponseEntity<>(categoryService.retireCategory(categoryId), HttpStatus.OK);
140+
public ResponseEntity<Void> retireCategory(@PathVariable @NotNull final Long categoryId) {
141+
categoryService.retireCategory(categoryId);
142+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
142143
}
143144
}

src/main/java/com/answerdigital/answerking/controller/ProductController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public ResponseEntity<ProductResponse> updateProduct(@PathVariable @NotNull fina
105105
schema = @Schema(implementation = ErrorResponse.class)) })
106106
})
107107
@DeleteMapping("/{id}")
108-
public ResponseEntity<ProductResponse> retireProduct(@PathVariable @NotNull final Long id) {
109-
return new ResponseEntity<>(productService.retireProduct(id), HttpStatus.OK);
108+
public ResponseEntity<Void> retireProduct(@PathVariable @NotNull final Long id) {
109+
productService.retireProduct(id);
110+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
110111
}
111112
}

src/main/java/com/answerdigital/answerking/mapper/ProductMapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import org.mapstruct.Mapper;
77
import org.mapstruct.Mapping;
88
import org.mapstruct.MappingTarget;
9-
109
import java.util.List;
11-
import java.util.stream.Collectors;
1210

13-
@Mapper(componentModel = "spring", imports = {List.class, Collectors.class})
11+
@Mapper(componentModel = "spring", imports = {List.class})
1412
public interface ProductMapper {
1513
@Mapping(target = "retired", constant = "false")
1614
Product addRequestToProduct(ProductRequest productRequest);

src/main/java/com/answerdigital/answerking/service/CategoryService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ public CategoryResponse removeProductFromCategory(final Long categoryId, final L
104104
return categoryMapper.convertCategoryEntityToCategoryResponse(savedCategory);
105105
}
106106

107-
public CategoryResponse retireCategory(final Long categoryId) {
107+
public void retireCategory(final Long categoryId) {
108108
final Category category = findById(categoryId);
109109
if(category.isRetired()) {
110110
throw new RetirementException(String.format("The category with ID %d is already retired", categoryId));
111111
}
112112
category.setRetired(true);
113113
final Category savedCategory = categoryRepository.save(category);
114-
return categoryMapper.convertCategoryEntityToCategoryResponse(savedCategory);
115114
}
116115

117116
public List<ProductResponse> findProductsByCategoryId(final Long categoryId) {

src/main/java/com/answerdigital/answerking/service/ProductService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ public ProductResponse updateProduct(final Long productId, final ProductRequest
7777
return productMapper.convertProductEntityToProductResponse(savedProduct);
7878
}
7979

80-
public ProductResponse retireProduct(final Long productId) {
80+
public void retireProduct(final Long productId) {
8181
final Product product = findById(productId);
8282
if (product.isRetired()) {
8383
throw new RetirementException(String.format("The product with ID %d is already retired", productId));
8484
}
8585
product.setRetired(true);
8686
final Product savedProduct = productRepository.save(product);
87-
return productMapper.convertProductEntityToProductResponse(savedProduct);
8887
}
8988

9089
public List<ProductResponse> findProductsByCategoryId(final Long categoryId) {

src/test/java/com/answerdigital/answerking/service/CategoryServiceTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ void testRetireCategory() {
281281
doReturn(expectedCategory).when(categoryRepository).save(any(Category.class));
282282

283283
// then
284-
assertEquals(categoryResponse.getClass(), categoryService.retireCategory(category.getId()).getClass());
285-
verify(categoryRepository).findById(anyLong());
286-
verify(categoryRepository).save(any(Category.class));
284+
categoryService.retireCategory(category.getId());
285+
286+
verify(categoryRepository).findById(category.getId());
287+
verify(categoryRepository).save(expectedCategory);
287288
}
288289

289290
@Test
@@ -299,7 +300,7 @@ void testRetireCategoryAlreadyRetiredThrowsRetirementException() {
299300

300301
// then
301302
assertThrows(RetirementException.class, () -> categoryService.retireCategory(retiredCategory.getId()));
302-
verify(categoryRepository).findById(anyLong());
303+
verify(categoryRepository).findById(retiredCategory.getId());
303304
}
304305

305306
@Test

src/test/java/com/answerdigital/answerking/service/ProductServiceTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2424
import static org.junit.jupiter.api.Assertions.assertEquals;
2525
import static org.junit.jupiter.api.Assertions.assertFalse;
26-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2726
import static org.junit.jupiter.api.Assertions.assertThrows;
2827
import static org.mockito.Mockito.any;
2928
import static org.mockito.Mockito.anyLong;
@@ -174,15 +173,15 @@ void updateProductThrowsExceptionIfProductNameAlreadyExist() {
174173
@Test
175174
void testRetireProduct() {
176175
// when
177-
when(productRepository.findById(anyLong()))
178-
.thenReturn(Optional.of(product));
179-
when(productRepository.save(any(Product.class)))
180-
.thenReturn(product);
176+
when(productRepository.findById(anyLong())).thenReturn(Optional.of(product));
177+
when(productRepository.save(any(Product.class))).thenReturn(product);
181178

182179
// then
183-
assertNotEquals(product.isRetired(), productService.retireProduct(PRODUCT_ID).isRetired());
180+
productService.retireProduct(PRODUCT_ID);
181+
product.setRetired(true);
182+
184183
verify(productRepository).findById(anyLong());
185-
verify(productRepository).save(any(Product.class));
184+
verify(productRepository).save(product);
186185
}
187186

188187
@Test
@@ -192,8 +191,7 @@ void testRetireProductAlreadyRetiredThrowsRetirementException() {
192191
expectedProduct.setRetired(true);
193192

194193
// when
195-
when(productRepository.findById(anyLong()))
196-
.thenReturn(Optional.of(expectedProduct));
194+
when(productRepository.findById(anyLong())).thenReturn(Optional.of(expectedProduct));
197195

198196
// then
199197
assertThrows(RetirementException.class, () -> productService.retireProduct(PRODUCT_ID));
@@ -203,8 +201,7 @@ void testRetireProductAlreadyRetiredThrowsRetirementException() {
203201
@Test
204202
void testRetireProductDoesNotExistThrowsNotFoundException() {
205203
// when
206-
when(productRepository.findById(anyLong()))
207-
.thenReturn(Optional.empty());
204+
when(productRepository.findById(anyLong())).thenReturn(Optional.empty());
208205

209206
// then
210207
assertThrows(NotFoundException.class, () -> productService.retireProduct(PRODUCT_ID));

0 commit comments

Comments
 (0)