### Question:
EndpointPolicyImpl implements EndpointPolicy { void chooseAlternative(Message m) { Collection<Assertion> alternative = null; if (requestor) { if (engine.isEnabled()) { alternative = engine.getAlternativeSelector().selectAlternative(policy, engine, assertor, null, m); } else { alternative = Collections.emptyList(); } } else { alternative = getSupportedAlternatives(m); } if (null == alternative) { throw new PolicyException(new org.apache.cxf.common.i18n.Message("NO_ALTERNATIVE_EXC", BUNDLE)); } setChosenAlternative(alternative); } EndpointPolicyImpl();  EndpointPolicyImpl(Policy p);  EndpointPolicyImpl(EndpointInfo ei,
                              PolicyEngineImpl engine,
                              boolean requestor,
                              Assertor assertor); Policy getPolicy(); Assertor getAssertor(); EndpointPolicy updatePolicy(Policy p, Message msg); Collection<Assertion> getChosenAlternative(); Collection<Assertion> getVocabulary(Message m); Collection<Assertion> getFaultVocabulary(Message m); List<Interceptor<? extends Message>> getInterceptors(Message m); List<Interceptor<? extends Message>> getFaultInterceptors(Message m); void initialize(Message m);  }### Answer:
@Test public void testChooseAlternative() { Policy policy = new Policy(); PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); Assertor assertor = control.createMock(Assertor.class); AlternativeSelector selector = control.createMock(AlternativeSelector.class); Message m = new MessageImpl(); EndpointPolicyImpl epi = new EndpointPolicyImpl(null, engine, true, assertor); epi.setPolicy(policy); EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes(); EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(null); control.replay(); try { epi.chooseAlternative(m); fail("Expected PolicyException not thrown."); } catch (PolicyException ex) { } control.verify(); control.reset(); EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes(); EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); Collection<Assertion> alternative = new ArrayList<>(); EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(alternative); control.replay(); epi.chooseAlternative(m); Collection<Assertion> choice = epi.getChosenAlternative(); assertSame(choice, alternative); control.verify(); control.reset(); EasyMock.expect(engine.isEnabled()).andReturn(false).anyTimes(); EasyMock.expect(engine.getAlternativeSelector()).andReturn(null).anyTimes(); control.replay(); try { epi.chooseAlternative(m); } catch (Exception ex) { fail("No Exception expected: " + ex); } choice = epi.getChosenAlternative(); assertTrue("not an empty list", choice != null && choice.isEmpty()); control.verify(); }