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

org.hamcrest.MatcherAssert Maven / Gradle / Ivy

Go to download

This is the core API of hamcrest matcher framework to be used by third-party framework providers. This includes the a foundation set of matcher implementations for common operations.

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


public class MatcherAssert {
    public static  void assertThat(T actual, Matcher matcher) {
        assertThat("", actual, matcher);
    }
    
    public static  void assertThat(String reason, T actual, Matcher matcher) {
        if (!matcher.matches(actual)) {
            Description description = new StringDescription();
            description.appendText(reason)
                       .appendText("\nExpected: ")
                       .appendDescriptionOf(matcher)
                       .appendText("\n     but: ");
            matcher.describeMismatch(actual, description);
            
            throw new AssertionError(description.toString());
        }
    }
    
    public static void assertThat(String reason, boolean assertion) {
        if (!assertion) {
            throw new AssertionError(reason);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy