aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.agent.test/src
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2010-10-07 16:04:47 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2010-10-07 16:04:47 +0000
commit57fbd3e8e69134708a5d790b0688110277a9163a (patch)
treed76a7c6f0237dd8f7627d3f625f4d75b978f43de /org.jacoco.agent.test/src
parentde7ef5e2da9fcf7cadce0f695fa268be74f96f29 (diff)
downloadjacoco-57fbd3e8e69134708a5d790b0688110277a9163a.tar.gz
Add missing test project for org.jacoco.agent.
Diffstat (limited to 'org.jacoco.agent.test/src')
-rw-r--r--org.jacoco.agent.test/src/org/jacoco/agent/AgentJarTest.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/org.jacoco.agent.test/src/org/jacoco/agent/AgentJarTest.java b/org.jacoco.agent.test/src/org/jacoco/agent/AgentJarTest.java
new file mode 100644
index 00000000..b1581355
--- /dev/null
+++ b/org.jacoco.agent.test/src/org/jacoco/agent/AgentJarTest.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc R. Hoffmann - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.agent;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link AgentJar}.
+ *
+ * @author Marc R. Hoffmann
+ * @version $qualified.bundle.version$
+ */
+public class AgentJarTest {
+
+ private File file;
+
+ @After
+ public void teardown() {
+ if (file != null) {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testGetResource() throws IOException {
+ final InputStream in = AgentJar.getResource().openStream();
+ assertAgentContents(in);
+ }
+
+ @Test
+ public void testGetResourceAsStream() throws IOException {
+ final InputStream in = AgentJar.getResourceAsStream();
+ assertAgentContents(in);
+ }
+
+ @Test
+ public void testExtractTo() throws IOException {
+ file = File.createTempFile("agent", ".jar");
+ AgentJar.extractTo(file);
+ assertAgentContents(new FileInputStream(file));
+ }
+
+ @Test(expected = IOException.class)
+ public void testExtractToNegative() throws IOException {
+ file = File.createTempFile("folder", null);
+ file.delete();
+ file.mkdirs();
+ AgentJar.extractTo(file);
+ }
+
+ @Test
+ public void testExtractToTempLocation() throws IOException {
+ file = AgentJar.extractToTempLocation();
+ assertAgentContents(new FileInputStream(file));
+ file.delete();
+ }
+
+ private void assertAgentContents(InputStream in) throws IOException {
+ final ZipInputStream zip = new ZipInputStream(in);
+ while (true) {
+ final ZipEntry entry = zip.getNextEntry();
+ assertNotNull("Manifest not found.", entry);
+ if ("META-INF/MANIFEST.MF".equals(entry.getName())) {
+ final Manifest manifest = new Manifest(zip);
+ assertEquals("JaCoCo Java Agent", manifest.getMainAttributes()
+ .getValue("Implementation-Title"));
+ in.close();
+ break;
+ }
+ }
+ }
+
+}