Top Description Fields Constructors Methods
org.hamcrest.text

public Class IsEqualCompressingWhiteSpace

extends TypeSafeMatcher<String>
Class Inheritance
Imports
org.hamcrest.Description, .Matcher, .TypeSafeMatcher

Tests if a string is equal to another string, compressing any changes in whitespace.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
describeMismatchSafely(String item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static Matcher<String>
equalToCompressingWhiteSpace(String
the expected value of matched strings
expectedString
)

Creates a matcher of String that matches when the examined string is equal to the specified expectedString, when whitespace differences are (mostly) ignored.

public static Matcher<String>
equalToIgnoringWhiteSpace(String
the expected value of matched strings
expectedString
)

public boolean
matchesSafely(String item)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this.
public String
stripSpaces(String toBeStripped)

Inherited from org.hamcrest.TypeSafeMatcher:
describeMismatchmatches

Field Detail

stringback to summary
private final String string

Constructor Detail

IsEqualCompressingWhiteSpaceback to summary
public IsEqualCompressingWhiteSpace(String string)

Method Detail

describeMismatchSafelyback to summary
public void describeMismatchSafely(String item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
equalToCompressingWhiteSpaceback to summary
public static Matcher<String> equalToCompressingWhiteSpace(String expectedString)

Creates a matcher of String that matches when the examined string is equal to the specified expectedString, when whitespace differences are (mostly) ignored. To be exact, the following whitespace rules are applied:

  • all leading and trailing whitespace of both the expectedString and the examined string are ignored
  • any remaining whitespace, appearing within either string, is collapsed to a single space before comparison
For example:
assertThat("   my\tfoo  bar ", equalToCompressingWhiteSpace(" my  foo bar"))
Parameters
expectedString:String

the expected value of matched strings

equalToIgnoringWhiteSpaceback to summary
public static Matcher<String> equalToIgnoringWhiteSpace(String expectedString)
Parameters
expectedString:String

the expected value of matched strings

matchesSafelyback to summary
public boolean matchesSafely(String item)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
stripSpacesback to summary
public String stripSpaces(String toBeStripped)