-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/test/kotlin/nexters/weski/ski_resort/SkiResortControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package nexters.weski.ski_resort | ||
|
||
import io.mockk.every | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
|
||
@WebMvcTest(SkiResortController::class) | ||
class SkiResortControllerTest @Autowired constructor( | ||
private val mockMvc: MockMvc | ||
) { | ||
|
||
@MockkBean | ||
lateinit var skiResortService: SkiResortService | ||
|
||
@Test | ||
fun `GET api_ski-resorts should return list of ski resorts`() { | ||
// Given | ||
val skiResorts = listOf( | ||
SkiResortDto(1, "스키장 A", ResortStatus.운영중, "2023-12-01", "2024-03-01", 5, 10), | ||
SkiResortDto(2, "스키장 B", ResortStatus.예정, "2023-12-15", null, 0, 8) | ||
) | ||
every { skiResortService.getAllSkiResorts() } returns skiResorts | ||
|
||
// When & Then | ||
mockMvc.perform(get("/api/ski-resorts")) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$[0].name").value("스키장 A")) | ||
.andExpect(jsonPath("$[1].name").value("스키장 B")) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/kotlin/nexters/weski/ski_resort/SkiResortServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nexters.weski.ski_resort | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
class SkiResortServiceTest { | ||
|
||
private val skiResortRepository: SkiResortRepository = mockk() | ||
private val skiResortService = SkiResortService(skiResortRepository) | ||
|
||
@Test | ||
fun `getAllSkiResorts should return list of SkiResortDto`() { | ||
// Given | ||
val skiResorts = listOf( | ||
SkiResort(1, "스키장 A", ResortStatus.운영중, null, null, 5, 10), | ||
SkiResort(2, "스키장 B", ResortStatus.예정, null, null, 0, 8) | ||
) | ||
every { skiResortRepository.findAll() } returns skiResorts | ||
|
||
// When | ||
val result = skiResortService.getAllSkiResorts() | ||
|
||
// Then | ||
assertEquals(2, result.size) | ||
assertEquals("스키장 A", result[0].name) | ||
assertEquals("스키장 B", result[1].name) | ||
} | ||
} |