diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-12-09 09:25:24 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-12-09 09:25:43 +0100 |
commit | 16f22400073acae3ee9b9936835c88d25982a035 (patch) | |
tree | dc96e86e1d5117cac83b10cc1d91fbe4723f3f0b /sonar-home/src/test | |
parent | 229663fac9e16f2be5c5be5c36e17aecf7a5efa7 (diff) | |
download | sonarqube-16f22400073acae3ee9b9936835c88d25982a035.tar.gz sonarqube-16f22400073acae3ee9b9936835c88d25982a035.zip |
Improve UT coverage
Diffstat (limited to 'sonar-home/src/test')
-rw-r--r-- | sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java index 3bbc97c0fc4..bc083e6d81d 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java @@ -28,6 +28,7 @@ import org.sonar.home.log.Slf4jLog; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -118,4 +119,29 @@ public class FileCacheTest { assertThat(cachedFile.getParentFile().getParentFile()).isEqualTo(cache.getDir()); assertThat(FileUtils.readFileToString(cachedFile)).contains("downloaded by"); } + + @Test + public void unzip_from_cache() throws IOException, URISyntaxException { + final File samplePlugin = new File(this.getClass().getResource("/sonar-checkstyle-plugin-2.8.jar").toURI()); + FileHashes hashes = mock(FileHashes.class); + FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes); + when(hashes.of(any(File.class))).thenReturn("ABCDE"); + + FileCache.Downloader downloader = new FileCache.Downloader() { + public void download(String filename, File toFile) throws IOException { + FileUtils.copyFile(samplePlugin, toFile); + } + }; + File cachedFile = cache.get("sonar-checkstyle-plugin-2.8.jar", "ABCDE", downloader); + assertThat(cachedFile).isNotNull().exists().isFile(); + assertThat(cachedFile.getName()).isEqualTo("sonar-checkstyle-plugin-2.8.jar"); + + File pluginDepsDir = cache.unzip(cachedFile); + assertThat(pluginDepsDir.listFiles()).hasSize(1); + File metaDir = new File(pluginDepsDir, "META-INF"); + assertThat(metaDir.listFiles()).hasSize(1); + File libDir = new File(metaDir, "lib"); + assertThat(libDir.listFiles()).hasSize(3); + assertThat(libDir.listFiles()).containsOnly(new File(libDir, "antlr-2.7.6.jar"), new File(libDir, "checkstyle-5.1.jar"), new File(libDir, "commons-cli-1.0.jar")); + } } |