GuiceUtils { private static void loadUrl( @Nonnull final Binder binder, @Nonnull final Properties properties, @Nonnull final String url) { assert binder != null; assert properties != null; assert url != null; try { loadUrl(properties, url.trim()); } catch (final IOException | NamingException e) { binder.addError(e); } } private  GuiceUtils(); static void bindProperties(
            @Nonnull final Binder binder,
            @Nonnull final String primaryPropertySourceUrl,
            @Nonnull final String... secondaryPropertySourceUrls);  }
@Test public void testLoadClasspathUrl() throws IOException, NamingException { LOG.info("testLoadClasspathUrl"); final Properties props = new Properties(); try { GuiceUtils.loadUrl(props, "classpath:non-existing-test-config.properties"); Assert.fail("Did not expect this"); } catch (final IOException e) { } GuiceUtils.loadUrl(props, "classpath:" + PROPERTY_FILE_SIMPLE); Assert.assertEquals(3, props.size()); }
@Test public void testLoadJndiUrl() throws IOException, NamingException { LOG.info("testLoadJndiProperties"); final Properties props = new Properties(); GuiceUtils.loadUrl(props, "jndi:java:comp/env" + GuiceUtils.JNDI_PROPETY_PREFIX_PARAM + "speedtools"); Assert.assertEquals(4, props.size()); LOG.info("testLoadJndiProperties passed with prefix"); props.clear(); GuiceUtils.loadUrl(props, "jndi:java:comp/env"); Assert.assertEquals(6, props.size()); LOG.info("testLoadJndiProperties passed without prefix"); props.clear(); GuiceUtils.loadUrl(props, "jndi:java:comp"); Assert.assertEquals(0, props.size()); LOG.info("testLoadJndiProperties passed without properties"); }
@Test public void testLoadFileUrl() throws IOException, NamingException { LOG.info("testLoadFileProperties"); final Properties props = new Properties(); try { GuiceUtils.loadUrl(props, "file:non/existing/path/but/if/it/exists/it/is/really/weird.txt"); Assert.fail("Did not expect to find this"); } catch (final FileNotFoundException e) { } final URL url = this.getClass().getClassLoader().getResource(PROPERTY_FILE_SIMPLE); assert url != null; final String fileLocation = url.getFile(); GuiceUtils.loadUrl(props, "file:" + fileLocation); Assert.assertEquals(3, props.size()); }
@Test public void testLoadNonExistingUrl() throws IOException, NamingException { LOG.info("testLoadNonExistingUrl"); final Properties props = new Properties(); try { GuiceUtils.loadUrl(props, "bla:non/existing/protocol"); Assert.fail("Did not expect to find this"); } catch (final MalformedURLException e) { } }