com.github.dreamhead.moco.matcher.MatchMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-core Show documentation
Show all versions of moco-core Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
package com.github.dreamhead.moco.matcher;
import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.RequestExtractor;
import com.github.dreamhead.moco.RequestMatcher;
import com.github.dreamhead.moco.resource.Resource;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import java.util.regex.Pattern;
public class MatchMatcher extends AbstractOperatorMatcher {
public MatchMatcher(final RequestExtractor extractor, final Resource expected) {
super(extractor, expected, new Predicate() {
@Override
public boolean apply(final String input) {
Pattern pattern = Pattern.compile(expected.readFor(Optional.absent()).toString());
return pattern.matcher(input).matches();
}
});
}
@Override
protected RequestMatcher newMatcher(final RequestExtractor extractor, final Resource resource) {
return new MatchMatcher(extractor, resource);
}
}