ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kotlin Clock mockito
    Kotlin 2021. 11. 10. 10:13
    import com.nhaarman.mockitokotlin2.given
    import org.junit.jupiter.api.Assertions.assertEquals
    import org.junit.jupiter.api.BeforeEach
    import org.junit.jupiter.api.Test
    import org.junit.jupiter.api.extension.ExtendWith
    import org.mockito.Mock
    import org.mockito.Mockito.mockStatic
    import org.mockito.junit.jupiter.MockitoExtension
    import org.springframework.data.projection.ProjectionFactory
    import org.springframework.data.projection.SpelAwareProxyProjectionFactory
    import java.time.Clock
    import java.time.ZonedDateTime
    
    @ExtendWith(MockitoExtension::class)
    class MyTest {
       private val clock = Clock.fixed(ZonedDateTime.parse("2021-10-25T00:00:00.000+09:00[Asia/Seoul]").toInstant(), SEOUL_ZONE_ID)
       
        @BeforeEach
        fun setup() {
            runCatching {
                val clockMock = mockStatic(Clock::class.java)
                clockMock.`when`<Clock>(Clock::systemDefaultZone).thenReturn(clock)
            }
        }
        
        @Test
        fun today(){
          assertEquals("2021-10-25T00:00+09:00[Asia/Seoul]", ZonedDateTime.now().toString())
        }
    }

    'Kotlin' 카테고리의 다른 글

    Kotlin 기본 문법  (0) 2019.08.03
    코틀린 기본요소  (2) 2019.03.20
    코틀린 프로젝트 생성 및 실행  (0) 2019.03.20
    코틀린 소개  (1) 2019.03.17

    댓글

Designed by Tistory.