From 477564ae6a3e9c39d23194c0766cfdb600de2db2 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Mon, 13 Nov 2023 07:44:11 +0000 Subject: [PATCH] feat: remove dead code --- .github/workflows/sonar-cloud.yml | 2 +- .../catalogservice/mapper/ProductMapper.java | 8 +---- .../controllers/ProductControllerTest.java | 31 ++++++++++--------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/.github/workflows/sonar-cloud.yml b/.github/workflows/sonar-cloud.yml index 66fb5aca..c044356f 100644 --- a/.github/workflows/sonar-cloud.yml +++ b/.github/workflows/sonar-cloud.yml @@ -28,7 +28,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: 21 - distribution: 'zulu' # Alternative distribution options are available. + distribution: 'microsoft' # Alternative distribution options are available. cache: 'maven' - name: Cache SonarCloud packages diff --git a/catalog-service/src/main/java/com/example/catalogservice/mapper/ProductMapper.java b/catalog-service/src/main/java/com/example/catalogservice/mapper/ProductMapper.java index b68f34d5..28d6c055 100644 --- a/catalog-service/src/main/java/com/example/catalogservice/mapper/ProductMapper.java +++ b/catalog-service/src/main/java/com/example/catalogservice/mapper/ProductMapper.java @@ -9,7 +9,6 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import com.example.catalogservice.entities.Product; import com.example.catalogservice.model.request.ProductRequest; import com.example.catalogservice.model.response.ProductResponse; -import com.example.common.dtos.ProductDto; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; @@ -17,18 +16,13 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. @Mapper(componentModel = "spring") public interface ProductMapper { - @Mapping(target = "id", ignore = true) - @Mapping(target = "inStock", ignore = true) - Product toEntity(ProductDto productDto); - + @Mapping(target = "withInStock", ignore = true) ProductResponse toProductResponse(Product product); @Mapping(target = "id", ignore = true) @Mapping(target = "inStock", ignore = true) Product toEntity(ProductRequest productRequest); - Product toEntity(ProductResponse productResponse); - @Mapping(target = "inStock", ignore = true) @Mapping(target = "id", ignore = true) void mapProductWithRequest(ProductRequest productRequest, @MappingTarget Product product); diff --git a/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java b/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java index e893c509..25475a7a 100644 --- a/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java +++ b/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java @@ -7,8 +7,8 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. package com.example.catalogservice.web.controllers; import static com.example.catalogservice.utils.AppConstants.PROFILE_TEST; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.is; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -69,20 +69,21 @@ void shouldFetchAllProducts() { .isOk() .expectBody(PagedResult.class) .value( - response -> { - assertAll( - () -> assertTrue(response.isFirst()), - () -> assertTrue(response.isLast()), - () -> assertFalse(response.hasNext()), - () -> assertFalse(response.hasPrevious()), - () -> assertEquals(3, response.totalElements()), - () -> assertEquals(1, response.pageNumber()), - () -> assertEquals(1, response.totalPages()), - () -> - assertEquals( - productResponseList.size(), - response.data().size())); - }); + response -> + assertThat(response) + .isNotNull() + .satisfies( + r -> { + assertThat(r.isFirst()).isTrue(); + assertThat(r.isLast()).isTrue(); + assertThat(r.hasNext()).isFalse(); + assertThat(r.hasPrevious()).isFalse(); + assertThat(r.totalElements()).isEqualTo(3); + assertThat(r.pageNumber()).isEqualTo(1); + assertThat(r.totalPages()).isEqualTo(1); + assertThat(r.data().size()) + .isEqualTo(productResponseList.size()); + })); } @Test