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

org.hamcrest.core.IsAnything Maven / Gradle / Ivy

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

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


/**
 * A matcher that always returns true.
 */
public class IsAnything extends BaseMatcher {

    private final String message;

    public IsAnything() {
        this("ANYTHING");
    }

    public IsAnything(String message) {
        this.message = message;
    }

    @Override
    public boolean matches(Object o) {
        return true;
    }

    @Override
    public void describeTo(Description description) {
        description.appendText(message);
    }

    /**
     * Creates a matcher that always matches, regardless of the examined object.
     */
    @Factory
    public static Matcher anything() {
        return new IsAnything();
    }

    /**
     * Creates a matcher that always matches, regardless of the examined object, but describes
     * itself with the specified {@link String}.
     *
     * @param description
     *     a meaningful {@link String} used when describing itself
     */
    @Factory
    public static Matcher anything(String description) {
        return new IsAnything(description);
    }
}