|
|
@ -18,11 +18,11 @@ package org.springframework.boot.context.properties;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.fail;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link PropertyMapper}.
|
|
|
|
* Tests for {@link PropertyMapper}.
|
|
|
@ -56,7 +56,7 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
|
|
|
void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
|
|
|
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assertions::fail);
|
|
|
|
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -100,14 +100,14 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenNonNullWhenSuppliedNullShouldNotMap() {
|
|
|
|
void whenNonNullWhenSuppliedNullShouldNotMap() {
|
|
|
|
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
|
|
|
|
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() {
|
|
|
|
void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() {
|
|
|
|
this.map.from(() -> {
|
|
|
|
this.map.from(() -> {
|
|
|
|
throw new NullPointerException();
|
|
|
|
throw new NullPointerException();
|
|
|
|
}).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
|
|
|
|
}).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -118,7 +118,7 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenTrueWhenValueIsFalseShouldNotMap() {
|
|
|
|
void whenTrueWhenValueIsFalseShouldNotMap() {
|
|
|
|
this.map.from(false).whenTrue().toCall(Assertions::fail);
|
|
|
|
this.map.from(false).whenTrue().toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -129,17 +129,17 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenFalseWhenValueIsTrueShouldNotMap() {
|
|
|
|
void whenFalseWhenValueIsTrueShouldNotMap() {
|
|
|
|
this.map.from(true).whenFalse().toCall(Assertions::fail);
|
|
|
|
this.map.from(true).whenFalse().toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenHasTextWhenValueIsNullShouldNotMap() {
|
|
|
|
void whenHasTextWhenValueIsNullShouldNotMap() {
|
|
|
|
this.map.from(() -> null).whenHasText().toCall(Assertions::fail);
|
|
|
|
this.map.from(() -> null).whenHasText().toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenHasTextWhenValueIsEmptyShouldNotMap() {
|
|
|
|
void whenHasTextWhenValueIsEmptyShouldNotMap() {
|
|
|
|
this.map.from("").whenHasText().toCall(Assertions::fail);
|
|
|
|
this.map.from("").whenHasText().toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -156,7 +156,7 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenEqualToWhenValueIsNotEqualShouldNotMatch() {
|
|
|
|
void whenEqualToWhenValueIsNotEqualShouldNotMatch() {
|
|
|
|
this.map.from("123").whenEqualTo("321").toCall(Assertions::fail);
|
|
|
|
this.map.from("123").whenEqualTo("321").toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -168,7 +168,7 @@ class PropertyMapperTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() {
|
|
|
|
void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() {
|
|
|
|
Supplier<Number> supplier = () -> 123L;
|
|
|
|
Supplier<Number> supplier = () -> 123L;
|
|
|
|
this.map.from(supplier).whenInstanceOf(Double.class).toCall(Assertions::fail);
|
|
|
|
this.map.from(supplier).whenInstanceOf(Double.class).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -179,7 +179,7 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenWhenValueDoesNotMatchShouldNotMap() {
|
|
|
|
void whenWhenValueDoesNotMatchShouldNotMap() {
|
|
|
|
this.map.from("123").when("321"::equals).toCall(Assertions::fail);
|
|
|
|
this.map.from("123").when("321"::equals).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -197,12 +197,12 @@ class PropertyMapperTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
|
|
|
void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
|
|
|
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(Assertions::fail);
|
|
|
|
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void whenWhenValueNotMatchesShouldSupportChainedCalls() {
|
|
|
|
void whenWhenValueNotMatchesShouldSupportChainedCalls() {
|
|
|
|
this.map.from("123").when("456"::equals).when("123"::equals).toCall(Assertions::fail);
|
|
|
|
this.map.from("123").when("456"::equals).when("123"::equals).toCall(() -> fail(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|