DuracloudCredentialsCoherenceCheckerValidator implements
    ConstraintValidator<DuracloudCredentialsCoherenceChecker, DuracloudCredentialsForm> { @Override public boolean isValid(DuracloudCredentialsForm value, ConstraintValidatorContext context) { try { ContentStore cs = contentStoreFactory.create(value); return cs != null; } catch (ContentStoreException ex) { log.warn("invalid credentials: " + ex.getMessage(), ex); return false; } } @Autowired  DuracloudCredentialsCoherenceCheckerValidator(
        ContentStoreFactory contentStoreFactory); @Override void initialize(DuracloudCredentialsCoherenceChecker constraintAnnotation); @Override boolean isValid(DuracloudCredentialsForm value,
                           ConstraintValidatorContext context);  }
@Test public void testIsValid() throws Exception { ContentStoreFactory f = EasyMock.createMock(ContentStoreFactory.class); DuracloudCredentialsForm credentials = new DuracloudCredentialsForm(); ContentStore contentStore = EasyMock.createMock(ContentStore.class); EasyMock.expect(f.create(credentials)).andReturn(contentStore); EasyMock.replay(f, contentStore); DuracloudCredentialsCoherenceCheckerValidator v = new DuracloudCredentialsCoherenceCheckerValidator(f); Assert.assertTrue(v.isValid(credentials, null)); EasyMock.verify(f, contentStore); }
@Test public void testIsInvalid() throws Exception { ContentStoreFactory f = EasyMock.createMock(ContentStoreFactory.class); DuracloudCredentialsForm credentials = new DuracloudCredentialsForm(); EasyMock.expect(f.create(credentials)).andThrow(new ContentStoreException("test exception")); EasyMock.replay(f); DuracloudCredentialsCoherenceCheckerValidator v = new DuracloudCredentialsCoherenceCheckerValidator(f); Assert.assertFalse(v.isValid(credentials, null)); EasyMock.verify(f); }