Skip to content

Commit

Permalink
Refactoring and replacing wildcard imports with specific imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr1stal423 committed Dec 3, 2024
1 parent bedca83 commit 499a317
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 21 deletions.
64 changes: 60 additions & 4 deletions service/src/main/java/greencity/service/EventServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 20 additions & 10 deletions service/src/test/java/greencity/service/EventServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,29 @@
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;
import java.util.List;
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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1059,7 +1069,7 @@ void testCheckingEqualityDateTimeInEventDateLocationDto() throws Exception {

@Test
void getAllEventAddressesTest() {
AddressDto expectedAddressDto = getAddressDto();
AddressDto expectedAddressDto = ModelUtils.getAddressDto();
List<AddressDto> expectedAddresses = List.of(expectedAddressDto);
Address address = ModelUtils.getAddress();

Expand Down

0 comments on commit 499a317

Please sign in to comment.