test: adjust flaky tests assertions on ConverterAwareMappingSpannerEntityWriterTests #2341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In the test case
com.google.cloud.spring.data.spanner.core.convert.ConverterAwareMappingSpannerEntityWriterTests#writeJsonArrayTest
andcom.google.cloud.spring.data.spanner.core.convert.ConverterAwareMappingSpannerEntityWriterTests#writeJsonTest
, we changed the assertion methods on the array of JSON elements.We used
org.mockito.ArgumentCaptor
to extract the argument andorg.skyscreamer.jsonassert.JSONAssert
to assert the JSON elements.Why are the changes needed?
There is an implementation-dependent operation in
ConverterAwareMappingSpannerEntityWriter#convertJsonToValue
, which is identified by the engine NonDex.When setting json object in
ConverterAwareMappingSpannerEntityWriter
will useconvertJsonToValue
.spring-cloud-gcp/spring-cloud-gcp-data-spanner/src/main/java/com/google/cloud/spring/data/spanner/core/convert/ConverterAwareMappingSpannerEntityWriter.java
Line 375 in d7a10f5
However, in the test
ConverterAwareMappingSpannerEntityWriterTests#writeJsonArrayTest
andConverterAwareMappingSpannerEntityWriterTests#writeJsonTest
, we assert the json argument string in particular order, which would not be guaranteed in different Gson/Java version.For example, there are possible orders in the argument of
toJsonArray
as below.Error message shown in NonDex engine is as below:
As a result, it would be better to change the assertion methods to prevent from the flaky behaviors.
Does this PR introduce any user-facing change?
No
Is the change a dependency upgrade?
No
How was this patch tested?
Test Environment:
Set up the NonDex engine:
Run the unit test using NonDex with the following command.
Please let me know if you have any concerns.