bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.55k stars 329 forks source link

Test case execution of squashNulls function is unreal #922

Open zeshuai007 opened 4 years ago

zeshuai007 commented 4 years ago

In ModifierTest, the conversion result of squashNullsTests.json is not expected, because the squashNulls function cannot remove null at the first level, and then Issue#909 has a related problem description However, the test case execution result of squashNullsTests.json passed unexpectedly successfully. This confuses me. It is certain that the test case of squashNull is problematic, so I extracted some code from the use case for verification. example:

@Test
    public void doSquashNullsTest() throws Exception {
      String testFile = "/json/modifier/functions/squashNullsTests.json";
      TemplatrTestCase testCase = TemplatrTestCase.OVERWRITR;
      String expectedStr = "{\"squashThisList\" : [ \"a\", 1, \"b\" ],\n" + 
                            "\"squashThisMap\" : { \"a\": \"A\", \"c\" : \"C\"},\n" + 
                            "\"superSquashThis\" : [ \"a\", { \"x\": \"X\", \"zList\" : [ \"z1\", \"z3\" ] }, \"b\" ],\n" + 
                            "\"doNotSquash\" : { \"a\": \"A\", \"b\": null, \"c\" : \"C\" }}";
      Object toExpected = JsonUtils.jsonToObject(expectedStr);
      String actualStr = "{\"squashThisList\":[\"a\",null,1,null,\"b\"],\n" + 
                          "\"squashThisMap\":{\"a\":\"A\",\"c\":\"C\"},\n" + 
                          "\"superSquashThis\":[\"a\",null,{\"x\":\"X\",\"zList\":[\"z1\",\"z3\"]},null,\"b\"],\n" + 
                          "\"doNotSquash\":{\"a\":\"A\",\"b\":null,\"c\":\"C\"}}";
      Object toActual = JsonUtils.jsonToObject(actualStr);
      JoltTestUtil.runArrayOrderObliviousDiffy( testCase.name() + " failed case " + testFile, toExpected, toActual );
  }
zeshuai007 commented 4 years ago

result:

[RemoteTestNG] detected TestNG version 6.8.9
[TestNG] Running: .................\testng-customsuite.xml

PASSED: doSquashNullsTest

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
zeshuai007 commented 4 years ago

Verification conclusion: For squashNullsTest.json tests should use JoltTestUtil.runDiffy instead of JoltTestUtil.runArrayOrderObliviousDiffy. Any helpful suggestions are welcome.