Skip to content

Add test cases for ObjectUtils#unwrapOptional #33618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* @author Rick Evans
* @author Sam Brannen
* @author Hyunjin Choi
* @author Ngoc Nhan
*/
class ObjectUtilsTests {

Expand Down Expand Up @@ -1114,4 +1115,22 @@ private static String prefix(Class<?> clazz) {
}
}

@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");
}

}