File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
spring-core/src/test/java/org/springframework/util Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 62
62
* @author Rick Evans
63
63
* @author Sam Brannen
64
64
* @author Hyunjin Choi
65
+ * @author Ngoc Nhan
65
66
*/
66
67
class ObjectUtilsTests {
67
68
@@ -1114,4 +1115,22 @@ private static String prefix(Class<?> clazz) {
1114
1115
}
1115
1116
}
1116
1117
1118
+ @ Test
1119
+ void unwrapOptional () {
1120
+
1121
+ assertThat (ObjectUtils .unwrapOptional (null )).isNull ();
1122
+ assertThat (ObjectUtils .unwrapOptional (Optional .empty ())).isNull ();
1123
+ assertThat (ObjectUtils .unwrapOptional (Optional .of ("some value" ))).isEqualTo ("some value" );
1124
+
1125
+ Optional <Optional <Object >> nestedEmptyOptional = Optional .of (Optional .empty ());
1126
+ assertThatIllegalArgumentException ()
1127
+ .isThrownBy (() -> ObjectUtils .unwrapOptional (nestedEmptyOptional ))
1128
+ .withMessage ("Multi-level Optional usage not supported" );
1129
+
1130
+ Optional <Optional <String >> nestedStringOptional = Optional .of (Optional .of ("some value" ));
1131
+ assertThatIllegalArgumentException ()
1132
+ .isThrownBy (() -> ObjectUtils .unwrapOptional (nestedStringOptional ))
1133
+ .withMessage ("Multi-level Optional usage not supported" );
1134
+ }
1135
+
1117
1136
}
You can’t perform that action at this time.
0 commit comments