3535import java .util .stream .Stream ;
3636
3737import static org .assertj .core .api .Assertions .assertThat ;
38+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
3839
3940/**
4041 * Unit tests for {@link SnakeYamlOps}.
@@ -111,7 +112,14 @@ void isMapReturnsTrueForMap() {
111112 void isMapReturnsFalseForNonMap () {
112113 assertThat (ops .isMap (new ArrayList <>())).isFalse ();
113114 assertThat (ops .isMap ("test" )).isFalse ();
114- assertThat (ops .isMap (null )).isFalse ();
115+ }
116+
117+ @ Test
118+ @ DisplayName ("isMap() throws NullPointerException for null" )
119+ void isMapThrowsNullPointerExceptionForNull () {
120+ assertThatThrownBy (() -> ops .isMap (null ))
121+ .isInstanceOf (NullPointerException .class )
122+ .hasMessageContaining ("must not be null" );
115123 }
116124
117125 @ Test
@@ -125,7 +133,14 @@ void isListReturnsTrueForList() {
125133 void isListReturnsFalseForNonList () {
126134 assertThat (ops .isList (new LinkedHashMap <>())).isFalse ();
127135 assertThat (ops .isList ("test" )).isFalse ();
128- assertThat (ops .isList (null )).isFalse ();
136+ }
137+
138+ @ Test
139+ @ DisplayName ("isList() throws NullPointerException for null" )
140+ void isListThrowsNullPointerExceptionForNull () {
141+ assertThatThrownBy (() -> ops .isList (null ))
142+ .isInstanceOf (NullPointerException .class )
143+ .hasMessageContaining ("must not be null" );
129144 }
130145
131146 @ Test
@@ -371,15 +386,11 @@ void mergeToListAppendsToExistingList() {
371386 }
372387
373388 @ Test
374- @ DisplayName ("mergeToList() creates new list from null" )
375- void mergeToListCreatesNewListFromNull () {
376- final DataResult <Object > result = ops .mergeToList (null , ops .createInt (1 ));
377-
378- assertThat (result .isSuccess ()).isTrue ();
379- @ SuppressWarnings ("unchecked" )
380- final List <Object > list = (List <Object >) result .result ().orElseThrow ();
381- assertThat (list ).hasSize (1 );
382- assertThat (list .get (0 )).isEqualTo (1 );
389+ @ DisplayName ("mergeToList() throws NullPointerException for null list" )
390+ void mergeToListThrowsNullPointerExceptionForNullList () {
391+ assertThatThrownBy (() -> ops .mergeToList (null , ops .createInt (1 )))
392+ .isInstanceOf (NullPointerException .class )
393+ .hasMessageContaining ("must not be null" );
383394 }
384395
385396 @ Test
@@ -461,18 +472,15 @@ void mergeToMapAddsKeyValueToExistingMap() {
461472 }
462473
463474 @ Test
464- @ DisplayName ("mergeToMap() creates new map from null" )
465- void mergeToMapCreatesNewMapFromNull () {
466- final DataResult < Object > result = ops .mergeToMap (
475+ @ DisplayName ("mergeToMap() throws NullPointerException for null map " )
476+ void mergeToMapThrowsNullPointerExceptionForNullMap () {
477+ assertThatThrownBy (() -> ops .mergeToMap (
467478 null ,
468479 ops .createString ("key" ),
469480 ops .createString ("value" )
470- );
471-
472- assertThat (result .isSuccess ()).isTrue ();
473- @ SuppressWarnings ("unchecked" )
474- final Map <String , Object > map = (Map <String , Object >) result .result ().orElseThrow ();
475- assertThat (map .get ("key" )).isEqualTo ("value" );
481+ ))
482+ .isInstanceOf (NullPointerException .class )
483+ .hasMessageContaining ("must not be null" );
476484 }
477485
478486 @ Test
@@ -709,11 +717,11 @@ void convertToConvertsMaps() {
709717 }
710718
711719 @ Test
712- @ DisplayName ("convertTo() returns null for null input" )
713- void convertToReturnsNullForNullInput () {
714- final Object result = ops .convertTo (ops , null );
715-
716- assertThat ( result ). isNull ( );
720+ @ DisplayName ("convertTo() throws NullPointerException for null input" )
721+ void convertToThrowsNullPointerExceptionForNullInput () {
722+ assertThatThrownBy (() -> ops .convertTo (ops , null ))
723+ . isInstanceOf ( NullPointerException . class )
724+ . hasMessageContaining ( "must not be null" );
717725 }
718726 }
719727
0 commit comments