/** Test rules and clear methods */
@Test
public void testClear()
{
// set up which should match every rule
RegexRules rules = new RegexRules( new RegexMatcher()
{
@Override
public boolean match( String pathPattern, String rulePattern )
{
return true;
}
} );
rules.add( "/abba", new TestRule( "alpha" ) );
rules.add( "/ad/ma", new TestRule( "beta" ) );
rules.add( "/gamma", new TestRule( "gamma" ) );
// check that rules returns all rules in the order which they were added
List<Rule> matches = rules.rules();
assertEquals( "Wrong number of rules returned (1)", 3, matches.size() );
assertEquals( "Rule Out Of Order (1)", "alpha", ( (TestRule) matches.get( 0 ) ).getIdentifier() );
assertEquals( "Rule Out Of Order (2)", "beta", ( (TestRule) matches.get( 1 ) ).getIdentifier() );
assertEquals( "Rule Out Of Order (3)", "gamma", ( (TestRule) matches.get( 2 ) ).getIdentifier() );
matches = rules.match( "", "/eggs", null, null );
assertEquals( "Wrong number of rules returned (2)", 3, matches.size() );
assertEquals( "Rule Out Of Order (4)", "alpha", ( (TestRule) matches.get( 0 ) ).getIdentifier() );
assertEquals( "Rule Out Of Order (5)", "beta", ( (TestRule) matches.get( 1 ) ).getIdentifier() );
assertEquals( "Rule Out Of Order (6)", "gamma", ( (TestRule) matches.get( 2 ) ).getIdentifier() );
rules.clear();
matches = rules.rules();
assertEquals( "Wrong number of rules returned (3)", 0, matches.size() );
matches = rules.match( "", "/eggs", null, null );
assertEquals( "Wrong number of rules returned (4)", 0, matches.size() );
}