### Question:
FirstAlternativeSelector extends BaseAlternativeSelector { public Collection<Assertion> selectAlternative(Policy policy, PolicyEngine engine, Assertor assertor, List<List<Assertion>> request, Message msg) { Iterator<List<Assertion>> alternatives = policy.getAlternatives(); while (alternatives.hasNext()) { List<Assertion> alternative = alternatives.next(); if (engine.supportsAlternative(alternative, assertor, msg) && this.isCompatibleWithRequest(alternative, request)) { return alternative; } } alternatives = policy.getAlternatives(); while (alternatives.hasNext()) { List<Assertion> alternative = alternatives.next(); if (engine.supportsAlternative(alternative, assertor, msg)) { return alternative; } } return null; }  Collection<Assertion> selectAlternative(Policy policy,
                                                   PolicyEngine engine,
                                                   Assertor assertor,
                                                   List<List<Assertion>> request,
                                                   Message msg);  }### Answer:
@Test public void testChooseAlternative() { AlternativeSelector selector = new FirstAlternativeSelector(); PolicyEngine engine = control.createMock(PolicyEngine.class); Assertor assertor = control.createMock(Assertor.class); Policy policy = new Policy(); ExactlyOne ea = new ExactlyOne(); All all = new All(); PolicyAssertion a1 = new TestAssertion(); all.addAssertion(a1); ea.addPolicyComponent(all); Collection<PolicyAssertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class); policy.addPolicyComponent(ea); Message m = new MessageImpl(); EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false); control.replay(); assertNull(selector.selectAlternative(policy, engine, assertor, null, m)); control.verify(); control.reset(); EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(true); control.replay(); Collection<Assertion> chosen = selector.selectAlternative(policy, engine, assertor, null, m); assertSame(1, chosen.size()); assertSame(chosen.size(), firstAlternative.size()); assertSame(chosen.iterator().next(), firstAlternative.iterator().next()); control.verify(); control.reset(); All other = new All(); other.addAssertion(a1); ea.addPolicyComponent(other); Collection<PolicyAssertion> secondAlternative = CastUtils.cast(other.getPolicyComponents(), PolicyAssertion.class); EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false); EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor, m)).andReturn(true); control.replay(); chosen = selector.selectAlternative(policy, engine, assertor, null, m); assertSame(1, chosen.size()); assertSame(chosen.size(), secondAlternative.size()); assertSame(chosen.iterator().next(), secondAlternative.iterator().next()); control.verify(); }