Resources { @Pure public static URL getResource(String path) { try { final Class<?> type = Caller.getCallerClass(1); if (type != null) { return getResource(type, path); } } catch (Throwable exception) { } return getResource((ClassLoader) null, path); } private  Resources(); @Pure static URL getResource(String path); @Pure @Deprecated(since = "17.0") static URL getResource(ClassLoader classLoader, Package packagename, String path); @Pure static URL getResource(Class<?> classname, String path); @Pure @Deprecated(since = "17.0") static URL getResource(ClassLoader classLoader, String path); @Pure static InputStream getResourceAsStream(String path); @Pure @Deprecated(since = "17.0") static InputStream getResourceAsStream(ClassLoader classLoader, Package packagename, String path); @Pure static InputStream getResourceAsStream(Class<?> classname, String path); @Pure @Deprecated(since = "17.0") static InputStream getResourceAsStream(ClassLoader classLoader, String path); @Pure static URL getPropertyFile(Class<?> classname, Locale locale); @Pure @Deprecated(since = "17.0") static URL getPropertyFile(ClassLoader classLoader, Class<?> classname, Locale locale); @Pure static String translateResourceName(String resourceName); static final String NAME_SEPARATOR; }
@Test public void getResourceString() { assertNull(Resources.getResource(null)); URL u1 = Resources.getResource(TEST_NAME_1); assertNotNull(u1); URL u2 = Resources.getResource(TEST_NAME_2); assertNotNull(u2); assertEquals(u1,u2); }
@Test public void getResourceClassString() { assertNull(Resources.getResource(ResourcesTest.class, null)); URL u1 = Resources.getResource(ResourcesTest.class, TEST_NAME_1); assertNotNull(u1); URL u2 = Resources.getResource(ResourcesTest.class, TEST_NAME_2); assertNotNull(u2); URL u3 = Resources.getResource(ResourcesTest.class, TEST_NAME_3); assertNotNull(u3); assertEquals(u1,u2); assertEquals(u1,u3); assertNull(Resources.getResource((Class<?>)null, null)); u1 = Resources.getResource((Class<?>)null, TEST_NAME_1); assertNull(u1); u2 = Resources.getResource((Class<?>)null, TEST_NAME_2); assertNull(u2); }