Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern test code 구현 close #41 #50

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public class Pattern {

@OneToMany(mappedBy = "pattern")
private List<Result> results = new ArrayList<>();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.endlesshorses.oot.pattern;

import com.endlesshorses.oot.custom.pattern.dto.PatternListResponseDto;
import com.endlesshorses.oot.custom.pattern.entity.Pattern;
import com.endlesshorses.oot.custom.pattern.repository.PatternRepository;
import com.endlesshorses.oot.custom.pattern.service.PatternService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.List;

import static org.mockito.Mockito.when;

@SpringBootTest
public class PatternServiceTest {
@Mock
private PatternRepository patternRepository;

@InjectMocks
private PatternService patternService;

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testList() {

Pattern pattern1 = new Pattern();
Pattern pattern2 = new Pattern();


List<Pattern> patternList = Arrays.asList(pattern1, pattern2);

//패턴 레포지토리의 findAll() 메서드가 호출될 때 패턴 엔티티 목록 반환하도록 설정
when(patternRepository.findAll()).thenReturn(patternList);

// 패턴 서비스의 list() 메서드 호출
List<PatternListResponseDto> result = patternService.list();

// 결과
if (!result.isEmpty()) {
Assertions.assertEquals("리브패턴", result.get(0).getName());
Assertions.assertEquals("리브러그패턴", result.get(1).getName());
} else {
// 패턴 목록이 비어있는 경우에 대한 예외 처리
Assertions.fail("패턴 목록이 비어있습니다.");
}
}

}
Loading