aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2015-10-02 00:04:39 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2015-10-02 00:04:39 +0200
commitc24f773806f64e86aa6a0b15aa20238f984c3f8c (patch)
tree74bb10ddb28e6672db2e5fb07087e69753603967 /org.jacoco.core.test
parent2c73d99ac91de90576210cc77c9e1e067719c02b (diff)
downloadjacoco-c24f773806f64e86aa6a0b15aa20238f984c3f8c.tar.gz
GitHub #319: Improved error message for incompatible exec data files.
In case of incompatible execution data formats read from another JaCoCo version ExecutionDataReader.read() now throws a IncompatibleExecDataVersionException with a better error message.
Diffstat (limited to 'org.jacoco.core.test')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java4
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java49
2 files changed, 51 insertions, 2 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
index 0efcf7a3..2b6dcbc3 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataReaderWriterTest.java
@@ -135,8 +135,8 @@ public class ExecutionDataReaderWriterTest {
createReader().read();
}
- @Test(expected = IOException.class)
- public void testInvalidHeaderVersion() throws IOException {
+ @Test(expected = IncompatibleExecDataVersionException.class)
+ public void testInvalidVersion() throws IOException {
buffer = new ByteArrayOutputStream();
buffer.write(ExecutionDataWriter.BLOCK_HEADER);
buffer.write(0xC0);
diff --git a/org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java b/org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java
new file mode 100644
index 00000000..e1735fc1
--- /dev/null
+++ b/org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2015 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.core.data;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link IncompatibleExecDataVersionExceptionTest}.
+ */
+public class IncompatibleExecDataVersionExceptionTest {
+
+ private IncompatibleExecDataVersionException exception;
+
+ @Before
+ public void setup() {
+ exception = new IncompatibleExecDataVersionException(0x1234);
+ }
+
+ @Test
+ public void testGetMessage() {
+ String expected = "Cannot read execution data version 0x1234. "
+ + "This version of JaCoCo uses execution data version 0x"
+ + Integer.toHexString(ExecutionDataWriter.FORMAT_VERSION) + ".";
+ assertEquals(expected, exception.getMessage());
+ }
+
+ @Test
+ public void testGetActualVersion() {
+ assertEquals(0x1234, exception.getActualVersion());
+ }
+
+ @Test
+ public void testGetExpectedVersion() {
+ assertEquals(ExecutionDataWriter.FORMAT_VERSION,
+ exception.getExpectedVersion());
+ }
+}