|
1 | 1 | package com.back.koreaTravelGuide.config |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper |
| 4 | +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule |
| 5 | +import com.fasterxml.jackson.module.kotlin.KotlinModule |
3 | 6 | import org.mockito.Mockito |
| 7 | +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer |
4 | 8 | import org.springframework.boot.test.context.TestConfiguration |
5 | 9 | import org.springframework.context.annotation.Bean |
6 | 10 | import org.springframework.context.annotation.Primary |
7 | 11 | import org.springframework.data.redis.connection.RedisConnectionFactory |
| 12 | +import org.springframework.data.redis.core.RedisTemplate |
| 13 | +import org.springframework.data.redis.core.ValueOperations |
8 | 14 |
|
9 | 15 | @TestConfiguration |
10 | 16 | class TestConfig { |
11 | 17 | @Bean |
12 | 18 | @Primary |
13 | | - fun redisConnectionFactory(): RedisConnectionFactory = Mockito.mock(RedisConnectionFactory::class.java) |
| 19 | + fun testRedisConnectionFactory(): RedisConnectionFactory = Mockito.mock(RedisConnectionFactory::class.java) |
| 20 | + |
| 21 | + @Bean |
| 22 | + @Primary |
| 23 | + fun testRedisTemplate(): RedisTemplate<String, String> { |
| 24 | + @Suppress("UNCHECKED_CAST") |
| 25 | + val template = Mockito.mock(RedisTemplate::class.java) as RedisTemplate<String, String> |
| 26 | + |
| 27 | + @Suppress("UNCHECKED_CAST") |
| 28 | + val valueOps = Mockito.mock(ValueOperations::class.java) as ValueOperations<String, String> |
| 29 | + |
| 30 | + Mockito.`when`(template.opsForValue()).thenReturn(valueOps) |
| 31 | + Mockito.`when`(valueOps.get(Mockito.anyString())).thenReturn(null) |
| 32 | + |
| 33 | + return template |
| 34 | + } |
| 35 | + |
| 36 | + @Bean |
| 37 | + fun javaTimeModuleCustomizer(): Jackson2ObjectMapperBuilderCustomizer { |
| 38 | + return Jackson2ObjectMapperBuilderCustomizer { builder -> |
| 39 | + builder.modulesToInstall(JavaTimeModule()) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Bean |
| 44 | + @Primary |
| 45 | + fun testObjectMapper(): ObjectMapper { |
| 46 | + return ObjectMapper().apply { |
| 47 | + registerModule(JavaTimeModule()) |
| 48 | + registerModule(KotlinModule.Builder().build()) |
| 49 | + } |
| 50 | + } |
14 | 51 | } |
0 commit comments