Add test cases for ObjectUtils#unwrapOptional
See gh-33618
This commit is contained in:
parent
fc8bd64f34
commit
4d87c77649
|
|
@ -62,6 +62,7 @@ import static org.springframework.util.ObjectUtils.isEmpty;
|
|||
* @author Rick Evans
|
||||
* @author Sam Brannen
|
||||
* @author Hyunjin Choi
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
class ObjectUtilsTests {
|
||||
|
||||
|
|
@ -1114,4 +1115,22 @@ class ObjectUtilsTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void unwrapOptional() {
|
||||
|
||||
assertThat(ObjectUtils.unwrapOptional(null)).isNull();
|
||||
assertThat(ObjectUtils.unwrapOptional(Optional.empty())).isNull();
|
||||
assertThat(ObjectUtils.unwrapOptional(Optional.of("some value"))).isEqualTo("some value");
|
||||
|
||||
Optional<Optional<Object>> nestedEmptyOptional = Optional.of(Optional.empty());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ObjectUtils.unwrapOptional(nestedEmptyOptional))
|
||||
.withMessage("Multi-level Optional usage not supported");
|
||||
|
||||
Optional<Optional<String>> nestedStringOptional = Optional.of(Optional.of("some value"));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ObjectUtils.unwrapOptional(nestedStringOptional))
|
||||
.withMessage("Multi-level Optional usage not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue