@@ -526,6 +526,8 @@ public void updateListener2Test() {
526
526
.put ("intKey" , Long .valueOf (42 ));
527
527
//.put("doubleKey", Double.valueOf(-23.45e67)); PROBLEM WITH DOUBLE CONVERTING TO BIGDECIMAL AFTER JSONOBJECT.TOSTRING
528
528
529
+ final JSONObject jsonObject3 = new JSONObject (jsonObject2 .toString ());
530
+
529
531
final JSONObject oldJsonObject2 = new JSONObject (jsonObject2 .toString ());
530
532
531
533
jsonObject1 .addUpdateListenerGlobal (evt -> {
@@ -565,8 +567,83 @@ public void updateListener2Test() {
565
567
assertEquals (jsonObject2 .toString (), oldJsonObject2 .toString ());
566
568
567
569
jsonObject1 .update (jsonObject2 );
570
+ jsonObject3 .updateOrRemove (jsonObject2 );
568
571
569
572
assertNotEquals (jsonObject1 .toString (), oldJsonObject1 .toString ());
570
573
assertEquals (jsonObject2 .toString (), oldJsonObject2 .toString ());
571
574
}
575
+
576
+ @ Test
577
+ public void updateOrRemoveSrcEmptyTest () {
578
+ try {
579
+ final JSONObject jsonObject1 = new JSONObject ();
580
+ final JSONObject jsonObject2 = new JSONObject ()
581
+ .put ("trueKey" , Boolean .valueOf (true ))
582
+ .put ("falseKey" , Boolean .valueOf (false ))
583
+ .put ("stringKey" , "hello world!" )
584
+ .put ("nullKey" , null );
585
+
586
+ jsonObject1 .addUpdateListenerGlobal (evt -> {
587
+ final Object oldValue = evt .getOldValue ();
588
+ final Object newValue = evt .getNewValue ();
589
+
590
+ if (!(oldValue == JSONObject .NULL && newValue == null )) {
591
+ assertNotEquals (oldValue , newValue );
592
+ }
593
+ });
594
+
595
+ jsonObject1 .updateOrRemove (jsonObject2 );
596
+ } catch (Exception ex ) {
597
+ ex .printStackTrace ();
598
+ fail (ex .getMessage ());
599
+ }
600
+ }
601
+
602
+ @ Test
603
+ public void updateOrRemoveDstEmptyTest () {
604
+ try {
605
+ final JSONObject jsonObject1 = new JSONObject ()
606
+ .put ("trueKey" , Boolean .valueOf (true ))
607
+ .put ("falseKey" , Boolean .valueOf (false ))
608
+ .put ("stringKey" , "hello world!" )
609
+ .put ("nullKey" , null );
610
+ final JSONObject jsonObject2 = new JSONObject ();
611
+
612
+ jsonObject1 .addUpdateListenerGlobal (evt -> {
613
+ final Object oldValue = evt .getOldValue ();
614
+ final Object newValue = evt .getNewValue ();
615
+
616
+ if (!(oldValue == JSONObject .NULL && newValue == null )) {
617
+ assertNotEquals (oldValue , newValue );
618
+ }
619
+ });
620
+
621
+ jsonObject1 .updateOrRemove (jsonObject2 );
622
+ } catch (Exception ex ) {
623
+ ex .printStackTrace ();
624
+ fail (ex .getMessage ());
625
+ }
626
+ }
627
+
628
+ @ Test
629
+ public void updateOrRemoveAlltEmptyTest () {
630
+ try {
631
+ final JSONObject jsonObject1 = new JSONObject ();
632
+ final JSONObject jsonObject2 = new JSONObject ();
633
+
634
+ jsonObject1 .addUpdateListenerGlobal (evt -> {
635
+ final Object oldValue = evt .getOldValue ();
636
+ final Object newValue = evt .getNewValue ();
637
+
638
+ if (!(oldValue == JSONObject .NULL && newValue == null )) {
639
+ assertNotEquals (oldValue , newValue );
640
+ }
641
+ });
642
+
643
+ jsonObject1 .updateOrRemove (jsonObject2 );
644
+ } catch (Exception ex ) {
645
+ ex .printStackTrace ();
646
+ fail (ex .getMessage ());
647
+ }
648
+ }
572
649
}
0 commit comments