MyPresentationPolicyAlternatives { public MyPresentationPolicy findOrThrow(URI policyUri) throws TokenVerificationException { for(PresentationPolicy pp: policyAlternatives.getPresentationPolicy()) { if (pp.getPolicyUID().equals(policyUri)) { return new MyPresentationPolicy(pp); } } String errorMessage = "Cannot find presentation policy with URI '" + policyUri + "' among the alternatives"; TokenVerificationException ex = new TokenVerificationException(); ex.errorMessages.add(errorMessage); throw ex; } MyPresentationPolicyAlternatives(PresentationPolicyAlternatives ppa); MyPresentationPolicy findOrThrow(URI policyUri);  }
@Test public void testFindOrThrow() throws Exception { PresentationPolicyAlternatives ppa = (PresentationPolicyAlternatives) XmlUtils.getObjectFromXML(getClass().getResourceAsStream( "/eu/abc4trust/sampleXml/presentationPolicies/presentationPolicyAlternativesHotel.xml"), true); MyPresentationPolicyAlternatives myppa = new MyPresentationPolicyAlternatives(ppa); URI policyUri1 = new URI("http: MyPresentationPolicy res = myppa.findOrThrow(policyUri1); assertEquals(policyUri1, res.getPolicyUri()); URI policyUri2 = new URI("blabla"); try { myppa.findOrThrow(policyUri2); fail("Expected TokenVerificationException"); } catch(TokenVerificationException ex) { assertTrue(ex.getMessage().contains("Cannot find")); } }