### Question:
PackageScanner { public static List<String> getClassNames(final String basePackage, ClassLoader classLoader) throws IOException, URISyntaxException { String baseFolderResource = basePackage.replace('.', '/'); final List<String> classNames = new ArrayList<>(); Enumeration<URL> resources = classLoader.getResources(baseFolderResource); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); URI uri = resource.toURI(); List<String> result; if (uri.getScheme().equals("jar")) { synchronized (PackageScanner.class) { try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap())) { final Path basePath = fileSystem.getPath(baseFolderResource).toAbsolutePath(); result = listClassNames(basePackage, basePath); } } } else { result = listClassNames(basePackage, Paths.get(uri)); } classNames.addAll(result); } return classNames; }  static List<String> getClassNames(final String basePackage, ClassLoader classLoader);  }### Answer:
@Test void getClassNames() throws Exception { assertThat(PackageScanner.getClassNames(getClass().getPackageName(), ElasticApmAgent.getAgentClassLoader())) .contains(PackageScanner.class.getName()); }
@Test void testScanJar() throws Exception { assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName(), ElasticApmAgent.getAgentClassLoader())) .contains(ByteBuddy.class.getName()); assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName(), ElasticApmAgent.getAgentClassLoader())) .contains(ByteBuddy.class.getName()); }
@Test void getClassNamesOfNonExistentPackage() throws Exception { assertThat(PackageScanner.getClassNames("foo.bar", ElasticApmAgent.getAgentClassLoader())).isEmpty(); }