|
17 | 17 | import org.junit.jupiter.api.DisplayName; |
18 | 18 | import org.junit.jupiter.api.Test; |
19 | 19 | import org.junit.jupiter.params.ParameterizedTest; |
| 20 | +import org.junit.jupiter.params.provider.Arguments; |
20 | 21 | import org.junit.jupiter.params.provider.CsvSource; |
| 22 | +import org.junit.jupiter.params.provider.MethodSource; |
| 23 | + |
| 24 | +import java.util.stream.Stream; |
21 | 25 |
|
22 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
23 | 28 |
|
24 | 29 | class OracleNoSqlLikeConverterTest { |
25 | 30 |
|
| 31 | + |
26 | 32 | @ParameterizedTest(name = "LIKE \"{0}\" -> pattern \"{1}\"") |
27 | | - @CsvSource(textBlock = """ |
28 | | - %Ota%;.*\\QOta\\E.* |
29 | | - Ota%;\\QOta\\E.* |
30 | | - %Ota;.*\\QOta\\E |
31 | | - Ota;\\QOta\\E |
32 | | - Ot_;\\QOt\\E. |
33 | | - _ta;.\\Qta\\E |
34 | | - %t_a%;.*\\Qt\\E.\\Qa\\E.* |
35 | | - .+;\\Q.+\\E |
36 | | - """, delimiter = ';') |
37 | | - @DisplayName("Converts SQL LIKE to Oracle NoSQL regex_like pattern (%, _ and literal quoting)") |
| 33 | + @MethodSource("cases") |
| 34 | + @DisplayName("Converts SQL LIKE to Oracle NoSQL regex_like pattern (no anchors)") |
38 | 35 | void shouldConvertSqlLikeToOracleNoSqlRegex(String like, String expected) { |
39 | 36 | String actual = OracleNoSqlLikeConverter.INSTANCE.convert(like); |
40 | 37 | assertThat(actual).isEqualTo(expected); |
41 | 38 | } |
42 | 39 |
|
| 40 | + static Stream<Arguments> cases() { |
| 41 | + return Stream.of( |
| 42 | + // starts / ends / contains / exact |
| 43 | + arguments("Lu%", "Lu.*"), |
| 44 | + arguments("%Lu", ".*Lu"), |
| 45 | + arguments("%Lu%", ".*Lu.*"), |
| 46 | + arguments("Lu", "Lu"), |
| 47 | + |
| 48 | + // single-char wildcard |
| 49 | + arguments("Ot_", "Ot."), |
| 50 | + arguments("_ta", ".ta"), |
| 51 | + |
| 52 | + // escaping of regex metacharacters |
| 53 | + arguments("%a.c%", ".*a\\.c.*"), |
| 54 | + arguments("100% match", "100.* match"), |
| 55 | + |
| 56 | + // edge cases |
| 57 | + arguments("", ""), // empty LIKE -> empty pattern |
| 58 | + arguments("%%", ".*.*"), // only wildcards |
| 59 | + arguments("__", "..") |
| 60 | + ); |
| 61 | + } |
| 62 | + |
43 | 63 | @Test |
44 | 64 | @DisplayName("Returns empty string for null input") |
45 | 65 | void shouldReturnEmptyForNull() { |
|
0 commit comments