diff --git a/src/main/java/com/endlesshorses/oot/custom/pattern/entity/Pattern.java b/src/main/java/com/endlesshorses/oot/custom/pattern/entity/Pattern.java index 1a19186..f4f0a32 100644 --- a/src/main/java/com/endlesshorses/oot/custom/pattern/entity/Pattern.java +++ b/src/main/java/com/endlesshorses/oot/custom/pattern/entity/Pattern.java @@ -26,4 +26,5 @@ public class Pattern { @OneToMany(mappedBy = "pattern") private List results = new ArrayList<>(); + } diff --git a/src/test/java/com/endlesshorses/oot/pattern/PatternServiceTest.java b/src/test/java/com/endlesshorses/oot/pattern/PatternServiceTest.java new file mode 100644 index 0000000..6ec0962 --- /dev/null +++ b/src/test/java/com/endlesshorses/oot/pattern/PatternServiceTest.java @@ -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 patternList = Arrays.asList(pattern1, pattern2); + + //패턴 레포지토리의 findAll() 메서드가 호출될 때 패턴 엔티티 목록 반환하도록 설정 + when(patternRepository.findAll()).thenReturn(patternList); + + // 패턴 서비스의 list() 메서드 호출 + List result = patternService.list(); + + // 결과 + if (!result.isEmpty()) { + Assertions.assertEquals("리브패턴", result.get(0).getName()); + Assertions.assertEquals("리브러그패턴", result.get(1).getName()); + } else { + // 패턴 목록이 비어있는 경우에 대한 예외 처리 + Assertions.fail("패턴 목록이 비어있습니다."); + } + } + +}