From 499a31793adedce0a3f5fb8c40ee0d931bec0278 Mon Sep 17 00:00:00 2001 From: whatIsLove Date: Tue, 3 Dec 2024 14:43:11 +0200 Subject: [PATCH] Refactoring and replacing wildcard imports with specific imports --- .../greencity/service/EventServiceImpl.java | 64 +++++++++++++++++-- .../events/AddEventDtoRequestMapperTest.java | 7 -- .../service/EventServiceImplTest.java | 30 ++++++--- 3 files changed, 80 insertions(+), 21 deletions(-) diff --git a/service/src/main/java/greencity/service/EventServiceImpl.java b/service/src/main/java/greencity/service/EventServiceImpl.java index 75f24cf7a..e79303cdd 100644 --- a/service/src/main/java/greencity/service/EventServiceImpl.java +++ b/service/src/main/java/greencity/service/EventServiceImpl.java @@ -7,7 +7,15 @@ import greencity.constant.ErrorMessage; import greencity.dto.PageableAdvancedDto; import greencity.dto.PageableDto; -import greencity.dto.event.*; +import greencity.dto.event.AddEventDtoRequest; +import greencity.dto.event.AddressDto; +import greencity.dto.event.EventAttenderDto; +import greencity.dto.event.EventAuthorDto; +import greencity.dto.event.EventDateLocationDto; +import greencity.dto.event.EventDto; +import greencity.dto.event.EventVO; +import greencity.dto.event.UpdateEventDto; +import greencity.dto.event.UpdateEventRequestDto; import greencity.dto.filter.FilterEventDto; import greencity.dto.geocoding.AddressLatLngResponse; import greencity.dto.notification.LikeNotificationDto; @@ -22,7 +30,12 @@ import greencity.entity.event.EventDateLocation; import greencity.entity.event.EventGrade; import greencity.entity.event.EventImages; -import greencity.enums.*; +import greencity.enums.AchievementAction; +import greencity.enums.AchievementCategoryType; +import greencity.enums.EventType; +import greencity.enums.NotificationType; +import greencity.enums.Role; +import greencity.enums.TagType; import greencity.exception.exceptions.BadRequestException; import greencity.exception.exceptions.NotFoundException; import greencity.exception.exceptions.UserHasNoPermissionToAccessException; @@ -47,9 +60,52 @@ import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; -import static greencity.constant.EventTupleConstant.*; +import static greencity.constant.EventTupleConstant.cityEn; +import static greencity.constant.EventTupleConstant.cityUa; +import static greencity.constant.EventTupleConstant.countComments; +import static greencity.constant.EventTupleConstant.countryEn; +import static greencity.constant.EventTupleConstant.countryUa; +import static greencity.constant.EventTupleConstant.creationDate; +import static greencity.constant.EventTupleConstant.description; +import static greencity.constant.EventTupleConstant.dislikes; +import static greencity.constant.EventTupleConstant.eventId; +import static greencity.constant.EventTupleConstant.finishDate; +import static greencity.constant.EventTupleConstant.formattedAddressEn; +import static greencity.constant.EventTupleConstant.formattedAddressUa; +import static greencity.constant.EventTupleConstant.grade; +import static greencity.constant.EventTupleConstant.houseNumber; +import static greencity.constant.EventTupleConstant.isFavorite; +import static greencity.constant.EventTupleConstant.isOpen; +import static greencity.constant.EventTupleConstant.isOrganizedByFriend; +import static greencity.constant.EventTupleConstant.isRelevant; +import static greencity.constant.EventTupleConstant.isSubscribed; +import static greencity.constant.EventTupleConstant.languageCode; +import static greencity.constant.EventTupleConstant.latitude; +import static greencity.constant.EventTupleConstant.likes; +import static greencity.constant.EventTupleConstant.longitude; +import static greencity.constant.EventTupleConstant.onlineLink; +import static greencity.constant.EventTupleConstant.organizerId; +import static greencity.constant.EventTupleConstant.organizerName; +import static greencity.constant.EventTupleConstant.regionEn; +import static greencity.constant.EventTupleConstant.regionUa; +import static greencity.constant.EventTupleConstant.startDate; +import static greencity.constant.EventTupleConstant.streetEn; +import static greencity.constant.EventTupleConstant.streetUa; +import static greencity.constant.EventTupleConstant.tagId; +import static greencity.constant.EventTupleConstant.tagName; +import static greencity.constant.EventTupleConstant.title; +import static greencity.constant.EventTupleConstant.titleImage; +import static greencity.constant.EventTupleConstant.type; @Service @Transactional diff --git a/service/src/test/java/greencity/mapping/events/AddEventDtoRequestMapperTest.java b/service/src/test/java/greencity/mapping/events/AddEventDtoRequestMapperTest.java index 72a5470a8..fcbd26688 100644 --- a/service/src/test/java/greencity/mapping/events/AddEventDtoRequestMapperTest.java +++ b/service/src/test/java/greencity/mapping/events/AddEventDtoRequestMapperTest.java @@ -20,13 +20,6 @@ class AddEventDtoRequestMapperTest { @InjectMocks private AddEventDtoRequestMapper mapper; - /* - * @Test void convertTest() { Event expected = ModelUtils.getEvent(); - * AddEventDtoRequest request = ModelUtils.addEventDtoRequest; - * - * assertEquals(expected.getTitle(), mapper.convert(request).getTitle()); } - */ - @Test void convertTestWithoutAddress() { Event expected = ModelUtils.getEventWithoutAddress(); diff --git a/service/src/test/java/greencity/service/EventServiceImplTest.java b/service/src/test/java/greencity/service/EventServiceImplTest.java index 36e8d63a0..ba8b00709 100644 --- a/service/src/test/java/greencity/service/EventServiceImplTest.java +++ b/service/src/test/java/greencity/service/EventServiceImplTest.java @@ -60,8 +60,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.Principal; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -69,9 +67,22 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Stream; - -import static greencity.ModelUtils.*; -import static org.junit.jupiter.api.Assertions.*; +import static greencity.ModelUtils.getAuthorVO; +import static greencity.ModelUtils.getEvent; +import static greencity.ModelUtils.getEventPreviewDtos; +import static greencity.ModelUtils.getFilterEventDto; +import static greencity.ModelUtils.getTupleElements; +import static greencity.ModelUtils.getTuples; +import static greencity.ModelUtils.getUser; +import static greencity.ModelUtils.getUserVO; +import static greencity.ModelUtils.getUsersHashSet; +import static greencity.ModelUtils.testUserVo; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyList; @@ -184,12 +195,11 @@ void saveEventWithoutAddress() { when(modelMapper.map(addEventDtoWithoutCoordinates, Event.class)).thenReturn(eventWithoutCoordinates); when(eventRepo.save(any(Event.class))).thenReturn(eventWithoutCoordinates); - BadRequestException exception = assertThrows(BadRequestException.class, () -> { - eventService.save(addEventDtoWithoutCoordinates, user.getEmail(), null); - }); + BadRequestException exception = assertThrows( + BadRequestException.class, + () -> eventService.save(addEventDtoWithoutCoordinates, user.getEmail(), null)); assertEquals(ErrorMessage.INVALID_COORDINATES, exception.getMessage()); - verify(eventRepo, times(0)).save(eventWithoutCoordinates); } @@ -1059,7 +1069,7 @@ void testCheckingEqualityDateTimeInEventDateLocationDto() throws Exception { @Test void getAllEventAddressesTest() { - AddressDto expectedAddressDto = getAddressDto(); + AddressDto expectedAddressDto = ModelUtils.getAddressDto(); List expectedAddresses = List.of(expectedAddressDto); Address address = ModelUtils.getAddress();