본문 바로가기

2019/1212

[MockK] JPA repository.save param assert @MockK lateinit var repository: UserRepository @Test fun test() { // given lateinit var result: User every { repository.save(any()) } answers { result = firstArg() // set save argument firstArg() } // when // then assertEquals(result, ...) // save 파라미터로 확인 가능 } @Test fun test() { // given every { repository.save(any()) } returnsArgument(0) // #1 every { repository.save(any()) } returnsArgument 0.. 2019. 12. 9.
[Test] webClient 통신 테스트 (mockServer) // build.gradle plugins{ // add testImplementation("org.mock-server:mockserver-netty:5.7.2") } mockserver 의존성 추가 @TestInstance(TestInstance.Lifecycle.PER_CLASS) abstract class MockServerNettyHelper { companion object { val GSON = Gson() } private val host = "http://localhost" private val port = 8000 lateinit var mockServer: ClientAndServer @BeforeAll fun startMockServer() { // #1 mockServer = Cl.. 2019. 12. 8.
[leetcode][539] Minimum Time Difference 문제 : https://leetcode.com/problems/minimum-time-difference/ 문자열들을 탐색하면서 ':' 기준으로 시, 분을 나눈다. 시 * 60 + 분 (분으로 변환. 정수형)을 리스트에 저장한다. 리스트를 오름차순 정렬한다. 가장 작은 수에 + 24*60 을 리스트의 가장뒤에 추가한다. 리스트를 앞에서부터 탐색하면서 인접한 분들의 차이를 구하고 이들 중 최소값이 정답이 된다. 시간복잡도는 O(NlogN) 소스코드 : https://github.com/fpdjsns/Algorithm/blob/master/leetcode/easy/1266.%20Minimum%20Time%20Visiting%20All%20Points.py 2019. 12. 8.
[leetcode][1266] Minimum Time Visiting All Points 문제 : https://leetcode.com/problems/minimum-time-visiting-all-points/ 두 점 사이의 거리 = | x점 사이의 거리 | + | y점 사이의 거리 | potints를 앞에서부터 탐색하면서 두 점 사이의 거리들의 합을 구하면 정답이 된다. 소스코드 : https://github.com/fpdjsns/Algorithm/blob/master/leetcode/easy/1266.%20Minimum%20Time%20Visiting%20All%20Points.py 이제부터는 파이썬으로 풀도록 노력해봐야겠다. 2019. 12. 7.
[Kotlin] String to LocalDateTime parse 말머리가 Kotlin인 이유는 kotlin으로 작성했기 때문.. java라고 봐도 무방하다. import java.time.LocalDateTime.of class LocalDateTimeTest { @Test fun test() { // expect assertEquals(of(2019, 12, 4, 12, 3, 12), "2019-12-04 12:03:12".toLocalDateTime()) assertEquals(of(2019, 12, 4, 12, 3), "2019-12-04 12:03".toLocalDateTime()) assertEquals(of(2019, 12, 4, 12, 3,12,100000000), "2019-12-04 12:03:12.1".toLocalDateTime()) } } 테스트.. 2019. 12. 7.
[JUnit5] @TestInstance TestInstance 는 테스트 인스턴스의 라이프 사이클을 설정할 때 사용한다. - PER_METHOD : test 함수 당 인스턴스가 생성된다. - PER_CLASS : test 클래스 당 인스턴스가 생성된다. @TestInstance(TestInstance.Lifecycle.PER_CLASS) class Test() { @BeforeAll fun setUp(){ println("setUp") } @AfterAll fun clean(){ println("clean") } @Test fun test() { } } 위와 같이 @TestInstance(TestInstance.Lifecycle.PER_CLASS) 어노테이션으로 라이프 사이클을 클래스 단위로 설정할 수 있다. 라이프 사이클을 클래스 단위로 지.. 2019. 12. 4.