### Question:
EndpointPolicyImpl implements EndpointPolicy { public EndpointPolicy updatePolicy(Policy p, Message msg) { EndpointPolicyImpl epi = createEndpointPolicy(); if (!PolicyUtils.isEmptyPolicy(p)) { Policy normalizedPolicy = p.normalize(engine == null ? null : engine.getRegistry(), true); epi.setPolicy(getPolicy().merge(normalizedPolicy)); } else { Policy clonedPolicy = new Policy(); clonedPolicy.addPolicyComponents(getPolicy().getPolicyComponents()); epi.setPolicy(clonedPolicy); } epi.checkExactlyOnes(); epi.finalizeConfig(msg); return epi; } 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 testUpdatePolicy() { EndpointPolicyImpl epi = new TestEndpointPolicy(); Policy p1 = new Policy(); QName aqn1 = new QName("http: p1.addAssertion(mockAssertion(aqn1, 5, true)); Policy p2 = new Policy(); QName aqn2 = new QName("http: p2.addAssertion(mockAssertion(aqn2, 5, true)); control.replay(); epi.setPolicy(p1.normalize(null, true)); Policy ep = epi.updatePolicy(p2, createMessage()).getPolicy(); List<ExactlyOne> pops = CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class); assertEquals("New policy must have 1 top level policy operator", 1, pops.size()); List<All> alts = CastUtils.cast(pops.get(0).getPolicyComponents(), All.class); assertEquals("2 alternatives should be available", 2, alts.size()); List<PolicyAssertion> assertions1 = CastUtils .cast(alts.get(0).getAssertions(), PolicyAssertion.class); assertEquals("1 assertion should be available", 1, assertions1.size()); List<PolicyAssertion> assertions2 = CastUtils .cast(alts.get(1).getAssertions(), PolicyAssertion.class); assertEquals("1 assertion should be available", 1, assertions2.size()); QName n1 = assertions1.get(0).getName(); QName n2 = assertions2.get(0).getName(); assertTrue("Policy was not merged", n1.equals(aqn1) && n2.equals(aqn2) || n1.equals(aqn2) && n2.equals(aqn1)); }