Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3052 Copy JsonHelper from Search 5
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
util/internal/test/src/main/java/org/hibernate/search/util/impl/test/JsonHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} | ||
} |