All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hamcrest.text.IsEqualIgnoringCase Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
/*  Copyright (c) 2000-2006 hamcrest.org
 */
package org.hamcrest.text;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;

/**
 * Tests if a string is equal to another string, regardless of the case.
 */
public class IsEqualIgnoringCase extends TypeSafeMatcher {

    // TODO: Replace String with CharSequence to allow for easy interopability between
    //       String, StringBuffer, StringBuilder, CharBuffer, etc (joe).

    private final String string;

    public IsEqualIgnoringCase(String string) {
        if (string == null) {
            throw new IllegalArgumentException("Non-null value required by IsEqualIgnoringCase()");
        }
        this.string = string;
    }

    @Override
    public boolean matchesSafely(String item) {
        return string.equalsIgnoreCase(item);
    }

    @Override
    public void describeMismatchSafely(String item, Description mismatchDescription) {
      mismatchDescription.appendText("was ").appendText(item);
    }
    
    @Override
    public void describeTo(Description description) {
        description.appendText("equalToIgnoringCase(")
                .appendValue(string)
                .appendText(")");
    }

    /**
     * Creates a matcher of {@link String} that matches when the examined string is equal to
     * the specified expectedString, ignoring case.
     * 

* For example: *

assertThat("Foo", equalToIgnoringCase("FOO"))
* * @param expectedString * the expected value of matched strings */ @Factory public static Matcher equalToIgnoringCase(String expectedString) { return new IsEqualIgnoringCase(expectedString); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy