// =====================================================================
// Create Mocks
// =====================================================================
final Matcher alocal = new SimpleMatcherMock("alocal", expectations);
final Matcher asequence = new MatcherMock("asequence", expectations);
final Matcher blocal = new SimpleMatcherMock("blocal", expectations);
final Matcher bsequence = new MatcherMock("bsequence", expectations);
final Matcher clocal = new SimpleMatcherMock("clocal", expectations);
final Matcher csequence = new MatcherMock("csequence", expectations);
final Matcher b_cMatcher = new MatcherMock(
"b_cMatcher", expectations);
final Matcher a_bcMatcher = new MatcherMock(
"a_bcMatcher", expectations);
// =====================================================================
// Set Expectations
// =====================================================================
// The different parts of the "b c" selector can be created in any
// order but that must be before the composite matcher is created.
final Expectations bcParts = new UnorderedExpectations() {
public void add() {
expectTypeSelectorWithDefaultNamespace("b", blocal, bsequence);
expectTypeSelectorWithDefaultNamespace("c", clocal, csequence);
}
};
final Expectations bcComposite = new OrderedExpectations() {
public void add() {
add(bcParts);
factoryMock.expects.createCompositeMatcher(bsequence, csequence,
Operator.DESCENDANT, matcherBuilderContextMock)
.returns(b_cMatcher);
}
};
// The different parts of the "a > (b c)" selector can be created in
// any order but that must be before the composite matcher is created.
final Expectations a_bcParts = new UnorderedExpectations() {
public void add() {
add(bcComposite);
expectTypeSelectorWithDefaultNamespace("a", alocal, asequence);
}
};
final Expectations a_bcComposite = new OrderedExpectations() {
public void add() {
add(a_bcParts);
factoryMock.expects.createCompositeMatcher(
asequence, b_cMatcher, Operator.CHILD,
matcherBuilderContextMock)
.returns(a_bcMatcher);
}
};
expectations.add(a_bcComposite);
specificityCalculatorMock.expects.addElementSelector();
specificityCalculatorMock.expects.addElementSelector();
specificityCalculatorMock.expects.addElementSelector();
// =====================================================================
// Test Expectations
// =====================================================================
// CSS: b c
CombinedSelector themeSelector;
themeSelector = createCombinedSelector(
createSelectorSequence("b"),
CombinatorEnum.DESCENDANT,
createSelectorSequence("c"));
// CSS: a > b c
themeSelector = createCombinedSelector(
createSelectorSequence("a"),
CombinatorEnum.CHILD,
themeSelector);
MatcherBuilder builder = createMatcherBuilder();
Matcher matcher = builder.getMatcher(themeSelector);
assertSame("Constructed matcher not as expected",
a_bcMatcher, matcher);
}