Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2013 Shazam Entertainment Limited
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  * 
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */
package com.shazam.shazamcrest;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
Determines if the org.hamcrest.Description contains comparable Json
Throws a org.junit.ComparisonFailure if the description passed in is of type ComparisonDescription, and the mismatch has been defined as a comparison failure.

Parameters:
reason the MatcherAssert.assertThat(java.lang.String,java.lang.Object,org.hamcrest.Matcher) reason
description the org.hamcrest.Description which potentially holds the comparison failure information
Throws:
org.junit.ComparisonFailure
	static void containsComparableJson(String reasonDescription descriptionthrows ComparisonFailure {
		if (description instanceof ComparisonDescription) {
			ComparisonDescription shazamDescription = (ComparisonDescriptiondescription;
			if (shazamDescription.isComparisonFailure()) {
				throw new ComparisonFailure(
						comparisonFailureMessage(reasonshazamDescription),
						shazamDescription.getExpected(),
						shazamDescription.getActual()
				);
			}
		}
	}
	private static String comparisonFailureMessage(String reasonComparisonDescription shazamDescription) {
		return (isNotBlank(reason) ? reason + "\n" : "") + shazamDescription.getDifferencesMessage();
	}
New to GrepCode? Check out our FAQ X