HibernateCORSValidator implements ICORSValidator { @Override public boolean isValidCORSOrigin(final URI origin) { try { return validDomains.get(origin); } catch (ExecutionException ee) { return false; } } @Inject  HibernateCORSValidator(final HibernateCORSCacheLoader cacheLoader); @Override boolean isValidCORSOrigin(final URI origin);  }
@Test public void loadValid() throws Exception { HibernateCORSCacheLoader loader = Mockito.mock(HibernateCORSCacheLoader.class); Mockito.doReturn(true) .when(loader) .load(Matchers.any(URI.class)); HibernateCORSValidator validator = new HibernateCORSValidator(loader); URI uri = new URI("http: Boolean response1 = validator.isValidCORSOrigin(uri); validator.isValidCORSOrigin(uri); assertTrue(response1); Mockito.verify(loader, Mockito.times(1)) .load(Matchers.any(URI.class)); }
@Test public void loadValidWithException() throws Exception { HibernateCORSCacheLoader loader = Mockito.mock(HibernateCORSCacheLoader.class); Mockito.doThrow(ExecutionException.class) .when(loader) .load(Matchers.any(URI.class)); HibernateCORSValidator validator = new HibernateCORSValidator(loader); URI uri = new URI("http: Boolean response1 = validator.isValidCORSOrigin(uri); validator.isValidCORSOrigin(uri); assertFalse(response1); Mockito.verify(loader, Mockito.times(2)) .load(Matchers.any(URI.class)); }