Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VasylyshynDmytro committed Jan 13, 2025
1 parent 8f754ad commit 89297af
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions service/src/test/java/greencity/service/PlaceServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ void updateDiscountDoesNotThrowExceptionTest() {
}

@Test
void updateFromUI_ShouldUpdatePlaceSuccessfully() {
void updateFromUISucceedsForValidPlaceTest() {
PlaceUpdateDto dto = new PlaceUpdateDto();
dto.setId(1L);
dto.setName("Updated Place");
Expand Down Expand Up @@ -1096,7 +1096,7 @@ void updateFromUI_ShouldUpdatePlaceSuccessfully() {
}

@Test
void updateFromUI_ShouldThrowException_WhenUserNotFound() {
void updateFromUIThrowsNotFoundExceptionForUserTest() {
PlaceUpdateDto dto = getPlaceUpdateDto();
when(userRepo.findByEmail(anyString())).thenReturn(Optional.empty());

Expand All @@ -1105,7 +1105,7 @@ void updateFromUI_ShouldThrowException_WhenUserNotFound() {
}

@Test
void updateFromUI_ShouldThrowNotFoundException_WhenCategoryNotFound() {
void updateFromUIThrowsNotFoundExceptionForCategoryTest() {
PlaceUpdateDto dto = new PlaceUpdateDto();
dto.setId(1L);
dto.setCategory(new CategoryDto("Nonexistent Category", "Nonexistent Category", 1L));
Expand All @@ -1115,4 +1115,16 @@ void updateFromUI_ShouldThrowNotFoundException_WhenCategoryNotFound() {
assertThrows(NotFoundException.class, () -> placeServiceImpl.updateFromUI(dto, null, "[email protected]"));
}

@Test
void updateCategoryThrowsNotFoundExceptionTest() {
PlaceUpdateDto dto = new PlaceUpdateDto();
dto.setId(1L);
dto.setCategory(new CategoryDto("Non-existent Category", "Non-existent Category Ua", 2L));
when(placeRepo.findById(1L)).thenReturn(Optional.of(genericEntity1));
when(categoryService.findByName("Non-existent Category")).thenThrow(new NotFoundException("Category not found"));

NotFoundException exception = assertThrows(NotFoundException.class, () -> placeServiceImpl.update(dto));
assertEquals("Category not found", exception.getMessage());
verify(placeRepo, never()).save(any(Place.class));
}
}

0 comments on commit 89297af

Please sign in to comment.