Skip to content

Commit f07ddd9

Browse files
authored
Merge pull request #96 from Alanscut/bean-test
improve the confused assert message
2 parents 18eddf7 + 08719d4 commit f07ddd9

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

src/test/java/org/json/junit/JSONObjectTest.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,24 @@ public void jsonObjectByBean2() {
589589
jsonObject.has("someString"));
590590
assertFalse("Normal field name (myDouble) processing did not work",
591591
jsonObject.has("myDouble"));
592-
assertFalse("Normal field name (someFloat) found",
592+
assertFalse("Normal field name (someFloat) processing did not work",
593593
jsonObject.has("someFloat"));
594-
assertFalse("Ignored field found!",
594+
assertFalse("Ignored field not found!",
595595
jsonObject.has("ignoredInt"));
596-
assertTrue("Normal field name (someInt) processing did not work",
596+
// getSomeInt() has no user-defined annotation
597+
assertTrue("Normal field name (someInt) should have been found",
597598
jsonObject.has("someInt"));
598-
assertTrue("Normal field name (someLong) processing did not work",
599+
// the user-defined annotation does not replace any value, so someLong should be found
600+
assertTrue("Normal field name (someLong) should have been found",
599601
jsonObject.has("someLong"));
600-
assertTrue("Overridden String field name (myStringField) not found",
602+
// myStringField replaces someString property name via user-defined annotation
603+
assertTrue("Overridden String field name (myStringField) should have been found",
601604
jsonObject.has("myStringField"));
602-
assertTrue("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) not found",
605+
// weird name replaces myDouble property name via user-defined annotation
606+
assertTrue("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) should have been found",
603607
jsonObject.has("Some Weird NAme that Normally Wouldn't be possible!"));
604-
assertTrue("Overridden String field name (InterfaceField) not found",
608+
// InterfaceField replaces someFloat property name via user-defined annotation
609+
assertTrue("Overridden String field name (InterfaceField) should have been found",
605610
jsonObject.has("InterfaceField"));
606611
}
607612

@@ -619,26 +624,39 @@ public void jsonObjectByBean3() {
619624
jsonObject.has("someInt"));
620625
assertFalse("Normal field name (myDouble) processing did not work",
621626
jsonObject.has("myDouble"));
622-
assertFalse("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) FOUND!",
627+
// myDouble was replaced by weird name, and then replaced again by AMoreNormalName via user-defined annotation
628+
assertFalse("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) should not be FOUND!",
623629
jsonObject.has("Some Weird NAme that Normally Wouldn't be possible!"));
624-
assertFalse("Normal field name (someFloat) found",
630+
assertFalse("Normal field name (someFloat) found, but was overridden",
625631
jsonObject.has("someFloat"));
626-
assertFalse("Ignored field found!",
632+
assertFalse("Ignored field found! but was overridden",
627633
jsonObject.has("ignoredInt"));
628-
assertFalse("Ignored field at the same level as forced name found",
634+
// shouldNotBeJSON property name was first ignored, then replaced by ShouldBeIgnored via user-defined annotations
635+
assertFalse("Ignored field at the same level as forced name should not have been found",
629636
jsonObject.has("ShouldBeIgnored"));
630-
assertTrue("Overridden int field name (newIntFieldName) not found",
637+
// able property name was replaced by Getable via user-defined annotation
638+
assertFalse("Normally ignored field (able) with explicit property name should not have been found",
639+
jsonObject.has("able"));
640+
// property name someInt was replaced by newIntFieldName via user-defined annotation
641+
assertTrue("Overridden int field name (newIntFieldName) should have been found",
631642
jsonObject.has("newIntFieldName"));
632-
assertTrue("Normal field name (someLong) processing did not work",
643+
// property name someLong was not replaced via user-defined annotation
644+
assertTrue("Normal field name (someLong) should have been found",
633645
jsonObject.has("someLong"));
634-
assertTrue("Overridden String field name (myStringField) not found",
646+
// property name someString was replaced by myStringField via user-defined annotation
647+
assertTrue("Overridden String field name (myStringField) should have been found",
635648
jsonObject.has("myStringField"));
636-
assertTrue(jsonObject.has("AMoreNormalName"));
637-
assertTrue("Overridden String field name (InterfaceField) not found",
649+
// property name myDouble was replaced by a weird name, followed by AMoreNormalName via user-defined annotations
650+
assertTrue("Overridden double field name (AMoreNormalName) should have been found",
651+
jsonObject.has("AMoreNormalName"));
652+
// property name someFloat was replaced by InterfaceField via user-defined annotation
653+
assertTrue("Overridden String field name (InterfaceField) should have been found",
638654
jsonObject.has("InterfaceField"));
639-
assertTrue("Forced field not found!",
655+
// property name ignoredInt was replaced by none, followed by forcedInt via user-defined annotations
656+
assertTrue("Forced field should have been found!",
640657
jsonObject.has("forcedInt"));
641-
assertTrue("Normally ignored field (getable) with explicit property name not found",
658+
// property name able was replaced by Getable via user-defined annotation
659+
assertTrue("Overridden boolean field name (Getable) should have been found",
642660
jsonObject.has("Getable"));
643661
}
644662

0 commit comments

Comments
 (0)