From a001096a9fd46c469a5e0c6feb756145c43049d8 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Mon, 29 Jun 2026 11:09:37 +0300 Subject: [PATCH 1/9] add RoomCategoryValidator --- .../roomcategory/RoomCategoryValidator.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java new file mode 100644 index 00000000..03ebc5e6 --- /dev/null +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java @@ -0,0 +1,47 @@ +package org.unilab.uniplan.roomcategory; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.unilab.uniplan.category.CategoryRepository; +import org.unilab.uniplan.exception.ResourceNotFoundException; +import org.unilab.uniplan.room.RoomRepository; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; + +import java.util.UUID; + +import static org.unilab.uniplan.utils.ErrorConstants.CATEGORY_NOT_FOUND; +import static org.unilab.uniplan.utils.ErrorConstants.ROOM_NOT_FOUND; + +@Component +@RequiredArgsConstructor +public class RoomCategoryValidator { + private final CategoryRepository categoryRepository; + private final RoomRepository roomRepository; + + public void validateForCreate(final RoomCategoryRequestDto requestDto) { + validateCategoryExists(requestDto.categoryId()); + validateRoomExists(requestDto.roomId()); + } + + public void validateForUpdate(final UUID id, final RoomCategoryRequestDto requestDto) { + validateCategoryExists(requestDto.categoryId()); + validateRoomExists(requestDto.roomId()); + } + + public void validateCategoryExists(final UUID categoryId) { + if (!categoryRepository.existsById(categoryId)) { + throw new ResourceNotFoundException( + CATEGORY_NOT_FOUND.getMessage(String.valueOf(categoryId)) + ); + } + } + + public void validateRoomExists(final UUID roomId) { + if (!roomRepository.existsById(roomId)) { + throw new ResourceNotFoundException( + ROOM_NOT_FOUND.getMessage(String.valueOf(roomId)) + ); + } + } +} + From b4db7f0b3e491d0353c1ff3b0f37324799919963 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Mon, 29 Jun 2026 11:29:11 +0300 Subject: [PATCH 2/9] Simplify roomCategoryService --- .../roomcategory/RoomCategoryService.java | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryService.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryService.java index 3133878c..0fe8f2f1 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryService.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryService.java @@ -1,52 +1,29 @@ package org.unilab.uniplan.roomcategory; -import static org.unilab.uniplan.utils.ErrorConstants.ROOM_CATEGORY_NOT_FOUND; - import java.util.List; -import java.util.UUID; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.unilab.uniplan.exception.ResourceNotFoundException; -import org.unilab.uniplan.roomcategory.dto.RoomCategoryDto; @Service @RequiredArgsConstructor public class RoomCategoryService { private final RoomCategoryRepository roomCategoryRepository; - private final RoomCategoryMapper roomCategoryMapper; - - @Transactional - public RoomCategoryDto createRoomCategory(final RoomCategoryDto roomCategoryDto) { - final RoomCategory roomCategory = roomCategoryMapper.toEntity(roomCategoryDto); - return roomCategoryMapper.toDto(roomCategoryRepository.save(roomCategory)); + public void save(final RoomCategory roomCategory) { + roomCategoryRepository.save(roomCategory); } - public List getAllRoomCategories() { - final List roomCategories = roomCategoryRepository.findAll(); - return roomCategoryMapper.toDtoList(roomCategories); + public List getAll() { + return roomCategoryRepository.findAll(); } - public RoomCategoryDto getRoomCategoryById(final UUID roomId, final UUID categoryId) { - final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); - - return roomCategoryRepository.findById(id) - .map(roomCategoryMapper::toDto) - .orElseThrow(() -> new ResourceNotFoundException( - ROOM_CATEGORY_NOT_FOUND.getMessage(String.valueOf(id)))); + public Optional getById(final RoomCategoryId id) { + return roomCategoryRepository.findById(id); } - @Transactional - public void deleteRoomCategory(final UUID roomId, final UUID categoryId) { - final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); - - final RoomCategory roomCategory = roomCategoryRepository.findById(id) - .orElseThrow(() -> new ResourceNotFoundException( - ROOM_CATEGORY_NOT_FOUND.getMessage( - String.valueOf(id)))); - + public void delete(RoomCategory roomCategory) { roomCategoryRepository.delete(roomCategory); } } From 6c87b28dbd3eeb33db49628ef0cac497118cb316 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Mon, 29 Jun 2026 15:28:16 +0300 Subject: [PATCH 3/9] migrate room category to facade --- .../roomcategory/RoomCategoryController.java | 24 ++---- .../roomcategory/RoomCategoryMapper.java | 18 ++--- .../roomcategory/RoomCategoryValidator.java | 2 +- .../roomcategory/RoomCategoryWebFacade.java | 77 +++++++++++++++++++ 4 files changed, 95 insertions(+), 26 deletions(-) create mode 100644 src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacade.java diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryController.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryController.java index 26661af8..2ccee76a 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryController.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryController.java @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import org.unilab.uniplan.roomcategory.dto.RoomCategoryDto; import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; import org.unilab.uniplan.roomcategory.dto.RoomCategoryResponseDto; @@ -25,39 +24,32 @@ @Tag(name = "Room-Category Assignments", description = "Manage the association of rooms with categories") public class RoomCategoryController { - private final RoomCategoryService roomCategoryService; - private final RoomCategoryMapper roomCategoryMapper; + private final RoomCategoryWebFacade roomCategoryWebFacade; @PostMapping("/add") - public ResponseEntity createRoomCategory( + public ResponseEntity createRoomCategory( @Valid @NotNull @RequestBody final RoomCategoryRequestDto roomCategoryRequestDto) { - RoomCategoryDto roomCategoryDto = roomCategoryService.createRoomCategory( - roomCategoryMapper.toInternalDto(roomCategoryRequestDto)); + roomCategoryWebFacade.createRoomCategory(roomCategoryRequestDto); - return new ResponseEntity<>(roomCategoryMapper.toResponseDto(roomCategoryDto), - HttpStatus.CREATED); + return ResponseEntity.status(HttpStatus.CREATED).build(); } @GetMapping("/getAll") - public List getAllRoomCategories() { - return roomCategoryMapper.toResponseDtoList(roomCategoryService.getAllRoomCategories()); + public ResponseEntity> getAllRoomCategories() { + return ResponseEntity.ok(roomCategoryWebFacade.getAllRoomCategories()); } @GetMapping("/getById") public ResponseEntity getRoomCategoryById(@RequestParam final UUID roomId, @RequestParam final UUID categoryId) { - RoomCategoryDto roomCategoryDto = roomCategoryService.getRoomCategoryById(roomId, - categoryId); - - return ResponseEntity.ok(roomCategoryMapper.toResponseDto(roomCategoryDto)); + return ResponseEntity.ok(roomCategoryWebFacade.getRoomCategoryById(roomId, categoryId)); } - @DeleteMapping("/delete") public ResponseEntity deleteRoomCategory(@RequestParam final UUID roomId, @RequestParam final UUID categoryId) { - roomCategoryService.deleteRoomCategory(roomId, categoryId); + roomCategoryWebFacade.deleteRoomCategory(roomId, categoryId); return ResponseEntity.noContent().build(); } } \ No newline at end of file diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryMapper.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryMapper.java index 875a7d4b..cd3908a0 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryMapper.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryMapper.java @@ -4,7 +4,7 @@ import java.util.UUID; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.unilab.uniplan.roomcategory.dto.RoomCategoryDto; +import org.mapstruct.MappingTarget; import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; import org.unilab.uniplan.roomcategory.dto.RoomCategoryResponseDto; @@ -14,19 +14,19 @@ public interface RoomCategoryMapper { @Mapping(target = "id", expression = "java(new RoomCategoryId(dto.roomId(), dto.categoryId()))") @Mapping(target = "room", ignore = true) @Mapping(target = "category", ignore = true) - RoomCategory toEntity(RoomCategoryDto dto); + RoomCategory toEntity(RoomCategoryRequestDto dto); @Mapping(source = "id.roomId", target = "roomId") @Mapping(source = "id.categoryId", target = "categoryId") - RoomCategoryDto toDto(RoomCategory entity); - - RoomCategoryDto toInternalDto(RoomCategoryRequestDto requestDto); + RoomCategoryResponseDto toResponseDto(final RoomCategory roomCategory); - RoomCategoryResponseDto toResponseDto(RoomCategoryDto roomCategoryDto); + List toResponseDtoList(List roomCategories); - List toDtoList(List entities); - - List toResponseDtoList(List roomCategories); + @Mapping(target = "id", expression = "java(new RoomCategoryId(requestDto.roomId(), requestDto.categoryId()))") + @Mapping(target = "room", ignore = true) + @Mapping(target = "category", ignore = true) + void updateEntity(final RoomCategoryRequestDto requestDto, + @MappingTarget final RoomCategory entity); RoomCategoryId toRoomCategoryId(UUID roomId, UUID categoryId); } diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java index 03ebc5e6..dedf9905 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.java @@ -23,7 +23,7 @@ public void validateForCreate(final RoomCategoryRequestDto requestDto) { validateRoomExists(requestDto.roomId()); } - public void validateForUpdate(final UUID id, final RoomCategoryRequestDto requestDto) { + public void validateForUpdate(final RoomCategoryId id, final RoomCategoryRequestDto requestDto) { validateCategoryExists(requestDto.categoryId()); validateRoomExists(requestDto.roomId()); } diff --git a/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacade.java b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacade.java new file mode 100644 index 00000000..aea2fdd0 --- /dev/null +++ b/src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacade.java @@ -0,0 +1,77 @@ +package org.unilab.uniplan.roomcategory; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import org.unilab.uniplan.exception.ResourceNotFoundException; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryResponseDto; +import java.util.List; +import java.util.UUID; + +import static org.unilab.uniplan.utils.ErrorConstants.ROOM_CATEGORY_NOT_FOUND; + +@Component +@Slf4j +@RequiredArgsConstructor +public class RoomCategoryWebFacade { + + private final RoomCategoryService roomCategoryService; + private final RoomCategoryMapper roomCategoryMapper; + private final RoomCategoryValidator roomCategoryValidator; + + private RoomCategory getRoomCategoryOrThrow(final RoomCategoryId id) { + return roomCategoryService.getById(id) + .orElseThrow(() -> new ResourceNotFoundException(ROOM_CATEGORY_NOT_FOUND.getMessage( + String.valueOf(id)))); + } + + @Transactional + public void createRoomCategory(final RoomCategoryRequestDto requestDto) { + roomCategoryValidator.validateForCreate(requestDto); + + final RoomCategory roomCategory = roomCategoryMapper.toEntity(requestDto); + roomCategoryService.save(roomCategory); + + log.info("created room category with roomId: {} and categoryId: {}", + requestDto.roomId(), + requestDto.categoryId()); + } + + @Transactional(readOnly = true) + public List getAllRoomCategories() { + return roomCategoryMapper.toResponseDtoList(roomCategoryService.getAll()); + } + + @Transactional + public void deleteRoomCategory(final UUID roomId, final UUID categoryId) { + final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); + final RoomCategory roomCategory = getRoomCategoryOrThrow(id); + + roomCategoryService.delete(roomCategory); + + log.info("deleted room category with ID: {}", id); + } + + @Transactional(readOnly = true) + public RoomCategoryResponseDto getRoomCategoryById(final UUID roomId, final UUID categoryId) { + final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); + final RoomCategory roomCategory = getRoomCategoryOrThrow(id); + + return roomCategoryMapper.toResponseDto(roomCategory); + } + + @Transactional + public void updateRoomCategory(final UUID roomId, final UUID categoryId, final RoomCategoryRequestDto requestDto) { + final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); + + roomCategoryValidator.validateForUpdate(id, requestDto); + + final RoomCategory roomCategory = getRoomCategoryOrThrow(id); + roomCategoryMapper.updateEntity(requestDto, roomCategory); + roomCategoryService.save(roomCategory); + + log.info("updated room category with ID: {}", roomCategory.getId()); + } +} From 35af1ab9d5a75993b4cd6349d16412680e03eda4 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Mon, 29 Jun 2026 15:42:23 +0300 Subject: [PATCH 4/9] refactor RoomCategoryServiceTest --- .../roomcategory/RoomCategoryServiceTest.java | 77 +++++-------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java index 4e75c35b..ccd3c1e8 100644 --- a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java @@ -26,98 +26,59 @@ class RoomCategoryServiceTest { @Mock private RoomCategoryRepository roomCategoryRepository; - @Mock - private RoomCategoryMapper roomCategoryMapper; - @InjectMocks private RoomCategoryService roomCategoryService; - private UUID roomId; - private UUID categoryId; - private RoomCategoryDto dto; + private RoomCategoryId id; private RoomCategory entity; @BeforeEach void setUp() { - roomId = UUID.randomUUID(); - categoryId = UUID.randomUUID(); - dto = new RoomCategoryDto(roomId, categoryId); + id = new RoomCategoryId(UUID.randomUUID(), UUID.randomUUID()); entity = new RoomCategory(); } @Test - void testCreateRoomCategoryShouldSaveAndReturnDto() { - when(roomCategoryMapper.toEntity(dto)).thenReturn(entity); - when(roomCategoryRepository.save(entity)).thenReturn(entity); - when(roomCategoryMapper.toDto(entity)).thenReturn(dto); + void testSaveShouldSaveRoomCategory() { + roomCategoryService.save(entity); - RoomCategoryDto result = roomCategoryService.createRoomCategory(dto); - - assertEquals(dto, result); + verify(roomCategoryRepository).save(entity); } @Test - void testGetAllRoomCategoriesShouldReturnListOfRoomCategoryDtos() { - List entities = List.of(entity); - List dtos = List.of(dto); + void testGetAllRoomCategoriesShouldReturnListOfRoomCategory() { + final List entities = List.of(entity); when(roomCategoryRepository.findAll()).thenReturn(entities); - when(roomCategoryMapper.toDtoList(entities)).thenReturn(dtos); - List result = roomCategoryService.getAllRoomCategories(); + final List result = roomCategoryService.getAll(); - assertEquals(dtos, result); + assertEquals(entities, result); + verify(roomCategoryRepository).findAll(); } @Test - void testGetRoomCategoryByIdShouldReturnRoomCategoryDtoIfFound() { - RoomCategoryId id = new RoomCategoryId(roomId, categoryId); - - when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + void testGetByIdShouldReturnRoomCategoryOptional() { when(roomCategoryRepository.findById(id)).thenReturn(Optional.of(entity)); - when(roomCategoryMapper.toDto(entity)).thenReturn(dto); - RoomCategoryDto result = roomCategoryService.getRoomCategoryById(roomId, - categoryId); - assertEquals(dto, result); + final Optional result = roomCategoryService.getById(id); + assertEquals((Optional.of(entity)), result); } @Test - void testGetRoomCategoryByIdShouldReturnEmptyOptionalIfNotFound() { - RoomCategoryId id = new RoomCategoryId(roomId, categoryId); - - when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + void testGetIdShouldReturnEmptyOptionalIfNotFound() { when(roomCategoryRepository.findById(id)).thenReturn(Optional.empty()); - ResourceNotFoundException exception = assertThrows(ResourceNotFoundException.class, () -> roomCategoryService.getRoomCategoryById(roomId, - categoryId)); + final Optional result = roomCategoryService.getById(id); - assertTrue(exception.getMessage().contains(String.valueOf(id))); + assertEquals(Optional.empty(), result); + verify(roomCategoryRepository).findById(id); } @Test - void testDeleteRoomCategoryShouldDeleteIfFound() { - RoomCategoryId id = new RoomCategoryId(roomId, categoryId); - - when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); - when(roomCategoryRepository.findById(id)).thenReturn(Optional.of(entity)); - doAnswer(invocation -> null).when(roomCategoryRepository).delete(entity); + void testDeleteShouldDeleteIfFound() { + roomCategoryService.delete(entity); - assertDoesNotThrow(() -> roomCategoryService.deleteRoomCategory(roomId, categoryId)); verify(roomCategoryRepository).delete(entity); } - - @Test - void testDeleteRoomCategoryShouldThrowIfNotFound() { - RoomCategoryId id = new RoomCategoryId(roomId, categoryId); - - when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); - when(roomCategoryRepository.findById(id)).thenReturn(Optional.empty()); - - ResourceNotFoundException exception = assertThrows(ResourceNotFoundException.class, () -> - roomCategoryService.deleteRoomCategory(roomId, categoryId)); - - assertTrue(exception.getMessage().contains(String.valueOf(roomId))); - assertTrue(exception.getMessage().contains(String.valueOf(categoryId))); - } } From dff3080e748d8346b9d97a24ba674f65b570be8a Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Mon, 29 Jun 2026 17:25:56 +0300 Subject: [PATCH 5/9] add RoomCategoryWebFacadeTest --- .../RoomCategoryWebFacadeTest.java | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java new file mode 100644 index 00000000..a9f600b2 --- /dev/null +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java @@ -0,0 +1,168 @@ +package org.unilab.uniplan.roomcategory; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InOrder; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.unilab.uniplan.exception.ResourceNotFoundException; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryResponseDto; + +@ExtendWith(MockitoExtension.class) +class RoomCategoryWebFacadeTest { + + @Mock + private RoomCategoryService roomCategoryService; + + @Mock + private RoomCategoryMapper roomCategoryMapper; + + @Mock + private RoomCategoryValidator roomCategoryValidator; + + @InjectMocks + private RoomCategoryWebFacade roomCategoryWebFacade; + + private UUID roomId; + private UUID categoryId; + private RoomCategoryId id; + private RoomCategory roomCategory; + private RoomCategoryRequestDto requestDto; + private RoomCategoryResponseDto responseDto; + + @BeforeEach + void setUp() { + roomId = UUID.randomUUID(); + categoryId = UUID.randomUUID(); + id = new RoomCategoryId(roomId, categoryId); + roomCategory = new RoomCategory(); + requestDto = mock(RoomCategoryRequestDto.class); + responseDto = mock(RoomCategoryResponseDto.class); + } + + @Test + void testCreateRoomCategoryShouldValidateMapAndSaveRoomCategory() { + when(roomCategoryMapper.toEntity(requestDto)).thenReturn(roomCategory); + + roomCategoryWebFacade.createRoomCategory(requestDto); + + final InOrder inOrder = inOrder(roomCategoryValidator, roomCategoryService); + inOrder.verify(roomCategoryValidator).validateForCreate(requestDto); + inOrder.verify(roomCategoryService).save(roomCategory); + + verify(roomCategoryMapper).toEntity(requestDto); + } + + @Test + void testGetAllRoomCategoriesShouldReturnResponseDtoList() { + final List roomCategories = List.of(roomCategory); + final List responseDtos = List.of(responseDto); + + when(roomCategoryService.getAll()).thenReturn(roomCategories); + when(roomCategoryMapper.toResponseDtoList(roomCategories)).thenReturn(responseDtos); + + final List result = roomCategoryWebFacade.getAllRoomCategories(); + + assertEquals(responseDtos, result); + verify(roomCategoryService).getAll(); + verify(roomCategoryMapper).toResponseDtoList(roomCategories); + } + + @Test + void testGetRoomCategoryByIdShouldReturnResponseDtoIfFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); + when(roomCategoryMapper.toResponseDto(roomCategory)).thenReturn(responseDto); + + final RoomCategoryResponseDto result = roomCategoryWebFacade.getRoomCategoryById(roomId, categoryId); + + assertEquals(responseDto, result); + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryService).getById(id); + verify(roomCategoryMapper).toResponseDto(roomCategory); + } + + @Test + void testGetRoomCategoryByIdShouldThrowIfNotFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.empty()); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryWebFacade.getRoomCategoryById(roomId, categoryId)); + + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryService).getById(id); + verify(roomCategoryMapper, never()).toResponseDto(any(RoomCategory.class)); + } + + @Test + void testUpdateRoomCategoryShouldValidateUpdateAndSaveRoomCategoryIfFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); + + roomCategoryWebFacade.updateRoomCategory(roomId, categoryId, requestDto); + + final InOrder inOrder = inOrder(roomCategoryValidator, roomCategoryService); + inOrder.verify(roomCategoryValidator).validateForUpdate(id, requestDto); + inOrder.verify(roomCategoryService).getById(id); + inOrder.verify(roomCategoryService).save(roomCategory); + + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryMapper).updateEntity(requestDto, roomCategory); + } + + @Test + void testUpdateRoomCategoryShouldThrowIfNotFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.empty()); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryWebFacade.updateRoomCategory(roomId, categoryId, requestDto)); + + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryValidator).validateForUpdate(id, requestDto); + verify(roomCategoryService).getById(id); + verify(roomCategoryMapper, never()).updateEntity(any(RoomCategoryRequestDto.class), any(RoomCategory.class)); + verify(roomCategoryService, never()).save(any(RoomCategory.class)); + } + + @Test + void testDeleteRoomCategoryShouldDeleteRoomCategoryIfFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); + + roomCategoryWebFacade.deleteRoomCategory(roomId, categoryId); + + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryService).getById(id); + verify(roomCategoryService).delete(roomCategory); + } + + @Test + void testDeleteRoomCategoryShouldThrowIfNotFound() { + when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); + when(roomCategoryService.getById(id)).thenReturn(Optional.empty()); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryWebFacade.deleteRoomCategory(roomId, categoryId)); + + verify(roomCategoryMapper).toRoomCategoryId(roomId, categoryId); + verify(roomCategoryService).getById(id); + verify(roomCategoryService, never()).delete(any(RoomCategory.class)); + } +} \ No newline at end of file From 33887f0c10e51be36c58fea220cd64dda2c24305 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Tue, 30 Jun 2026 10:46:46 +0300 Subject: [PATCH 6/9] add messages to @NotNull --- .../uniplan/roomcategory/dto/RoomCategoryRequestDto.java | 4 ++-- .../uniplan/roomcategory/dto/RoomCategoryResponseDto.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryRequestDto.java b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryRequestDto.java index 026c5e8f..0a4b7971 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryRequestDto.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryRequestDto.java @@ -5,10 +5,10 @@ public record RoomCategoryRequestDto( - @NotNull + @NotNull(message = "Room ID cannot be null") UUID roomId, - @NotNull + @NotNull(message = "Category ID cannot be null") UUID categoryId ) { diff --git a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java index 6c20290e..3f7d6d20 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java @@ -5,10 +5,10 @@ public record RoomCategoryResponseDto( - @NotNull + @NotNull(message = "Room ID cannot be null") UUID roomId, - @NotNull + @NotNull(message = "Category ID cannot be null") UUID categoryId ) { From 54b519af0bdea202aa0fcf4f957fbef563560130 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Tue, 30 Jun 2026 13:23:24 +0300 Subject: [PATCH 7/9] remove validations from response dto --- .../uniplan/roomcategory/dto/RoomCategoryResponseDto.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java index 3f7d6d20..50a8bcc9 100644 --- a/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java +++ b/src/main/java/org/unilab/uniplan/roomcategory/dto/RoomCategoryResponseDto.java @@ -5,10 +5,8 @@ public record RoomCategoryResponseDto( - @NotNull(message = "Room ID cannot be null") UUID roomId, - @NotNull(message = "Category ID cannot be null") UUID categoryId ) { From 3608c079f3ab5a744136ea04c918e7c0d182fd7d Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Wed, 1 Jul 2026 11:09:31 +0300 Subject: [PATCH 8/9] add RoomCategoryValidatorTest --- pr-review.patch | Bin 0 -> 65580 bytes .../RoomCategoryValidatorTest.java | 148 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 pr-review.patch create mode 100644 src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java diff --git a/pr-review.patch b/pr-review.patch new file mode 100644 index 0000000000000000000000000000000000000000..085026692ea50086643e27fed1fb7be45b5e11f2 GIT binary patch literal 65580 zcmeHQ`)?daa^9Z<FXb|}AI zpZzR%9Lb#r@_H`cpU&o&qi=O%ZEE(vpZ%RcdpLV5RCve})h+q%OL_gOyB<`&Cf8o??s_AyCql&|`NL>ey1&g+U}v@? zFkTbLugbqIf$FBbyDjhVi$eNJc(*_MRsMe}cy4uEd@4AnGQm%jiMf-B`6XSCX8(LK zD#v~;QUD3rmyto^bD85*ID$DbTP{Jrn?0QUUVeFZG18X2$KM-)43dU-sni|LwmS}= zbl+~t-CHs;W`Yjc0T&1R*$&9Z%iNO5VXM67RH-Z7aKb2QV3MetXzAOVn z)P%<(^*4pOpNq^q7Fg%<`H5)3ZTYt^-{yKmy_m-GEQ`yudblh!)W+MQgI@~mt_U5k ziVae2gnk^)UUm8h+YKuXtvnTpc_ftgQvbY@rFo)1s(Fiz0tEV-(Sg}Qf)aJ44)g4yNQ`8ZQ#)P z><>bN1Myhv!P?JV!ai!@)I9eP{2-iH9a$g#pnAzGD+D$C+mR8*v>0G69EGiz7h-|e zg72B=2WbC7t~nL^hig|qdpb|_807L4Sb7exbJo=2`FRoJ(Bj>aXddw}BAF`^+rZ*| zCjXZ`^3;^6!?+_+EaLHPv6SjHwr2k#P<;}l=uE!3D&He>ITNo0Z}UoINUbXGfqY>c zjqkmDo^|)b+U|?zhTN*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YM~JN_A~oe9p($q4P%iVFiTp?#^nD zM_cdk7{lJRbTej}SVbwFFA&#;$Rl63eI}CiQg*eWhaNUy+^&UmKlJ#g>eVaOB^y%b zU!*rZMpY2=}R*Jn|Pvc`e?$b+g`{b9JG<)4y zrQFcwm8E7mkL3AP_BpAKSiMKeAzF`TNU_9>sn+*<#GEds?bL6+zR$i&_w(&_5gDr6 zhy>^_Qf~!|&8W>NcW`-%h3%*_%R~G(<*oYkobd6r2B+c6vpdv(#q2bChn8=J$H+4h zlcBQiryez}rt%Dd2vIJjCA-yQ@j*FIB z99*^Zr27@T4NGO`p6FV78enT5+=pYm%3SS_QtC7-bBmf@o^N;z3m==#9cMG!M~Ph2 nrlhmfrQ$b>^1fP>I{%`~L~pdLjF$7P6rR$qD6<)qSbhCJ2#92b literal 0 HcmV?d00001 diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java new file mode 100644 index 00000000..65158e63 --- /dev/null +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java @@ -0,0 +1,148 @@ +package org.unilab.uniplan.roomcategory; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.UUID; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.unilab.uniplan.category.CategoryRepository; +import org.unilab.uniplan.exception.ResourceNotFoundException; +import org.unilab.uniplan.room.RoomRepository; +import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; + +@ExtendWith(MockitoExtension.class) +class RoomCategoryValidatorTest { + + @Mock + private CategoryRepository categoryRepository; + + @Mock + private RoomRepository roomRepository; + + @InjectMocks + private RoomCategoryValidator roomCategoryValidator; + + private UUID roomId; + private UUID categoryId; + private RoomCategoryId id; + private RoomCategoryRequestDto requestDto; + + @BeforeEach + void setUp() { + roomId = UUID.randomUUID(); + categoryId = UUID.randomUUID(); + id = new RoomCategoryId(roomId, categoryId); + requestDto = new RoomCategoryRequestDto(roomId, categoryId); + } + + @Test + void testValidateForCreateShouldPassWhenCategoryAndRoomExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(true); + when(roomRepository.existsById(roomId)).thenReturn(true); + + assertDoesNotThrow(() -> roomCategoryValidator.validateForCreate(requestDto)); + + verify(categoryRepository).existsById(categoryId); + verify(roomRepository).existsById(roomId); + } + + @Test + void testValidateForCreateShouldThrowWhenCategoryDoesNotExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateForCreate(requestDto)); + + verify(categoryRepository).existsById(categoryId); + } + + @Test + void testValidateForCreateShouldThrowWhenRoomDoesNotExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(true); + when(roomRepository.existsById(roomId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateForCreate(requestDto)); + + verify(categoryRepository).existsById(categoryId); + verify(roomRepository).existsById(roomId); + } + + @Test + void testValidateForUpdateShouldPassWhenCategoryAndRoomExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(true); + when(roomRepository.existsById(roomId)).thenReturn(true); + + assertDoesNotThrow(() -> roomCategoryValidator.validateForUpdate(id, requestDto)); + + verify(categoryRepository).existsById(categoryId); + verify(roomRepository).existsById(roomId); + } + + @Test + void testValidateForUpdateShouldThrowWhenCategoryDoesNotExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateForUpdate(id, requestDto)); + + verify(categoryRepository).existsById(categoryId); + } + + @Test + void testValidateForUpdateShouldThrowWhenRoomDoesNotExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(true); + when(roomRepository.existsById(roomId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateForUpdate(id, requestDto)); + + verify(categoryRepository).existsById(categoryId); + verify(roomRepository).existsById(roomId); + } + + @Test + void testValidateCategoryExistsShouldPassWhenCategoryExists() { + when(categoryRepository.existsById(categoryId)).thenReturn(true); + + assertDoesNotThrow(() -> roomCategoryValidator.validateCategoryExists(categoryId)); + + verify(categoryRepository).existsById(categoryId); + } + + @Test + void testValidateCategoryExistsShouldThrowWhenCategoryDoesNotExist() { + when(categoryRepository.existsById(categoryId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateCategoryExists(categoryId)); + + verify(categoryRepository).existsById(categoryId); + } + + @Test + void testValidateRoomExistsShouldPassWhenRoomExists() { + when(roomRepository.existsById(roomId)).thenReturn(true); + + assertDoesNotThrow(() -> roomCategoryValidator.validateRoomExists(roomId)); + + verify(roomRepository).existsById(roomId); + } + + @Test + void testValidateRoomExistsShouldThrowWhenRoomDoesNotExist() { + when(roomRepository.existsById(roomId)).thenReturn(false); + + assertThrows(ResourceNotFoundException.class, + () -> roomCategoryValidator.validateRoomExists(roomId)); + + verify(roomRepository).existsById(roomId); + } +} \ No newline at end of file From 5d13b2d70e3f20a9d7beca52c09d0019eaab4823 Mon Sep 17 00:00:00 2001 From: Djesika Vacheva Date: Tue, 28 Jul 2026 10:08:35 +0300 Subject: [PATCH 9/9] rename test methods --- .../roomcategory/RoomCategoryServiceTest.java | 10 +++++----- .../RoomCategoryValidatorTest.java | 20 +++++++++---------- .../RoomCategoryWebFacadeTest.java | 16 +++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java index ccd3c1e8..655f6e10 100644 --- a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryServiceTest.java @@ -39,14 +39,14 @@ void setUp() { } @Test - void testSaveShouldSaveRoomCategory() { + void save_shouldSaveRoomCategory() { roomCategoryService.save(entity); verify(roomCategoryRepository).save(entity); } @Test - void testGetAllRoomCategoriesShouldReturnListOfRoomCategory() { + void getAll_shouldReturnListOfRoomCategories() { final List entities = List.of(entity); when(roomCategoryRepository.findAll()).thenReturn(entities); @@ -58,7 +58,7 @@ void testGetAllRoomCategoriesShouldReturnListOfRoomCategory() { } @Test - void testGetByIdShouldReturnRoomCategoryOptional() { + void getById_shouldReturnOptional_whenRoomCategoryExists() { when(roomCategoryRepository.findById(id)).thenReturn(Optional.of(entity)); final Optional result = roomCategoryService.getById(id); @@ -66,7 +66,7 @@ void testGetByIdShouldReturnRoomCategoryOptional() { } @Test - void testGetIdShouldReturnEmptyOptionalIfNotFound() { + void getById_shouldReturnEmptyOptional_whenRoomCategoryDoesNotExist() { when(roomCategoryRepository.findById(id)).thenReturn(Optional.empty()); final Optional result = roomCategoryService.getById(id); @@ -76,7 +76,7 @@ void testGetIdShouldReturnEmptyOptionalIfNotFound() { } @Test - void testDeleteShouldDeleteIfFound() { + void delete_shouldDeleteRoomCategory() { roomCategoryService.delete(entity); verify(roomCategoryRepository).delete(entity); diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java index 65158e63..fe8c238f 100644 --- a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryValidatorTest.java @@ -43,7 +43,7 @@ void setUp() { } @Test - void testValidateForCreateShouldPassWhenCategoryAndRoomExist() { + void validateForCreate_shouldPass_whenCategoryAndRoomExist() { when(categoryRepository.existsById(categoryId)).thenReturn(true); when(roomRepository.existsById(roomId)).thenReturn(true); @@ -54,7 +54,7 @@ void testValidateForCreateShouldPassWhenCategoryAndRoomExist() { } @Test - void testValidateForCreateShouldThrowWhenCategoryDoesNotExist() { + void ValidateForCreateShouldThrowWhenCategoryDoesNotExist() { when(categoryRepository.existsById(categoryId)).thenReturn(false); assertThrows(ResourceNotFoundException.class, @@ -64,7 +64,7 @@ void testValidateForCreateShouldThrowWhenCategoryDoesNotExist() { } @Test - void testValidateForCreateShouldThrowWhenRoomDoesNotExist() { + void validateForCreate_shouldThrow_whenCategoryDoesNotExist() { when(categoryRepository.existsById(categoryId)).thenReturn(true); when(roomRepository.existsById(roomId)).thenReturn(false); @@ -76,7 +76,7 @@ void testValidateForCreateShouldThrowWhenRoomDoesNotExist() { } @Test - void testValidateForUpdateShouldPassWhenCategoryAndRoomExist() { + void validateForUpdate_shouldPass_whenCategoryAndRoomExist() { when(categoryRepository.existsById(categoryId)).thenReturn(true); when(roomRepository.existsById(roomId)).thenReturn(true); @@ -87,7 +87,7 @@ void testValidateForUpdateShouldPassWhenCategoryAndRoomExist() { } @Test - void testValidateForUpdateShouldThrowWhenCategoryDoesNotExist() { + void validateForUpdate_shouldThrow_whenCategoryDoesNotExist() { when(categoryRepository.existsById(categoryId)).thenReturn(false); assertThrows(ResourceNotFoundException.class, @@ -97,7 +97,7 @@ void testValidateForUpdateShouldThrowWhenCategoryDoesNotExist() { } @Test - void testValidateForUpdateShouldThrowWhenRoomDoesNotExist() { + void validateForUpdate_shouldThrow_whenRoomDoesNotExist() { when(categoryRepository.existsById(categoryId)).thenReturn(true); when(roomRepository.existsById(roomId)).thenReturn(false); @@ -109,7 +109,7 @@ void testValidateForUpdateShouldThrowWhenRoomDoesNotExist() { } @Test - void testValidateCategoryExistsShouldPassWhenCategoryExists() { + void validateCategoryExists_shouldPass_whenCategoryExists() { when(categoryRepository.existsById(categoryId)).thenReturn(true); assertDoesNotThrow(() -> roomCategoryValidator.validateCategoryExists(categoryId)); @@ -118,7 +118,7 @@ void testValidateCategoryExistsShouldPassWhenCategoryExists() { } @Test - void testValidateCategoryExistsShouldThrowWhenCategoryDoesNotExist() { + void validateCategoryExists_shouldThrow_whenCategoryDoesNotExist() { when(categoryRepository.existsById(categoryId)).thenReturn(false); assertThrows(ResourceNotFoundException.class, @@ -128,7 +128,7 @@ void testValidateCategoryExistsShouldThrowWhenCategoryDoesNotExist() { } @Test - void testValidateRoomExistsShouldPassWhenRoomExists() { + void validateRoomExists_shouldPass_whenRoomExists() { when(roomRepository.existsById(roomId)).thenReturn(true); assertDoesNotThrow(() -> roomCategoryValidator.validateRoomExists(roomId)); @@ -137,7 +137,7 @@ void testValidateRoomExistsShouldPassWhenRoomExists() { } @Test - void testValidateRoomExistsShouldThrowWhenRoomDoesNotExist() { + void validateRoomExists_shouldThrow_whenRoomDoesNotExist() { when(roomRepository.existsById(roomId)).thenReturn(false); assertThrows(ResourceNotFoundException.class, diff --git a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java index a9f600b2..382b16ce 100644 --- a/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java +++ b/src/test/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacadeTest.java @@ -56,7 +56,7 @@ void setUp() { } @Test - void testCreateRoomCategoryShouldValidateMapAndSaveRoomCategory() { + void createRoomCategory_shouldValidateMapAndSaveRoomCategory() { when(roomCategoryMapper.toEntity(requestDto)).thenReturn(roomCategory); roomCategoryWebFacade.createRoomCategory(requestDto); @@ -69,7 +69,7 @@ void testCreateRoomCategoryShouldValidateMapAndSaveRoomCategory() { } @Test - void testGetAllRoomCategoriesShouldReturnResponseDtoList() { + void getAllRoomCategories_shouldReturnResponseDtoList() { final List roomCategories = List.of(roomCategory); final List responseDtos = List.of(responseDto); @@ -84,7 +84,7 @@ void testGetAllRoomCategoriesShouldReturnResponseDtoList() { } @Test - void testGetRoomCategoryByIdShouldReturnResponseDtoIfFound() { + void getRoomCategoryById_shouldReturnResponseDto_whenRoomCategoryExists() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); when(roomCategoryMapper.toResponseDto(roomCategory)).thenReturn(responseDto); @@ -98,7 +98,7 @@ void testGetRoomCategoryByIdShouldReturnResponseDtoIfFound() { } @Test - void testGetRoomCategoryByIdShouldThrowIfNotFound() { + void getRoomCategoryById_shouldThrow_whenRoomCategoryNotExist() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.empty()); @@ -111,7 +111,7 @@ void testGetRoomCategoryByIdShouldThrowIfNotFound() { } @Test - void testUpdateRoomCategoryShouldValidateUpdateAndSaveRoomCategoryIfFound() { + void updateRoomCategory_shouldValidateUpdateAndSaveRoomCategory_whenRoomCategoryExists() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); @@ -127,7 +127,7 @@ void testUpdateRoomCategoryShouldValidateUpdateAndSaveRoomCategoryIfFound() { } @Test - void testUpdateRoomCategoryShouldThrowIfNotFound() { + void updateRoomCategory_shouldThrow_whenRoomCategoryDoesNotExist() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.empty()); @@ -142,7 +142,7 @@ void testUpdateRoomCategoryShouldThrowIfNotFound() { } @Test - void testDeleteRoomCategoryShouldDeleteRoomCategoryIfFound() { + void deleteRoomCategory_shouldDeleteRoomCategory_whenRoomCategoryExists() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.of(roomCategory)); @@ -154,7 +154,7 @@ void testDeleteRoomCategoryShouldDeleteRoomCategoryIfFound() { } @Test - void testDeleteRoomCategoryShouldThrowIfNotFound() { + void deleteRoomCategory_shouldThrow_whenRoomCategoryDoesNotExist() { when(roomCategoryMapper.toRoomCategoryId(roomId, categoryId)).thenReturn(id); when(roomCategoryService.getById(id)).thenReturn(Optional.empty());