Skip to content

Commit

Permalink
HSEARCH-3052 Copy JsonHelper from Search 5
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jan 25, 2019
1 parent 84ff47c commit fcf0570
Showing 1 changed file with 47 additions and 0 deletions.
@@ -0,0 +1,47 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.util.impl.test;

import static org.junit.Assert.fail;

import org.json.JSONException;
import org.skyscreamer.jsonassert.JSONCompare;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;

/**
* Helper functionality around JSON documents.
*
* @author Gunnar Morling
*/
public class JsonHelper {

private JsonHelper() {
}

public static void assertJsonEquals(String expectedJson, String actualJson) {
assertJsonEquals( expectedJson, actualJson, JSONCompareMode.NON_EXTENSIBLE );
}

public static void assertJsonEqualsIgnoringUnknownFields(String expectedJson, String actualJson) {
assertJsonEquals( expectedJson, actualJson, JSONCompareMode.LENIENT );
}

private static void assertJsonEquals(String expectedJson, String actualJson, JSONCompareMode mode) {
try {
JSONCompareResult result = JSONCompare.compareJSON( expectedJson, actualJson, mode );

if ( result.failed() ) {
fail( result.getMessage() + "; Actual: " + actualJson );
throw new IllegalStateException( "This should never happen" );
}
}
catch (JSONException e) {
throw new RuntimeException( e );
}
}
}

0 comments on commit fcf0570

Please sign in to comment.