Skip to content

Commit

Permalink
fixup: Reuse DelegatingClassLoaderTest as parameterized PluginScanner…
Browse files Browse the repository at this point in the history
…Test

Signed-off-by: Greg Harris <greg.harris@aiven.io>
  • Loading branch information
gharris1727 committed Jul 5, 2023
1 parent b9e7ffa commit af3ed97
Showing 1 changed file with 33 additions and 2 deletions.
Expand Up @@ -20,21 +20,52 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;

public class DelegatingClassLoaderTest {
@RunWith(Parameterized.class)
public class PluginScannerTest {

private enum ScannerType { Reflection, ServiceLoader };

@Rule
public TemporaryFolder pluginDir = new TemporaryFolder();

public PluginScanner scanner;

@Parameterized.Parameters
public static Collection<Object[]> parameters() {
List<Object[]> values = new ArrayList<>();
for (ScannerType type : ScannerType.values()) {
values.add(new Object[]{type});
}
return values;
}

public PluginScannerTest(ScannerType scannerType) {
switch (scannerType) {
case Reflection:
this.scanner = new ReflectionScanner();
break;
case ServiceLoader:
this.scanner = new ServiceLoaderScanner();
break;
default:
throw new IllegalArgumentException("Unknown type " + scannerType);
}
}

@Test
public void testLoadingUnloadedPluginClass() {
DelegatingClassLoader classLoader = initClassLoader(
Expand Down Expand Up @@ -115,7 +146,7 @@ private DelegatingClassLoader initClassLoader(List<Path> pluginLocations) {
ClassLoaderFactory factory = new ClassLoaderFactory();
DelegatingClassLoader classLoader = factory.newDelegatingClassLoader(DelegatingClassLoader.class.getClassLoader());
Set<PluginSource> pluginSources = PluginUtils.pluginSources(pluginLocations, classLoader, factory);
PluginScanResult scanResult = new ReflectionScanner().discoverPlugins(pluginSources);
PluginScanResult scanResult = scanner.discoverPlugins(pluginSources);
classLoader.installDiscoveredPlugins(scanResult);
return classLoader;
}
Expand Down

0 comments on commit af3ed97

Please sign in to comment.