test_class.file: bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java
test_class.identifier: ResourceBundleClassLoaderTest
test_case.body: @Test
      public void testName() throws Exception {
          Path tmp = Files.createTempDirectory("tmp");
          URL hostPropertiesURL = createTmpTestPropetiesFile(tmp, "host/OH-INF/i18n/test.properties");
          URL fragmentPropertiesURL = createTmpTestPropetiesFile(tmp, "fragment/OH-INF/i18n/test.properties");
  
          Bundle bundleMock = mock(Bundle.class);
          when(bundleMock.findEntries(any(), any(), anyBoolean()))
                  .thenAnswer(answer -> Collections.enumeration(List.of(hostPropertiesURL, fragmentPropertiesURL)));
          when(bundleMock.getEntry(any())).thenReturn(hostPropertiesURL);
  
          ResourceBundleClassLoader classloader = new ResourceBundleClassLoader(bundleMock, "/OH-INF/i18n",
                  "*.properties");
  
          List<URL> propertiesURLs = Collections.list(bundleMock.findEntries("/OH-INF/i18n", "*.properties", true));
  
          assertEquals(2, propertiesURLs.size());
          assertTrue(propertiesURLs.contains(hostPropertiesURL));
          assertTrue(propertiesURLs.contains(fragmentPropertiesURL));
  
          assertEquals(hostPropertiesURL, bundleMock.getEntry(null));
          assertEquals(hostPropertiesURL, bundleMock.getEntry("always-return-hostPropertiesURL"));
  
          URL resource = classloader.getResource("test.properties");
          assertEquals(fragmentPropertiesURL, resource);
      }
test_case.class_method_signature: ResourceBundleClassLoaderTest.testName()
test_case.full_signature: @Test public void testName()
test_case.identifier: testName
test_case.invocations: createTempDirectory createTmpTestPropetiesFile createTmpTestPropetiesFile mock thenAnswer when findEntries any any anyBoolean enumeration of thenReturn when getEntry any list findEntries assertEquals size assertTrue contains assertTrue contains assertEquals getEntry assertEquals getEntry getResource assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testName()
focal_class.declarator: bundle
focal_class.modifier: private
focal_class.original_string: private Bundle bundle;
focal_class.type: Bundle
focal_class.var_name: bundle
focal_class.declarator: path
focal_class.modifier: private
focal_class.original_string: private String path;
focal_class.type: String
focal_class.var_name: path
focal_class.declarator: filePattern
focal_class.modifier: private
focal_class.original_string: private String filePattern;
focal_class.type: String
focal_class.var_name: filePattern
focal_class.file: bundles/org.openhab.core/src/main/java/org/openhab/core/common/osgi/ResourceBundleClassLoader.java
focal_class.identifier: ResourceBundleClassLoader
focal_class.class_method_signature: ResourceBundleClassLoader.ResourceBundleClassLoader(Bundle bundle, String path, String filePattern)
focal_class.full_signature: public  ResourceBundleClassLoader(Bundle bundle, String path, String filePattern)
focal_class.identifier: ResourceBundleClassLoader
focal_class.modifiers: public
focal_class.parameters: (Bundle bundle, String path, String filePattern)
focal_class.signature:  ResourceBundleClassLoader(Bundle bundle, String path, String filePattern)
focal_class.class_method_signature: ResourceBundleClassLoader.getResource(String name)
focal_class.full_signature: @Override public URL getResource(String name)
focal_class.identifier: getResource
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: URL
focal_class.signature: URL getResource(String name)
focal_class.class_method_signature: ResourceBundleClassLoader.getResourceAsStream(String name)
focal_class.full_signature: @Override public InputStream getResourceAsStream(String name)
focal_class.identifier: getResourceAsStream
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: InputStream
focal_class.signature: InputStream getResourceAsStream(String name)
focal_class.superclass: extends ClassLoader
focal_method.body: @Override
      public URL getResource(String name) {
          Enumeration<URL> resourceFiles = this.bundle.findEntries(this.path, this.filePattern, true);
  
          List<URL> allResources = new LinkedList<>();
          if (resourceFiles != null) {
              while (resourceFiles.hasMoreElements()) {
                  URL resourceURL = resourceFiles.nextElement();
                  String resourcePath = resourceURL.getFile();
                  File resourceFile = new File(resourcePath);
                  String resourceFileName = resourceFile.getName();
  
                  if (resourceFileName.equals(name)) {
                      allResources.add(resourceURL);
                  }
              }
          }
  
          if (allResources.isEmpty()) {
              return null;
          }
  
          if (allResources.size() == 1) {
              return allResources.get(0);
          }
  
          // handle fragment resources. return first one.
          for (URL url : allResources) {
              boolean isHostResource = bundle.getEntry(url.getPath()) != null
                      && bundle.getEntry(url.getPath()).equals(url);
              if (isHostResource) {
                  continue;
              }
              return url;
          }
  
          return null;
      }
focal_method.class_method_signature: ResourceBundleClassLoader.getResource(String name)
focal_method.full_signature: @Override public URL getResource(String name)
focal_method.identifier: getResource
focal_method.invocations: findEntries hasMoreElements nextElement getFile getName equals add isEmpty size get getEntry getPath equals getEntry getPath
focal_method.modifiers: @Override public
focal_method.parameters: (String name)
focal_method.return: URL
focal_method.signature: URL getResource(String name)