diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2022-12-29 11:36:56 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-12-30 20:02:50 +0000 |
commit | 32ff596c042f0d95ad1b2a575a3867fd6fc775c9 (patch) | |
tree | 9875ab007b7ac85113eb7a31032aed570cd0d09b /server/sonar-webserver-api/src/test | |
parent | db1874af5166749a7259d1f26b6e646ce9db3502 (diff) | |
download | sonarqube-32ff596c042f0d95ad1b2a575a3867fd6fc775c9.tar.gz sonarqube-32ff596c042f0d95ad1b2a575a3867fd6fc775c9.zip |
[NO-JIRA] Unit test should generate jars in temporary folder
Diffstat (limited to 'server/sonar-webserver-api/src/test')
-rw-r--r-- | server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java index 4164eb7c373..bc2aaabb139 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java @@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull; 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; @@ -48,6 +49,8 @@ public class ServerPluginManagerTest { @Rule public LogTester logTester = new LogTester(); + @Rule + public TemporaryFolder temp = new TemporaryFolder(); private PluginClassLoader pluginClassLoader = mock(PluginClassLoader.class); private PluginJarExploder jarExploder = mock(PluginJarExploder.class); @@ -61,7 +64,7 @@ public class ServerPluginManagerTest { } @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)); @@ -89,11 +92,11 @@ public class ServerPluginManagerTest { .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"); @@ -102,17 +105,6 @@ public class ServerPluginManagerTest { 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); } |