Polish "Add support for converting String to Pattern"
See gh-24311
This commit is contained in:
@@ -319,10 +319,16 @@ class DefaultConversionServiceTests {
|
||||
assertThat(convertToUUID).isEqualTo(uuid);
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringToPatternEmptyString() {
|
||||
assertThat(conversionService.convert("", Pattern.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringToPattern() {
|
||||
String regex = "\\s";
|
||||
assertThat(conversionService.convert(regex, Pattern.class)).extracting(Pattern::pattern).isEqualTo(regex);
|
||||
String pattern = "\\s";
|
||||
assertThat(conversionService.convert(pattern, Pattern.class))
|
||||
.isInstanceOfSatisfying(Pattern.class, regex -> assertThat(regex.pattern()).isEqualTo(pattern));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.core.convert.support
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* Tests for Kotlin support in [DefaultConversionService].
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class DefaultConversionServiceKotlinTests {
|
||||
|
||||
private val conversionService = DefaultConversionService()
|
||||
|
||||
@Test
|
||||
fun stringToRegexEmptyString() {
|
||||
assertThat(conversionService.convert("", Regex::class.java)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringToRegex() {
|
||||
val pattern = "\\w+"
|
||||
assertThat(conversionService.convert(pattern, Regex::class.java)).isInstanceOfSatisfying(
|
||||
Regex::class.java
|
||||
) { regex -> assertThat(regex.pattern).isEqualTo(pattern) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun regexToString() {
|
||||
val pattern = "\\w+"
|
||||
assertThat(conversionService.convert(pattern.toRegex(), String::class.java)).isEqualTo(pattern)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user