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

org.cthul.matchers.hamcrest.MatchResultExpected 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.hamcrest;

import org.cthul.matchers.diagnose.result.MatchResult;
import org.cthul.matchers.diagnose.safe.TypesafeFeatureMatcher;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.SelfDescribing;

/**
 *
 */
public class MatchResultExpected extends TypesafeFeatureMatcher, SelfDescribing> {

    @Factory
    public static MatchResultExpected expectedDescription(Matcher messageMatcher) {
        return new MatchResultExpected(messageMatcher);
    }
    
    @Factory
    public static MatchResultExpected expectedMessage(Matcher messageMatcher) {
        return new MatchResultExpected(HasDescription.message(messageMatcher));
    }
    
    @Factory
    public static MatchResultExpected expectedMessage(String message) {
        return new MatchResultExpected(HasDescription.message(message));
    }
    
    @Factory
    public static  IsMatchResult expected(Matcher messageMatcher) {
        return IsMatchResult.mismatch(expectedMessage(messageMatcher));
    }
    
    @Factory
    public static  IsMatchResult expected(String message) {
        return IsMatchResult.mismatch(expectedMessage(message));
    }
    
    public MatchResultExpected(Matcher featureMatcher) {
        super(featureMatcher, "expected", "expected");
    }

    @Override
    protected SelfDescribing getFeature(MatchResult value) {
        MatchResult.Mismatch mism = value.getMismatch();
        if (mism == null) return null;
        return mism.getExpectedDescription();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy