}
public Occurrences add(ThreadMatcher matcher, Expectations expectations) {
ExpectationBuilder builder = null;
synchronized (this) {
for (int i = 0; i < outstandingBindings.size(); i++) {
ThreadBinder binder = (ThreadBinder) outstandingBindings.get(i);
if (binder.matcher == matcher) {
builder = binder.builder;
}
}
}
if (builder == null) {
throw new IllegalStateException(
"Could not find builder that is bound to " + matcher);
}
ExpectationBuilder oldBuilder = currentBuilder;
this.currentBuilder = builder;
try {
return super.add(expectations);
} finally {
this.currentBuilder = oldBuilder;