diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-01-26 18:24:01 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-02-02 17:27:19 +0100 |
commit | 35f1487144f72e49b73383c0e96d73b53c60c641 (patch) | |
tree | ceb208c0c3d0e631561c9807d394ca97503df1ae /sonar-plugin-api | |
parent | 7a15c4d1064bbda06a204427bc71a26d9091647a (diff) | |
download | sonarqube-35f1487144f72e49b73383c0e96d73b53c60c641.tar.gz sonarqube-35f1487144f72e49b73383c0e96d73b53c60c641.zip |
Use protocol buffers format for analysis reports
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java index f60e7fb8f53..5ba09482ff4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ZipUtilsTest.java @@ -21,7 +21,9 @@ package org.sonar.api.utils; import com.google.common.collect.Iterators; import org.apache.commons.io.FileUtils; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; @@ -34,24 +36,33 @@ import static org.assertj.core.api.Assertions.assertThat; public class ZipUtilsTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + @Test public void shouldZipDirectory() throws IOException { File foo = FileUtils.toFile(getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldZipDirectory/foo.txt")); File dir = foo.getParentFile(); - File zip = new File("target/tmp/shouldZipDirectory.zip"); + File zip = temp.newFile(); ZipUtils.zipDir(dir, zip); - assertThat(zip).exists(); + assertThat(zip).exists().isFile(); assertThat(zip.length()).isGreaterThan(1L); Iterator<? extends ZipEntry> zipEntries = Iterators.forEnumeration(new ZipFile(zip).entries()); assertThat(zipEntries).hasSize(4); + + File unzipDir = temp.newFolder(); + ZipUtils.unzip(zip, unzipDir); + assertThat(new File(unzipDir, "bar.txt")).exists().isFile(); + assertThat(new File(unzipDir, "foo.txt")).exists().isFile(); + assertThat(new File(unzipDir, "dir1/hello.properties")).exists().isFile(); } @Test public void shouldUnzipFile() throws IOException { File zip = FileUtils.toFile(getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldUnzipFile.zip")); - File toDir = new File("target/tmp/shouldUnzipFile/"); + File toDir = temp.newFolder(); ZipUtils.unzip(zip, toDir); assertThat(toDir.list()).hasSize(3); } @@ -59,7 +70,7 @@ public class ZipUtilsTest { @Test public void should_unzip_stream_file() throws Exception { InputStream zip = getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldUnzipFile.zip").openStream(); - File toDir = new File("target/tmp/shouldUnzipStreamFile/"); + File toDir = temp.newFolder(); ZipUtils.unzip(zip, toDir); assertThat(toDir.list()).hasSize(3); } |