diff --git a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java index 318ee350..30ee70f2 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java @@ -23,21 +23,21 @@ public CommentRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java index 4b65c7f3..04bed092 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java +++ b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java @@ -4,21 +4,16 @@ import com.cvi.config.entity.BaseEntity; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.Objects; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Objects; + @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java index c3253449..db98b83d 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java @@ -22,21 +22,21 @@ public LikeRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java index 2de7038c..16853772 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java @@ -2,16 +2,17 @@ import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.persistence.Embeddable; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.Embeddable; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Embeddable diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java index 80dd89dd..644697f8 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java @@ -7,29 +7,16 @@ import com.cvi.image.domain.Image; import com.cvi.like.domain.model.Like; import com.cvi.user.domain.model.User; +import lombok.*; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.validation.constraints.NotBlank; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; @Getter @Entity @@ -62,7 +49,7 @@ public class Post extends BaseEntity { @Builder public Post(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, User user, - String content, int viewCount, VaccinationType vaccinationType) { + String content, int viewCount, VaccinationType vaccinationType) { super(id, createdAt, lastModifiedAt); this.user = user; this.content = content; diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index 53e14859..73121ddc 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -1,12 +1,10 @@ package com.cvi.post.domain.model; -import static com.cvi.post.domain.model.QPost.post; - -import com.cvi.exception.InvalidInputException; import com.querydsl.core.types.OrderSpecifier; -import java.util.Arrays; import lombok.Getter; +import static com.cvi.post.domain.model.QPost.post; + @Getter public enum Sort { LIKE_COUNT_ASC(post.likes.likes.size().asc()), diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java index 301a041c..e7050a72 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java @@ -1,10 +1,5 @@ package com.cvi.post.domain.repository; -import static com.cvi.comment.domain.model.QComment.comment; -import static com.cvi.like.domain.model.QLike.like; -import static com.cvi.post.domain.model.QPost.post; -import static com.cvi.user.domain.model.QUser.user; - import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.QPost; import com.cvi.post.domain.model.VaccinationType; @@ -12,10 +7,16 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPQLQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; import java.util.List; import java.util.Objects; import java.util.Optional; -import javax.persistence.EntityManager; + +import static com.cvi.comment.domain.model.QComment.comment; +import static com.cvi.like.domain.model.QLike.like; +import static com.cvi.post.domain.model.QPost.post; +import static com.cvi.user.domain.model.QUser.user; public class PostRepositoryImpl implements PostQueryDsl { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java index 7ce619a1..5091b5ec 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java @@ -1,9 +1,10 @@ package com.cvi.publicdata.domain.model; +import lombok.Getter; + import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import lombok.Getter; @Getter public enum RegionPopulation { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java index 4ac68892..f016e4d3 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java @@ -39,8 +39,8 @@ public class VaccinationStatistic extends PublicData { @Builder public VaccinationStatistic(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, RegionPopulation regionPopulation, - LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, - long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { + LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, + long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { super(id, createdAt, lastModifiedAt, regionPopulation); this.baseDate = baseDate; this.firstCnt = firstCnt; diff --git a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java index 7f306154..bb39b3de 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java +++ b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java @@ -4,15 +4,10 @@ import com.cvi.exception.InvalidInputException; import lombok.*; import lombok.extern.slf4j.Slf4j; -import org.hibernate.validator.constraints.Length; -import org.springframework.util.StringUtils; import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.Objects; -import java.util.regex.Matcher; import java.util.regex.Pattern; @Slf4j diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java index e27986fe..5830a573 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java @@ -1,8 +1,5 @@ package com.cvi.comment.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.exception.UnAuthorizedException; @@ -11,11 +8,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("댓글 도메인 테스트") class CommentTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java index 0d4a344d..199a4171 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java @@ -1,7 +1,6 @@ package com.cvi.comment.domain.repository; import com.cvi.comment.domain.model.Comment; -import com.cvi.image.domain.Image; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -15,8 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import java.util.Arrays; - import static org.assertj.core.api.Assertions.assertThat; @DisplayName("CommentRepository 테스트") @@ -49,51 +46,51 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); postRepository.save(post1); } private void initComments() { comment1 = Comment.builder() - .content("댓글 내용1") - .user(user1) - .build(); + .content("댓글 내용1") + .user(user1) + .build(); comment1.assignPost(post1); commentRepository.save(comment1); comment2 = Comment.builder() - .content("댓글 내용2") - .user(user2) - .build(); + .content("댓글 내용2") + .user(user2) + .build(); comment2.assignPost(post1); commentRepository.save(comment2); comment3 = Comment.builder() - .content("댓글 내용3") - .user(user2) - .build(); + .content("댓글 내용3") + .user(user2) + .build(); comment3.assignPost(post1); commentRepository.save(comment3); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java index 0d9ac89d..962aca34 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; @DisplayName("Boolean 을 Y/N로 변환 테스트") class BooleanToYNConverterTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java index cce9c643..8580cccc 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java @@ -1,11 +1,11 @@ package com.cvi.image.model; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.image.domain.Image; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("Image 도메인 테스트") class ImageTest { @@ -14,19 +14,19 @@ class ImageTest { void equalsAndHashcode() { //given final Image image1 = Image.builder() - .id(1L) - .url("aaaa/image1") - .build(); + .id(1L) + .url("aaaa/image1") + .build(); final Image image2 = Image.builder() - .id(1L) - .url("bbbb/image2") - .build(); + .id(1L) + .url("bbbb/image2") + .build(); //when //then assertThat(image1) - .isNotSameAs(image2) - .isEqualTo(image2) - .hasSameHashCodeAs(image2); + .isNotSameAs(image2) + .isEqualTo(image2) + .hasSameHashCodeAs(image2); assertThat(image1.getName()).isEqualTo("image1"); assertThat(image2.isSameAs(1L)).isTrue(); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index 4478b512..888a48dd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -1,8 +1,5 @@ package com.cvi.image.repository; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; import com.cvi.post.domain.model.Post; @@ -12,13 +9,17 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; -import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("ImageRepository 테스트") @DataJpaTest class ImageRepositoryTest { @@ -38,24 +39,24 @@ class ImageRepositoryTest { @BeforeEach void setUp() { User user = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); userRepository.save(user); image = Image.builder() - .url("image1_s3_url") - .build(); + .url("image1_s3_url") + .build(); imageRepository.save(image); post = Post.builder() - .user(user) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); postRepository.save(post); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java index 743a29eb..a36efbb5 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java @@ -1,8 +1,5 @@ package com.cvi.like.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; @@ -10,11 +7,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("좋아요 도메인 테스트") class LikeTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 2614e662..667abd6d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -47,54 +47,54 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); post2 = Post.builder() - .user(user1) - .content("내용 2") - .vaccinationType(VaccinationType.JANSSEN) - .build(); + .user(user1) + .content("내용 2") + .vaccinationType(VaccinationType.JANSSEN) + .build(); postRepository.save(post1); postRepository.save(post2); } private void initLikes() { like1 = Like.builder() - .user(user1) - .build(); + .user(user1) + .build(); like1.assignPost(post1); likeRepository.save(like1); like2 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like2.assignPost(post1); likeRepository.save(like2); like3 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like3.assignPost(post2); likeRepository.save(like3); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java index d8b0638d..607b9edd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java @@ -36,31 +36,31 @@ class PostTest { @BeforeEach void init() { post = Post.builder() - .content("content1") - .vaccinationType(VaccinationType.ASTRAZENECA) - .createdAt(LocalDateTime.now()) - .build(); + .content("content1") + .vaccinationType(VaccinationType.ASTRAZENECA) + .createdAt(LocalDateTime.now()) + .build(); user = User.builder() - .id(1L) - .nickname("안녕하세욘") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(1L) + .nickname("안녕하세욘") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); comment = Comment.builder() - .id(1L) - .content("댓글입니다.") - .user(user) - .build(); + .id(1L) + .content("댓글입니다.") + .user(user) + .build(); like = Like.builder() - .id(1L) - .user(user) - .build(); + .id(1L) + .user(user) + .build(); image = Image.builder() - .id(1L) - .url("image1_s3_url/image") - .build(); + .id(1L) + .url("image1_s3_url/image") + .build(); } @DisplayName("게시글 작성자 할당 - 성공") @@ -78,14 +78,14 @@ void assignUser() { void assignUserFailureWhenAlreadyExists() { //given User targetUser = User.builder() - .id(2L) - .nickname("독함") - .build(); + .id(2L) + .nickname("독함") + .build(); //when post.assignUser(user); //then assertThatThrownBy(() -> post.assignUser(targetUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 할당 - 실패 - 할당하려는 작성자가 없음") @@ -95,7 +95,7 @@ void assignUserFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignUser(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 할당 - 성공") @@ -116,7 +116,7 @@ void assignCommentFailureWhenAlreadyExists() { post.assignComment(comment); //then assertThatThrownBy(() -> post.assignComment(comment)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 댓글 할당 - 실패 - 할당하려는 댓글이 없음") @@ -126,7 +126,7 @@ void assignCommentFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignComment(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 수정 - 성공") @@ -134,9 +134,9 @@ void assignCommentFailureWhenNull() { void updateComment() { //given Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); post.updateComment(1L, updateComment, user); @@ -149,18 +149,18 @@ void updateComment() { void updateCommentFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .build(); + .id(2L) + .nickname("다른유저") + .build(); Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); //then assertThatThrownBy(() -> post.updateComment(1L, updateComment, anotherUser)) - .isInstanceOf(UnAuthorizedException.class); + .isInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 댓글 삭제 - 성공") @@ -180,19 +180,19 @@ void deleteCommentInComments() { void deleteCommentInCommentsFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(2L) + .nickname("다른유저") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); //when post.assignComment(comment); Comments comments = post.getComments(); //then assertThatThrownBy(() -> comments.delete(comment.getId(), anotherUser)) - .isExactlyInstanceOf(UnAuthorizedException.class); + .isExactlyInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 좋아요 할당 - 성공") @@ -213,7 +213,7 @@ void assignLikeFailureWhenAlreadyExists() { post.assignLike(like); //then assertThatThrownBy(() -> post.assignLike(like)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 좋아요 할당 - 실패 - 할당하려는 좋아요가 없음") @@ -223,7 +223,7 @@ void assignLikeFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignLike(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 사진 할당 - 성공") @@ -243,7 +243,7 @@ void assignImagesFailureWhenAlreadyExists() { //when //then assertThatThrownBy(() -> post.assignImages(Collections.emptyList())) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 이미지 삭제 - 성공") @@ -286,8 +286,8 @@ void increaseViewCount() { void update() { //given Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when post.updateContent(updatedPost, user); @@ -300,17 +300,17 @@ void update() { void updateFailWhenUserNotMatch() { //given User targetUser = User.builder() - .id(2L) - .nickname("라이언방구") - .build(); + .id(2L) + .nickname("라이언방구") + .build(); Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.updateContent(updatedPost, targetUser)) - .isExactlyInstanceOf(InvalidOperationException.class); + .isExactlyInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 확인 - 성공") @@ -318,17 +318,17 @@ void updateFailWhenUserNotMatch() { void deletePost() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatCode(() -> post.validateAuthor(user)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } @DisplayName("게시글 작성자 확인 - 실패 - 글 작성자가 아님") @@ -336,21 +336,21 @@ void deletePost() { void deletePostFailureWhenNotAuthor() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); User otherUser = User.builder() - .id(3L) - .nickname("라이언") - .build(); + .id(3L) + .nickname("라이언") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.validateAuthor(otherUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 좋아요 이미 누름 - 성공") @@ -377,21 +377,21 @@ void isNotLikedBy() { void isNotAlreadyLikedBy() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); User otherUser = User.builder() - .id(3L) - .nickname("라이언") - .build(); + .id(3L) + .nickname("라이언") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.validateAuthor(otherUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글이 이미지 보유 확인 - 성공 - 있음") @@ -446,13 +446,13 @@ void getS3PathsOfAllImages() { void resizePagingRangeTest(int offset, int size, List contentResult) { //given User user = User.builder() - .id(1L) - .nickname("인비") - .build(); + .id(1L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .user(user) - .build(); + .content("내용") + .user(user) + .build(); Comment comment1 = Comment.builder().content("댓글1").user(user).createdAt(LocalDateTime.now().minusHours(1L)).build(); Comment comment2 = Comment.builder().content("댓글2").user(user).createdAt(LocalDateTime.now().minusHours(2L)).build(); post.assignComment(comment1); @@ -465,10 +465,10 @@ void resizePagingRangeTest(int offset, int size, List contentResult) { static Stream resizePagingRangeTest() { return Stream.of( - Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), - Arguments.of(1, 1, Collections.singletonList("댓글2")), - Arguments.of(0, 1, Collections.singletonList("댓글1")), - Arguments.of(2, 1, Collections.emptyList()) + Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), + Arguments.of(1, 1, Collections.singletonList("댓글2")), + Arguments.of(0, 1, Collections.singletonList("댓글1")), + Arguments.of(2, 1, Collections.emptyList()) ); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java index d941c80c..6beee448 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java @@ -1,7 +1,5 @@ package com.cvi.post.domain.repository; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.comment.domain.model.Comment; import com.cvi.comment.domain.repository.CommentRepository; import com.cvi.image.domain.Image; @@ -15,19 +13,21 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import static org.assertj.core.api.Assertions.assertThat; @DisplayName("PostRepository 테스트") @DataJpaTest diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java index f9dacaae..bd107eca 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java @@ -9,54 +9,54 @@ public class VaccinationStatisticFactory { public static final LocalDate TARGET_DATE = LocalDate.now(); public static final List KOREA_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() ); public static final List WORLD_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() ); public static final List VACCINATION_STATISTICS_FROM_DB = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() ); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java index 7db743ad..1c4a22d0 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java @@ -1,29 +1,29 @@ package com.cvi.publicdata.domain.model; -import static org.assertj.core.api.Assertions.assertThat; - -import java.math.BigDecimal; - import com.cvi.CustomParameterizedTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.provider.CsvSource; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("백신 접종률 도메인 테스트") class VaccinationStatisticTest { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "2100000, 4.1", - "21000000, 40.5", - "11000000, 21.2" + "2100000, 4.1", + "21000000, 40.5", + "11000000, 21.2" }) void accumulateFirstRate(long totalFirstCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalFirstCnt(totalFirstCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalFirstCnt(totalFirstCnt) + .build(); //when BigDecimal accumulateFirstRate = vaccinationStatistic.getTotalFirstRate(); //then @@ -33,16 +33,16 @@ void accumulateFirstRate(long totalFirstCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "1100000, 2.1", - "3000000, 5.8", - "11000000, 21.2" + "1100000, 2.1", + "3000000, 5.8", + "11000000, 21.2" }) void accumulateSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -52,16 +52,16 @@ void accumulateSecondRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "2253618189, 28.6", - "2276706840, 28.9", - "2303769251, 29.2" + "2253618189, 28.6", + "2276706840, 28.9", + "2303769251, 29.2" }) void accumulateWorldFirstRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -71,16 +71,16 @@ void accumulateWorldFirstRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "1153697698, 14.6", - "1175939230, 14.9", - "1181952381, 15.0" + "1153697698, 14.6", + "1175939230, 14.9", + "1181952381, 15.0" }) void accumulateWorldSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java index 75588d39..971867ce 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java @@ -1,15 +1,13 @@ package com.cvi.publicdata.domain.model; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.KOREA_VACCINATION_STATISTICS_FROM_API; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.TARGET_DATE; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.VACCINATION_STATISTICS_FROM_DB; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.WORLD_VACCINATION_STATISTICS_FROM_API; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.List; + +import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.*; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("VaccinationStatistic 일급 컬렉션 기능 테스트") class VaccinationStatisticsTest { @@ -20,7 +18,7 @@ void findUnSavedStatisticsWhenAnotherDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE ); //then assertThat(unSavedStatistics.size()).isEqualTo(RegionPopulation.size() - 1); @@ -34,7 +32,7 @@ void findUnSavedStatisticsWhenSameDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE + KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE ); //then assertThat(unSavedStatistics).isEmpty(); @@ -47,7 +45,7 @@ void findWorldUnSavedStatisticsWhenTargetDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(WORLD_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) ); //then assertThat(unSavedStatistics.size()).isEqualTo(WORLD_VACCINATION_STATISTICS_FROM_API.size() - 1); @@ -65,7 +63,7 @@ void findWorldRecentlyStatistics() { assertThat(koreaRecentlyStatistics.size()).isEqualTo(RegionPopulation.size() - 1); assertThat(koreaRecentlyStatistics).noneMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(koreaRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .contains(TARGET_DATE.minusDays(1)); + .contains(TARGET_DATE.minusDays(1)); } @DisplayName("타겟 날짜 이전의 데이터가 DB에 저장되어 있을때(타겟날짜에 데이터가 저장되어 있지 않음) 이전 날짜의 데이터 반환 - 성공 - 세계 데이터") @@ -78,6 +76,6 @@ void findKoreaRecentlyStatistics() { //then assertThat(worldRecentlyStatistics).allMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(worldRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .doesNotContain(TARGET_DATE); + .doesNotContain(TARGET_DATE); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java index 6e5977f4..39010b04 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java @@ -22,13 +22,13 @@ class UserTest { @BeforeEach void init() { this.user = User.builder() - .id(1L) - .ageRange(AgeRange.TEENS) - .createdAt(LocalDateTime.now()) - .nickname("검프") - .profileUrl("www.gump.com") - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(AgeRange.TEENS) + .createdAt(LocalDateTime.now()) + .nickname("검프") + .profileUrl("www.gump.com") + .socialProvider(SocialProvider.KAKAO) + .build(); } @DisplayName("사용자 생성 - 성공") @@ -39,11 +39,11 @@ void save(String name) { //when //then assertThatCode(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).doesNotThrowAnyException(); } @@ -56,13 +56,13 @@ void saveFailure(String name) { //when //then assertThatThrownBy(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).isInstanceOf(InvalidInputException.class) - .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); + .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); } @@ -72,14 +72,14 @@ void saveFailure(String name) { void update(String name, AgeRange ageRange, boolean shotVerified) { //given User updateUser = User.builder() - .id(1L) - .ageRange(ageRange) - .createdAt(LocalDateTime.now()) - .nickname(name) - .profileUrl("www.budae.com") - .shotVerified(shotVerified) - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(ageRange) + .createdAt(LocalDateTime.now()) + .nickname(name) + .profileUrl("www.budae.com") + .shotVerified(shotVerified) + .socialProvider(SocialProvider.KAKAO) + .build(); //when user.update(updateUser); //then @@ -90,6 +90,6 @@ void update(String name, AgeRange ageRange, boolean shotVerified) { static Stream update() { return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), - Arguments.of("2", AgeRange.THIRTIES, false)); + Arguments.of("2", AgeRange.THIRTIES, false)); } }