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

org.cthul.matchers.object.InstanceThat Maven / Gradle / Ivy

Go to download

Provides hamcrest.org matchers for strings and exceptions, allows matching code blocks, and provides several utilities for combining matchers.

The newest version!
package org.cthul.matchers.object;

import org.cthul.matchers.chain.AndChainMatcher;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsInstanceOf;

/**
 *
 */
public class InstanceThat {
    
    @Factory
    @SuppressWarnings("unchecked")
    public static  AndChainMatcher.Builder instanceThat(Class clazz, Matcher m) {
        return (AndChainMatcher.Builder) AndChainMatcher.both(IsInstanceOf.instanceOf(clazz), m);
    }
    
    @Factory
    @SuppressWarnings("unchecked")
    public static  AndChainMatcher.Builder instanceThat(Class clazz, Matcher... m) {
        Matcher[] matchers = new Matcher[m.length+1];
        matchers[0] = IsInstanceOf.instanceOf(clazz);
        System.arraycopy(m, 0, matchers, 1, m.length);
        return AndChainMatcher.both(matchers);
    }
    
    @Factory
    @SuppressWarnings("unchecked")
    public static  AndChainMatcher.Builder isInstanceThat(Class clazz, Matcher m) {
        return (AndChainMatcher.Builder) AndChainMatcher.both(Is.is(IsInstanceOf.instanceOf(clazz)), m);
    }
    
    @Factory
    @SuppressWarnings("unchecked")
    public static  Matcher isInstanceThat(Class clazz, Matcher... m) {
        return Is.is(InstanceThat.instanceThat(clazz, m));
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy