### Question:
AuthPolicyValidatingInterceptor extends WSS4JBasicAuthValidator implements PhaseInterceptor<Message> { public void handleMessage(Message message) throws Fault { AuthorizationPolicy policy = message.get(AuthorizationPolicy.class); if (policy == null || policy.getUserName() == null || policy.getPassword() == null) { String name = null; if (policy != null) { name = policy.getUserName(); } org.apache.cxf.common.i18n.Message errorMsg = new org.apache.cxf.common.i18n.Message("NO_USER_PASSWORD", BUNDLE, name); LOG.warning(errorMsg.toString()); throw new SecurityException(errorMsg.toString()); } try { super.validate(message); } catch (Exception ex) { throw new Fault(ex); } } AuthPolicyValidatingInterceptor();  AuthPolicyValidatingInterceptor(String phase); void handleMessage(Message message); @Override void handleFault(Message arg0); @Override Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors(); @Override Set<String> getAfter(); @Override Set<String> getBefore(); @Override String getId(); @Override String getPhase();  }### Answer:
@Test public void testValidateAuthorizationPolicy() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertTrue(validator.isValidated()); }
@Test public void testInvalidUsernamePassword() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setUserName("bob"); policy.setPassword("pswd2"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); in.handleMessage(message); assertFalse(validator.isValidated()); }
@Test public void testNoUsername() throws Exception { AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor(); TestSTSTokenValidator validator = new TestSTSTokenValidator(); in.setValidator(validator); AuthorizationPolicy policy = new AuthorizationPolicy(); policy.setPassword("pswd"); Message message = new MessageImpl(); message.put(AuthorizationPolicy.class, policy); try { in.handleMessage(message); fail("Failure expected with no username"); } catch (SecurityException ex) { } }