
com.github.tomakehurst.wiremock.matching.MemoizingStringValuePattern Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wiremock Show documentation
Show all versions of wiremock Show documentation
A web service test double for all occasions
package com.github.tomakehurst.wiremock.matching;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.concurrent.ExecutionException;
import static com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked;
public abstract class MemoizingStringValuePattern extends StringValuePattern {
private final LoadingCache cache = CacheBuilder.newBuilder()
.build(new CacheLoader() {
@Override
public MatchResult load(String value) {
return new MemoizingMatchResult(calculateMatch(value));
}
});
public MemoizingStringValuePattern(String expectedValue) {
super(expectedValue);
}
@Override
public final MatchResult match(String value) {
if (value == null) {
return MatchResult.noMatch();
}
try {
return cache.get(value);
} catch (ExecutionException e) {
return throwUnchecked(e, MatchResult.class);
}
}
protected abstract MatchResult calculateMatch(String value);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy