import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.LogTester;
import org.sonar.core.platform.ExplodedPlugin;
@Rule
public LogTester logTester = new LogTester();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
private PluginClassLoader pluginClassLoader = mock(PluginClassLoader.class);
private PluginJarExploder jarExploder = mock(PluginJarExploder.class);
}
@Test
- public void load_plugins() {
+ public void load_plugins() throws IOException {
ServerPluginInfo p1 = newPluginInfo("p1");
ServerPluginInfo p2 = newPluginInfo("p2");
when(jarLoader.loadPlugins()).thenReturn(Arrays.asList(p1, p2));
.allMatch(p -> logTester.logs().contains(String.format("Deploy %s / %s / %s", p.getName(), p.getVersion(), p.getImplementationBuild())));
}
- private static ServerPluginInfo newPluginInfo(String key) {
+ private ServerPluginInfo newPluginInfo(String key) throws IOException {
ServerPluginInfo pluginInfo = mock(ServerPluginInfo.class);
when(pluginInfo.getKey()).thenReturn(key);
when(pluginInfo.getType()).thenReturn(EXTERNAL);
- when(pluginInfo.getNonNullJarFile()).thenReturn(getJarFile(key));
+ when(pluginInfo.getNonNullJarFile()).thenReturn(temp.newFile(key + ".jar"));
when(pluginInfo.getName()).thenReturn(key + "_name");
Version version = mock(Version.class);
when(version.getName()).thenReturn(key + "_version");
return pluginInfo;
}
- @NotNull
- private static File getJarFile(String key) {
- File file = new File(key + ".jar");
- try {
- file.createNewFile();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return file;
- }
-
private static FileAndMd5 newFileAndMd5(File file) {
return new PluginFilesAndMd5.FileAndMd5(file);
}