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

com.lyncode.jtwig.functions.util.CastMatcher Maven / Gradle / Ivy

The newest version!
package com.lyncode.jtwig.functions.util;

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

public class CastMatcher extends BaseMatcher {
    private final Class typeClass;
    private final Matcher matcher;

    public CastMatcher(Class typeClass, Matcher matcher) {
        this.typeClass = typeClass;
        this.matcher = matcher;
    }

    @Override
    public boolean matches(Object item) {
        if (typeClass.isInstance(item))
            return matcher.matches(item);
        else
            return false;
    }

    @Override
    public void describeTo(Description description) {
        description.appendDescriptionOf(matcher);
    }
}