3333import java .util .zip .ZipInputStream ;
3434import java .util .zip .ZipOutputStream ;
3535
36+ import org .jacoco .core .JaCoCo ;
3637import org .jacoco .core .analysis .AnalyzerTest ;
3738import org .jacoco .core .internal .Pack200Streams ;
3839import org .jacoco .core .internal .data .CRC64 ;
@@ -127,8 +128,7 @@ public void instrument_should_throw_exception_for_unsupported_class_file_version
127128 instrumenter .instrument (bytes , "UnsupportedVersion" );
128129 fail ("exception expected" );
129130 } catch (final IOException e ) {
130- assertEquals ("Error while instrumenting UnsupportedVersion." ,
131- e .getMessage ());
131+ assertExceptionMessage ("UnsupportedVersion" , e );
132132 assertEquals ("Unsupported class file major version 64" ,
133133 e .getCause ().getMessage ());
134134 }
@@ -156,8 +156,7 @@ public void testInstrumentBrokenClass1() throws IOException {
156156 instrumenter .instrument (brokenclass , "Broken.class" );
157157 fail ();
158158 } catch (IOException e ) {
159- assertEquals ("Error while instrumenting Broken.class." ,
160- e .getMessage ());
159+ assertExceptionMessage ("Broken.class" , e );
161160 }
162161 }
163162
@@ -178,8 +177,7 @@ public void testInstrumentBrokenStream() {
178177 instrumenter .instrument (new BrokenInputStream (), "BrokenStream" );
179178 fail ("exception expected" );
180179 } catch (IOException e ) {
181- assertEquals ("Error while instrumenting BrokenStream." ,
182- e .getMessage ());
180+ assertExceptionMessage ("BrokenStream" , e );
183181 }
184182 }
185183
@@ -194,8 +192,7 @@ public void testInstrumentBrokenStream2() {
194192 new ByteArrayOutputStream (), "BrokenStream" );
195193 fail ("exception expected" );
196194 } catch (IOException e ) {
197- assertEquals ("Error while instrumenting BrokenStream." ,
198- e .getMessage ());
195+ assertExceptionMessage ("BrokenStream" , e );
199196 }
200197 }
201198
@@ -230,8 +227,7 @@ public void instrumentAll_should_throw_exception_for_unsupported_class_file_vers
230227 new ByteArrayOutputStream (), "UnsupportedVersion" );
231228 fail ("exception expected" );
232229 } catch (final IOException e ) {
233- assertEquals ("Error while instrumenting UnsupportedVersion." ,
234- e .getMessage ());
230+ assertExceptionMessage ("UnsupportedVersion" , e );
235231 assertEquals ("Unsupported class file major version 64" ,
236232 e .getCause ().getMessage ());
237233 }
@@ -297,7 +293,7 @@ public void testInstrumentAll_Broken() {
297293 new ByteArrayOutputStream (), "Broken" );
298294 fail ("exception expected" );
299295 } catch (IOException e ) {
300- assertEquals ( "Error while instrumenting Broken. " , e . getMessage () );
296+ assertExceptionMessage ( " Broken" , e );
301297 }
302298 }
303299
@@ -324,7 +320,7 @@ public int read() throws IOException {
324320 instrumenter .instrumentAll (inputStream , new ByteArrayOutputStream (),
325321 "Broken" );
326322 } catch (IOException e ) {
327- assertEquals ( "Error while instrumenting Broken. " , e . getMessage () );
323+ assertExceptionMessage ( " Broken" , e );
328324 }
329325 }
330326
@@ -346,7 +342,7 @@ public void testInstrumentAll_BrokenZip() {
346342 new ByteArrayOutputStream (), "Test.zip" );
347343 fail ("exception expected" );
348344 } catch (IOException e ) {
349- assertEquals ( "Error while instrumenting Test.zip. " , e . getMessage () );
345+ assertExceptionMessage ( " Test.zip" , e );
350346 }
351347 }
352348
@@ -371,9 +367,7 @@ public void testInstrumentAll_BrokenZipEntry() throws IOException {
371367 new ByteArrayOutputStream (), "broken.zip" );
372368 fail ("exception expected" );
373369 } catch (IOException e ) {
374- assertEquals (
375- "Error while instrumenting broken.zip@brokenentry.txt." ,
376- e .getMessage ());
370+ assertExceptionMessage ("broken.zip@brokenentry.txt" , e );
377371 }
378372 }
379373
@@ -394,8 +388,7 @@ public void testInstrumentAll_BrokenClassFileInZip() throws IOException {
394388 "test.zip" );
395389 fail ();
396390 } catch (IOException e ) {
397- assertEquals ("Error while instrumenting test.zip@Test.class." ,
398- e .getMessage ());
391+ assertExceptionMessage ("test.zip@Test.class" , e );
399392 }
400393 }
401394
@@ -412,7 +405,7 @@ public void testInstrumentAll_BrokenGZ() {
412405 new ByteArrayOutputStream (), "Test.gz" );
413406 fail ("exception expected" );
414407 } catch (IOException e ) {
415- assertEquals ( "Error while instrumenting Test.gz. " , e . getMessage () );
408+ assertExceptionMessage ( " Test.gz" , e );
416409 }
417410 }
418411
@@ -462,8 +455,7 @@ public void testInstrumentAll_BrokenPack200() {
462455 instrumenter .instrumentAll (new ByteArrayInputStream (buffer ),
463456 new ByteArrayOutputStream (), "Test.pack200" );
464457 } catch (IOException e ) {
465- assertEquals ("Error while instrumenting Test.pack200." ,
466- e .getMessage ());
458+ assertExceptionMessage ("Test.pack200" , e );
467459 }
468460 }
469461
@@ -516,4 +508,10 @@ public void testInstrumentAll_KeepSignatures() throws IOException {
516508 assertNull (zipin .getNextEntry ());
517509 }
518510
511+ private void assertExceptionMessage (String name , Exception ex ) {
512+ String expected = "Error while instrumenting " + name + " with JaCoCo "
513+ + JaCoCo .VERSION + "/" + JaCoCo .COMMITID_SHORT + "." ;
514+ assertEquals (expected , ex .getMessage ());
515+ }
516+
519517}
0 commit comments