### Question:
HighestPrecedenceFilter implements ACITupleFilter { @Override public Collection<ACITuple> filter( AciContext aciContext, OperationScope scope, Entry userEntry ) throws LdapException { ACI_LOG.debug( "Filtering HighestPrecedence..." ); if ( aciContext.getAciTuples().size() <= 1 ) { ACI_LOG.debug( "HighestPrecedence : nothing to do" ); return aciContext.getAciTuples(); } int maxPrecedence = -1; for ( ACITuple tuple : aciContext.getAciTuples() ) { if ( ( tuple.getPrecedence() != null ) && ( tuple.getPrecedence() > maxPrecedence ) ) { maxPrecedence = tuple.getPrecedence(); } } for ( Iterator<ACITuple> i = aciContext.getAciTuples().iterator(); i.hasNext(); ) { ACITuple tuple = i.next(); if ( ( tuple.getPrecedence() != null ) && ( tuple.getPrecedence() != maxPrecedence ) ) { i.remove(); } } return aciContext.getAciTuples(); }  @Override Collection<ACITuple> filter( AciContext aciContext, OperationScope scope, Entry userEntry );  }### Answer:
@Test public void testZeroTuple() throws Exception { HighestPrecedenceFilter filter = new HighestPrecedenceFilter(); AciContext aciContext = new AciContext( null, null ); aciContext.setAciTuples( AT_EMPTY_COLLECTION ); assertEquals( 0, filter.filter( aciContext, null, null ).size() ); }
@Test public void testOneTuple() throws Exception { HighestPrecedenceFilter filter = new HighestPrecedenceFilter(); Collection<ACITuple> tuples = new ArrayList<ACITuple>(); tuples.add( new ACITuple( UC_EMPTY_COLLECTION, AuthenticationLevel.NONE, PI_EMPTY_COLLECTION, MO_EMPTY_SET, true, 10 ) ); tuples = Collections.unmodifiableCollection( tuples ); AciContext aciContext = new AciContext( null, null ); aciContext.setAciTuples( tuples ); assertEquals( tuples, filter.filter( aciContext, null, null ) ); }
@Test public void testMoreThanOneTuples() throws Exception { final int MAX_PRECEDENCE = 10; HighestPrecedenceFilter filter = new HighestPrecedenceFilter(); Collection<ACITuple> tuples = new ArrayList<ACITuple>(); tuples.add( new ACITuple( UC_EMPTY_COLLECTION, AuthenticationLevel.NONE, PI_EMPTY_COLLECTION, MO_EMPTY_SET, true, MAX_PRECEDENCE ) ); tuples.add( new ACITuple( UC_EMPTY_COLLECTION, AuthenticationLevel.NONE, PI_EMPTY_COLLECTION, MO_EMPTY_SET, true, MAX_PRECEDENCE / 2 ) ); tuples.add( new ACITuple( UC_EMPTY_COLLECTION, AuthenticationLevel.NONE, PI_EMPTY_COLLECTION, MO_EMPTY_SET, true, MAX_PRECEDENCE ) ); tuples.add( new ACITuple( UC_EMPTY_COLLECTION, AuthenticationLevel.NONE, PI_EMPTY_COLLECTION, MO_EMPTY_SET, true, MAX_PRECEDENCE / 3 ) ); AciContext aciContext = new AciContext( null, null ); aciContext.setAciTuples( tuples ); tuples = filter.filter( aciContext, null, null ); for ( ACITuple tuple : tuples ) { assertNotNull( tuple.getPrecedence() ); assertEquals( MAX_PRECEDENCE, tuple.getPrecedence().intValue() ); } }