Skip to content

Commit de7efc4

Browse files
committed
✅ Increase coverage
1 parent f3ec10c commit de7efc4

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

src/main/kotlin/io/github/tobi/laa/spring/boot/embedded/redis/conf/RedisConfParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal object RedisConfParser {
8181
}
8282
}
8383

84-
private enum class ArgsParseState {
84+
internal enum class ArgsParseState {
8585
UNESCAPED, ESCAPED_SINGLE, ESCAPED_DOUBLE
8686
}
8787
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.github.tobi.laa.spring.boot.embedded.redis
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.junit.jupiter.api.DisplayName
5+
import org.junit.jupiter.api.Nested
6+
import org.junit.jupiter.api.Test
7+
8+
@DisplayName("RedisFlushAll tests")
9+
internal class RedisFlushAllTest {
10+
11+
@Nested
12+
@DisplayName("RedisFlushAll.Mode tests")
13+
internal inner class ModeTest {
14+
15+
@Test
16+
@DisplayName("Static field entries returns all enum values")
17+
fun getEntries_returnsAllValues() {
18+
assertThat(RedisFlushAll.Mode.entries).containsExactlyInAnyOrder(
19+
RedisFlushAll.Mode.AFTER_METHOD,
20+
RedisFlushAll.Mode.AFTER_CLASS,
21+
RedisFlushAll.Mode.NEVER
22+
)
23+
}
24+
}
25+
}
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
package io.github.tobi.laa.spring.boot.embedded.redis.conf
22

3+
import io.mockk.junit5.MockKExtension
34
import org.assertj.core.api.Assertions.assertThatThrownBy
45
import org.junit.jupiter.api.DisplayName
56
import org.junit.jupiter.api.Test
6-
import redis.embedded.RedisServer
7+
import org.junit.jupiter.api.extension.ExtendWith
8+
import redis.embedded.RedisInstance
79

810
@DisplayName("Tests for RedisConfLocator")
11+
@ExtendWith(MockKExtension::class)
912
internal class RedisConfLocatorTest {
1013

1114
@Test
12-
@DisplayName("RedisConfLocator should throw exception for missing file")
15+
@DisplayName("RedisConfLocator should throw exception for empty args")
16+
fun emptyArgs_shouldThrowException() {
17+
val redis = TestRedis(emptyList())
18+
assertThatThrownBy { RedisConfLocator.locate(redis) }
19+
.isExactlyInstanceOf(IllegalStateException::class.java)
20+
.hasMessage("No config file found for embedded Redis server: $redis")
21+
}
22+
23+
@Test
24+
@DisplayName("RedisConfLocator should throw exception for missing file with .conf extension")
1325
fun missingFile_shouldThrowException() {
14-
val redis = RedisServer(6379, emptyList(), false)
26+
val redis = TestRedis(listOf("redis.properties"))
1527
assertThatThrownBy { RedisConfLocator.locate(redis) }
1628
.isExactlyInstanceOf(IllegalStateException::class.java)
1729
.hasMessage("No config file found for embedded Redis server: $redis")
1830
}
31+
32+
private class TestRedis(args: List<String>) : RedisInstance(0, args, null, false, null, null) {
33+
34+
override fun start() {}
35+
override fun stop() {}
36+
override fun ports(): MutableList<Int> = mutableListOf()
37+
override fun isActive(): Boolean = false
38+
}
1939
}

src/test/kotlin/io/github/tobi/laa/spring/boot/embedded/redis/conf/RedisConfParserTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.assertj.core.api.Assertions.*
55
import org.assertj.core.api.ThrowableAssert.ThrowingCallable
66
import org.junit.jupiter.api.DisplayName
77
import org.junit.jupiter.api.Named.named
8+
import org.junit.jupiter.api.Nested
9+
import org.junit.jupiter.api.Test
810
import org.junit.jupiter.api.extension.ExtensionContext
911
import org.junit.jupiter.params.ParameterizedTest
1012
import org.junit.jupiter.params.provider.Arguments
@@ -201,4 +203,19 @@ internal class RedisConfParserTest {
201203
)
202204
}
203205
}
206+
207+
@Nested
208+
@DisplayName("RedisConfParser.ArgsParseState tests")
209+
internal inner class ArgsParseStateTest {
210+
211+
@Test
212+
@DisplayName("Static field entries returns all enum values")
213+
fun getEntries_returnsAllValues() {
214+
assertThat(RedisConfParser.ArgsParseState.entries).containsExactlyInAnyOrder(
215+
RedisConfParser.ArgsParseState.UNESCAPED,
216+
RedisConfParser.ArgsParseState.ESCAPED_SINGLE,
217+
RedisConfParser.ArgsParseState.ESCAPED_DOUBLE
218+
)
219+
}
220+
}
204221
}

0 commit comments

Comments
 (0)