Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook to skip asserting x-content equivalence #33114

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.test;

import org.elasticsearch.common.Strings;
Expand All @@ -34,9 +35,17 @@ public abstract class AbstractSerializingTestCase<T extends ToXContent & Writeab
* both for equality and asserts equality on the two instances.
*/
public final void testFromXContent() throws IOException {
AbstractXContentTestCase.testFromXContent(NUMBER_OF_TEST_RUNS, this::createTestInstance, supportsUnknownFields(),
getShuffleFieldsExceptions(), getRandomFieldsExcludeFilter(), this::createParser, this::doParseInstance,
this::assertEqualInstances, true, getToXContentParams());
AbstractXContentTestCase.testFromXContent(
NUMBER_OF_TEST_RUNS,
this::createTestInstance,
supportsUnknownFields(),
getShuffleFieldsExceptions(),
getRandomFieldsExcludeFilter(),
this::createParser,
this::doParseInstance,
this::assertEqualInstances,
assertToXContentEquivalence(),
Copy link
Member Author

@jasontedor jasontedor Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key change, from true to use the assertToXContentEquivalence hook. This is why I like long parameter lists on a single line per parameter. 😇

Were this method already formatted on a single line per parameter, the diff would have made this change obvious:

diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractSerializingTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractSerializingTestCase.java
index 7e945a8414c..5aeb30bfdbd 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/AbstractSerializingTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractSerializingTestCase.java
@@ -44,7 +44,7 @@ public abstract class AbstractSerializingTestCase<T extends ToXContent & Writeab
                 this::createParser,
                 this::doParseInstance,
                 this::assertEqualInstances,
-                true,
+                assertToXContentEquivalence(),
                 getToXContentParams());
     }
 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

getToXContentParams());
}

/**
Expand Down Expand Up @@ -72,4 +81,15 @@ protected String[] getShuffleFieldsExceptions() {
protected ToXContent.Params getToXContentParams() {
return ToXContent.EMPTY_PARAMS;
}

/**
* Whether or not to assert equivalence of the {@link org.elasticsearch.common.xcontent.XContent} of the test instance and the instance
* parsed from the {@link org.elasticsearch.common.xcontent.XContent} of the test instance.
*
* @return true if equivalence should be asserted, otherwise false
*/
protected boolean assertToXContentEquivalence() {
return true;
}

}