@@ -178,6 +178,7 @@ public void expectNotEmpty() {
178178 assertEquals ("" , X .expectNotEmpty ("" , null , "" ));
179179
180180 assertEquals ("" , X .expectNotEmpty (null , null , null , null ));
181+ assertEquals ("v3" , X .expectNotEmpty (null , null , "v3" , null ));
181182 assertEquals ("v4" , X .expectNotEmpty (null , null , null , "v4" ));
182183 }
183184
@@ -466,4 +467,61 @@ public void sneakyThrow_ErrorInput_ThrowsSameError() {
466467 });
467468 }
468469
470+ @ Test
471+ void expectEquals () {
472+ final User old = new User ();
473+ final User input = new User ();
474+
475+ // input.name = null, old.name = null => DO NOTHING
476+ X .expectEquals (input , old , User ::getName , User ::setName );
477+ assertNull (input .getName ());
478+ assertNull (old .getName ());
479+
480+ old .setName ("A" );
481+ // input.name = null, old.name = "A" => input.name = "A", old.name = "A"
482+ X .expectEquals (input , old , User ::getName , User ::setName );
483+ assertEquals ("A" , input .getName ());
484+ assertEquals ("A" , old .getName ());
485+
486+ // input.name = "A", old.name = "A" => DO NOTHING
487+ X .expectEquals (input , old , User ::getName , User ::setName );
488+ assertEquals ("A" , input .getName ());
489+ assertEquals ("A" , old .getName ());
490+
491+ // input.name = "A", old.name = null => input.name = "A", old.name = "A"
492+ old .setName (null );
493+ X .expectEquals (input , old , User ::getName , User ::setName );
494+ assertEquals ("A" , input .getName ());
495+ assertEquals ("A" , old .getName ());
496+
497+ // input.name = "B", old.name = "A" => throw IllegalArgumentException
498+ input .setName ("B" );
499+ assertThrows (IllegalArgumentException .class , () -> X .expectEquals (input , old , User ::getName , User ::setName , "Name cannot be modified" ));
500+ }
501+
502+ @ Test
503+ void expectEqualsBasedOld () {
504+ final User old = new User ();
505+ final User input = new User ();
506+
507+ // input.name = null, old.name = null => DO NOTHING
508+ X .expectEqualsBasedOld (input , old , User ::getName , input ::setName );
509+ assertNull (input .getName ());
510+ assertNull (old .getName ());
511+
512+ old .setName ("A" );
513+ // input.name = null, old.name = "A" => input.name = "A", old.name = "A"
514+ X .expectEqualsBasedOld (input , old , User ::getName , input ::setName );
515+ assertEquals ("A" , input .getName ());
516+ assertEquals ("A" , old .getName ());
517+
518+ // input.name = "B", old.name = "A" => throw IllegalArgumentException
519+ input .setName ("B" );
520+ assertThrows (IllegalArgumentException .class , () -> X .expectEqualsBasedOld (input , old , User ::getName , input ::setName , "Name cannot be modified" ));
521+
522+ // input.name = "B", old.name = null => throw IllegalArgumentException
523+ old .setName (null );
524+ assertThrows (IllegalArgumentException .class , () -> X .expectEqualsBasedOld (input , old , User ::getName , input ::setName , "Name cannot be modified" ));
525+ }
526+
469527}
0 commit comments