Skip to content

Commit

Permalink
fix: 테스트 실패로 인한 빌드 실패 수정 (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Apr 2, 2024
2 parents 4e0649a + 17fe3ae commit 088994e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
30 changes: 23 additions & 7 deletions src/test/java/org/sopt/app/application/FriendServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
package org.sopt.app.application;

import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;

import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
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.sopt.app.application.poke.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.sopt.app.interfaces.postgres.FriendRepository;

@ExtendWith(MockitoExtension.class)
class FriendServiceTest {

@SpringBootTest
public class FriendServiceTest {
@Mock
private FriendRepository friendRepository;

@Autowired
@InjectMocks
private FriendService friendService;

@Test
@DisplayName("200 - getIsNewUserSuccess")
@DisplayName("SUCCESS_친구가 없다면 새로운 유저로 판단하여 true 반환")
void getIsNewUserSuccess() {
Assertions.assertEquals(true, friendService.getIsNewUser(1L));
//given
final Long anyUserId = anyLong();
//when
when(friendRepository.findAllByFriendUserId(anyUserId)).thenReturn(List.of());
when(friendRepository.findAllByUserIdAndFriendUserIdIn(anyUserId, List.of())).thenReturn(List.of());
//then
Assertions.assertTrue(friendService.getIsNewUser(anyUserId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,74 @@

import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.sopt.app.common.config.QuerydslConfiguration;
import org.sopt.app.domain.entity.Friend;
import org.sopt.app.domain.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;

@SpringBootTest
public class FriendRepositoryTest {
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
@Import(QuerydslConfiguration.class)
class FriendRepositoryTest {

@Autowired
private FriendRepository friendRepository;

@Autowired
private UserRepository userRepository;

User user1 = new User();
User user2 = new User();

Friend friend = new Friend();

@BeforeEach
void beforeTest() {

user1 = userRepository.save(
User.builder()
.playgroundId(generateUniquePlaygroundId())
.build()
);
user2 = userRepository.save(
User.builder()
.playgroundId(generateUniquePlaygroundId())
.build()
);

friend = friendRepository.save(Friend.builder().userId(user1.getId()).friendUserId(user2.getId()).build());
}

private Long generateUniquePlaygroundId() {
long playgroundId = Long.MAX_VALUE;

for (int i = 0; i < 1000; i++) {
if (userRepository.findUserByPlaygroundId(playgroundId).isEmpty()) {
break;
}
playgroundId = playgroundId - i;
}
return playgroundId;
}

@Test
@DisplayName("200 - findAllByFriendUserId")
@DisplayName("SUCCESS_유저 아이디로 친구 찾기")
void findAllByFriendUserIdSuccess() {
Assertions.assertEquals(List.of(), friendRepository.findAllByFriendUserId(1L));
Assertions.assertEquals(List.of(friend), friendRepository.findAllByFriendUserId(user2.getId()));
}

@Test
@DisplayName("200 - findAllByUserIdAndFriendUserIdIn")
@DisplayName("SUCCESS_유저 아이디와 친구 아이디로 친구 찾기")
void findAllByUserIdAndFriendUserIdInSuccess() {
Assertions.assertEquals(List.of(), friendRepository.findAllByUserIdAndFriendUserIdIn(1L, List.of(2L)));
Assertions.assertEquals(List.of(friend), friendRepository.findAllByUserIdAndFriendUserIdIn(user1.getId(), List.of(user2.getId())));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.app.interfaces.postgres;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.sopt.app.common.config.QuerydslConfiguration;
Expand All @@ -12,14 +13,14 @@
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
@Import(QuerydslConfiguration.class)
public class MainDescriptionRepositoryTest {
class MainDescriptionRepositoryTest {

@Autowired
private MainDescriptionRepository mainDescriptionRepository;

@Test
@DisplayName("SUCCESS_메인 문구 전체 조회")
void SUCCESS_findAll() {
System.out.println(mainDescriptionRepository.findAll());
Assertions.assertDoesNotThrow(() -> mainDescriptionRepository.findAll());
}
}

0 comments on commit 088994e

Please sign in to comment.