aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2012-01-01 10:57:47 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2012-01-01 10:57:47 +0000
commite7bc097684a543d3d334b43ca04dd9b95e53b45b (patch)
tree9d13e0f4698361ab4303636f59a378f32d998087
parent309c43963dc0d834fd20e03b5cf5c3577d5d27f2 (diff)
downloadjacoco-e7bc097684a543d3d334b43ca04dd9b95e53b45b.tar.gz
Add missing test cases.
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java
index 992b9fe9..b1944a81 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java
@@ -16,7 +16,11 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -26,13 +30,18 @@ import java.util.zip.ZipOutputStream;
import org.jacoco.core.data.ExecutionDataStore;
import org.jacoco.core.test.TargetLoader;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
/**
* Unit tests for {@link Analyzer}.
*/
public class AnalyzerTest {
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
private Analyzer analyzer;
private final Set<String> classes = new HashSet<String>();
@@ -118,4 +127,48 @@ public class AnalyzerTest {
assertEquals(Collections.emptySet(), classes);
}
+ @Test
+ public void testAnalyzeAll4() throws IOException {
+ createClassfile("bin1", AnalyzerTest.class);
+ final int count = analyzer.analyzeAll(folder.getRoot());
+ assertEquals(1, count);
+ assertEquals(
+ Collections.singleton("org/jacoco/core/analysis/AnalyzerTest"),
+ classes);
+ }
+
+ @Test
+ public void testAnalyzeAll5() throws IOException {
+ createClassfile("bin1", Analyzer.class);
+ createClassfile("bin2", AnalyzerTest.class);
+ String path = "bin1" + File.pathSeparator + "bin2";
+ final int count = analyzer.analyzeAll(path, folder.getRoot());
+ assertEquals(2, count);
+ assertEquals(
+ new HashSet<String>(Arrays.asList(
+ "org/jacoco/core/analysis/Analyzer",
+ "org/jacoco/core/analysis/AnalyzerTest")), classes);
+ }
+
+ @Test(expected = IOException.class)
+ public void testAnalyzeAll6() throws IOException {
+ File file = new File(folder.getRoot(), "broken.zip");
+ OutputStream out = new FileOutputStream(file);
+ ZipOutputStream zip = new ZipOutputStream(out);
+ zip.putNextEntry(new ZipEntry("brokenentry.txt"));
+ out.write(0x23); // Unexpected data here
+ zip.close();
+ analyzer.analyzeAll(file);
+ }
+
+ private void createClassfile(final String dir, final Class<?> source)
+ throws IOException {
+ File file = new File(folder.getRoot(), dir);
+ file.mkdirs();
+ file = new File(file, "some.class");
+ OutputStream out = new FileOutputStream(file);
+ out.write(TargetLoader.getClassDataAsBytes(source));
+ out.close();
+ }
+
}