SupplyFromProviderURIOrNodesProperty implements Supplier<InputStream>, Function<URI, InputStream> { @Override public InputStream get() { if (nodes != null) return Strings2.toInputStream(nodes); return apply(url.get()); } @VisibleForTesting  SupplyFromProviderURIOrNodesProperty(URI url); @Inject  SupplyFromProviderURIOrNodesProperty(@Provider Supplier<URI> url); @Override InputStream get(); @Override String toString(); @Override InputStream apply(URI input);  }
@Test public void testFromURI() throws Exception { String path = getClass().getResource("/test1.yaml").getPath(); SupplyFromProviderURIOrNodesProperty supplier = new SupplyFromProviderURIOrNodesProperty(URI.create("file: + path)); assertEquals(Strings2.toStringAndClose(supplier.get()), Strings2.toStringAndClose(getClass().getResourceAsStream( "/test1.yaml"))); }
@Test public void testFromURIClasspath() throws Exception { SupplyFromProviderURIOrNodesProperty supplier = new SupplyFromProviderURIOrNodesProperty(URI .create("classpath: assertEquals(Strings2.toStringAndClose(supplier.get()), Strings2.toStringAndClose(getClass().getResourceAsStream( "/test1.yaml"))); }
@Test public void testFromProperty() throws Exception { SupplyFromProviderURIOrNodesProperty supplier = new SupplyFromProviderURIOrNodesProperty(URI.create("file: supplier.nodes = Strings2.toStringAndClose(getClass().getResourceAsStream("/test1.yaml")); assertEquals(Strings2.toStringAndClose(supplier.get()), Strings2.toStringAndClose(getClass().getResourceAsStream( "/test1.yaml"))); }
@Test public void testSupplyMultipleTimes() throws Exception { String path = getClass().getResource("/test1.yaml").getPath(); SupplyFromProviderURIOrNodesProperty supplier = new SupplyFromProviderURIOrNodesProperty(URI.create("file: + path)); for (int i = 0; i < 5; i++) assertEquals(Strings2.toStringAndClose(supplier.get()), Strings2.toStringAndClose(getClass() .getResourceAsStream("/test1.yaml"))); }