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

net.thucydides.core.matchers.BeanPropertyMatcher Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package net.thucydides.core.matchers;

import org.hamcrest.Matcher;

import static net.thucydides.core.matchers.dates.BeanFields.fieldValueIn;

class BeanPropertyMatcher implements BeanFieldMatcher {
    private final String fieldName;
    private final Matcher matcher;

    protected BeanPropertyMatcher(String fieldName, Matcher matcher) {
        this.fieldName = fieldName;
        this.matcher = matcher;
    }

    @Override
    public boolean matches(final Object bean) {

        return matcher.matches(fieldValueIn(bean).forField(fieldName));
    }

    @Override
    public  Matcher getMatcher() {
        return new InstantiatedBeanMatcher(this);
    }

    @Override
    public String toString() {
        String matcherDescription = matcher.toString();
        String htmlFriendlyMatcherDescription = matcherDescription.replaceAll("\"", "'");
        return fieldName + " " + htmlFriendlyMatcherDescription;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy