From c24f773806f64e86aa6a0b15aa20238f984c3f8c Mon Sep 17 00:00:00 2001 From: "Marc R. Hoffmann" Date: Fri, 2 Oct 2015 00:04:39 +0200 Subject: 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. --- .../core/data/ExecutionDataReaderWriterTest.java | 4 +- .../IncompatibleExecDataVersionExceptionTest.java | 49 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 org.jacoco.core.test/src/org/jacoco/core/data/IncompatibleExecDataVersionExceptionTest.java (limited to 'org.jacoco.core.test') 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()); + } +} -- cgit v1.2.3