ExporterJarRepository { public ExporterJarClassLoader load(final String jarPath) throws ExporterJarLoadException { return load(Paths.get(jarPath)); } ExporterJarRepository();  ExporterJarRepository(final Map<Path, ExporterJarClassLoader> loadedJars); Map<Path, ExporterJarClassLoader> getJars(); ExporterJarClassLoader remove(final String jarPath); ExporterJarClassLoader remove(final Path jarPath); ExporterJarClassLoader load(final String jarPath); ExporterJarClassLoader load(final Path jarPath); static final String JAR_EXTENSION; }
@Test public void shouldThrowExceptionOnLoadIfNotAJar() throws IOException { final File fake = temporaryFolder.newFile("fake-file"); assertThatThrownBy(() -> jarRepository.load(fake.getAbsolutePath())) .isInstanceOf(ExporterJarLoadException.class); }
@Test @Ignore public void shouldThrowExceptionOnLoadIfNotReadable() throws Exception { final File dummy = temporaryFolder.newFile("unreadable.jar"); assumeTrue(dummy.setReadable(false)); assertThatThrownBy(() -> jarRepository.load(dummy.getAbsolutePath())) .isInstanceOf(ExporterJarLoadException.class); }
@Test public void shouldThrowExceptionIfJarMissing() throws IOException { final File dummy = temporaryFolder.newFile("missing.jar"); FileUtil.deleteFile(dummy); assertThatThrownBy(() -> jarRepository.load(dummy.getAbsolutePath())) .isInstanceOf(ExporterJarLoadException.class); }
@Test public void shouldLoadClassLoaderForJar() throws IOException { final File dummy = temporaryFolder.newFile("readable.jar"); assumeTrue(dummy.setReadable(true)); assertThat(jarRepository.load(dummy.getAbsolutePath())) .isInstanceOf(ExporterJarClassLoader.class); }
@Test public void shouldLoadClassLoaderCorrectlyOnlyOnce() throws Exception { final Class exportedClass = TestJarExporter.class; final File jarFile = jarCreator.create(exportedClass); final ExporterJarClassLoader classLoader = jarRepository.load(jarFile.toPath()); assertThat(classLoader.loadClass(exportedClass.getCanonicalName())).isNotEqualTo(exportedClass); assertThat(jarRepository.load(jarFile.toPath())).isEqualTo(classLoader); }