public void reportOr() { assertStateFor("Or(?)", TWO_SUB_MATCHERS); ArgumentMatcher<?> m1 = popMatcher(); ArgumentMatcher<?> m2 = popMatcher(); reportMatcher(new Or(m1, m2)); }
private void assertStateFor(String additionalMatcherName, int subMatchersCount) { assertMatchersFoundFor(additionalMatcherName); assertIncorrectUseOfAdditionalMatchers(additionalMatcherName, subMatchersCount); }
private List<LocalizedMatcher> resetStack() { ArrayList<LocalizedMatcher> lastMatchers = new ArrayList<LocalizedMatcher>(matcherStack); reset(); return lastMatchers; }
public HandyReturnValues reportNot() { assertStateFor("Not(?)", ONE_SUB_MATCHER); Not not = new Not(popLastArgumentMatchers(ONE_SUB_MATCHER).get(0)); matcherStack.push(new LocalizedMatcher(not)); return new HandyReturnValues(); }
public HandyReturnValues reportAnd() { assertState(!matcherStack.isEmpty(), "No matchers found for And(?)."); And and = new And(popLastArgumentMatchers(2)); matcherStack.push(new LocalizedMatcher(and)); return new HandyReturnValues(); }
public List<LocalizedMatcher> pullLocalizedMatchers() { if (matcherStack.isEmpty()) { return emptyList(); } List<LocalizedMatcher> lastMatchers = resetStack(); return lastMatchers; }
private List<Matcher> popLastArgumentMatchers(int count) { assertState(!matcherStack.isEmpty(), "No matchers found."); assertState(matcherStack.size() >= count, "" + count + " matchers expected, " + matcherStack.size() + " recorded."); List<Matcher> result = new LinkedList<Matcher>(); result.addAll(matcherStack.subList(matcherStack.size() - count, matcherStack.size())); for (int i = 0; i < count; i++) { matcherStack.pop(); } return result; }
public HandyReturnValues reportAnd() { assertStateFor("And(?)", TWO_SUB_MATCHERS); And and = new And(popLastArgumentMatchers(TWO_SUB_MATCHERS)); matcherStack.push(new LocalizedMatcher(and)); return new HandyReturnValues(); }
public HandyReturnValues reportNot() { assertState(!matcherStack.isEmpty(), "No matchers found for Not(?)."); Not not = new Not(popLastArgumentMatchers(1).get(0)); matcherStack.push(new LocalizedMatcher(not)); return new HandyReturnValues(); }
public void validateState() { if (!matcherStack.isEmpty()) { List<LocalizedMatcher> lastMatchers = resetStack(); throw misplacedArgumentMatcher(lastMatchers); } }
public void reportNot() { assertStateFor("Not(?)", ONE_SUB_MATCHER); ArgumentMatcher<?> m = popMatcher(); reportMatcher(new Not(m)); }
public HandyReturnValues reportOr() { assertStateFor("Or(?)", TWO_SUB_MATCHERS); Or or = new Or(popLastArgumentMatchers(TWO_SUB_MATCHERS)); matcherStack.push(new LocalizedMatcher(or)); return new HandyReturnValues(); }
public HandyReturnValues reportOr() { assertState(!matcherStack.isEmpty(), "No matchers found."); Or or = new Or(popLastArgumentMatchers(2)); matcherStack.push(new LocalizedMatcher(or)); return new HandyReturnValues(); }
private void assertStateFor(String additionalMatcherName, int subMatchersCount) { if (matcherStack.isEmpty()) { throw reportNoSubMatchersFound(additionalMatcherName); } if (matcherStack.size() < subMatchersCount) { List<LocalizedMatcher> lastMatchers = resetStack(); throw incorrectUseOfAdditionalMatchers(additionalMatcherName, subMatchersCount, lastMatchers); } }
public void reportAnd() { assertStateFor("And(?)", TWO_SUB_MATCHERS); ArgumentMatcher<?> m1 = popMatcher(); ArgumentMatcher<?> m2 = popMatcher(); reportMatcher(new And(m1, m2)); }