From c73490ef1aa3d56d5530f695748236a1fe146498 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov <138671+Godin@users.noreply.github.com> Date: Tue, 3 Mar 2020 22:53:47 +0200 Subject: [PATCH] Upgrade JUnit to 4.13 (#1026) --- org.jacoco.build/pom.xml | 2 +- .../jacoco/core/analysis/AnalyzerTest.java | 2 +- .../jacoco/core/instr/InstrumenterTest.java | 2 +- .../internal/ContentTypeDetectorTest.java | 2 +- .../core/internal/Pack200StreamsTest.java | 2 +- .../core/internal/instr/InstrSupportTest.java | 32 ++++++++------- .../runtime/InjectedClassRuntimeTest.java | 2 +- .../validation/StatementExecutorTest.java | 37 ++++++++++-------- .../test/validation/StatementParserTest.java | 39 ++++++++++++------- .../jacoco/core/tools/ExecDumpClientTest.java | 15 +++---- .../org/jacoco/examples/ConsoleOutput.java | 4 +- .../src/org/jacoco/examples/ExecDumpTest.java | 2 +- 12 files changed, 77 insertions(+), 64 deletions(-) diff --git a/org.jacoco.build/pom.xml b/org.jacoco.build/pom.xml index b2bf811f26..f5e758ed76 100644 --- a/org.jacoco.build/pom.xml +++ b/org.jacoco.build/pom.xml @@ -142,7 +142,7 @@ 7.2 1.7.1 2.0.28 - 4.8.2 + 4.13 20100721 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 6acb8f5e8e..9fc20df30a 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 @@ -39,10 +39,10 @@ import org.jacoco.core.internal.Pack200Streams; import org.jacoco.core.internal.data.CRC64; import org.jacoco.core.test.TargetLoader; +import org.junit.AssumptionViolatedException; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; import org.junit.rules.TemporaryFolder; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java index 9a4a1c10e5..b2d27a976f 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java @@ -39,9 +39,9 @@ import org.jacoco.core.internal.instr.InstrSupport; import org.jacoco.core.runtime.IExecutionDataAccessorGenerator; import org.jacoco.core.test.TargetLoader; +import org.junit.AssumptionViolatedException; import org.junit.Before; import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java index 75db677ee9..68fb4807ae 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java @@ -24,8 +24,8 @@ import java.util.zip.ZipOutputStream; import org.jacoco.core.test.TargetLoader; +import org.junit.AssumptionViolatedException; import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; /** * Unit tests for {@link ContentTypeDetector}. diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index c8290fac99..d489f9d490 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -31,8 +31,8 @@ import java.util.zip.ZipOutputStream; import org.jacoco.core.test.TargetLoader; +import org.junit.AssumptionViolatedException; import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; /** * Unit tests for {@link Pack200Streams}. diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java index c0bd3732e0..924e61be8f 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java @@ -16,11 +16,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; @@ -37,9 +36,6 @@ public class InstrSupportTest { private Printer printer; private TraceMethodVisitor trace; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setup() { printer = new Textifier(); @@ -142,20 +138,26 @@ public void assertNotIntrumented_should_accept_non_jacoco_memebers() { @Test public void assertNotIntrumented_should_throw_exception_when_jacoco_data_field_is_present() { - exception.expect(IllegalStateException.class); - exception.expectMessage( - "Cannot process instrumented class Foo. Please supply original non-instrumented classes."); - - InstrSupport.assertNotInstrumented("$jacocoData", "Foo"); + try { + InstrSupport.assertNotInstrumented("$jacocoData", "Foo"); + fail("exception expected"); + } catch (IllegalStateException e) { + assertEquals( + "Cannot process instrumented class Foo. Please supply original non-instrumented classes.", + e.getMessage()); + } } @Test public void assertNotIntrumented_should_throw_exception_when_jacoco_init_method_is_present() { - exception.expect(IllegalStateException.class); - exception.expectMessage( - "Cannot process instrumented class Foo. Please supply original non-instrumented classes."); - - InstrSupport.assertNotInstrumented("$jacocoInit", "Foo"); + try { + InstrSupport.assertNotInstrumented("$jacocoInit", "Foo"); + fail("exception expected"); + } catch (IllegalStateException e) { + assertEquals( + "Cannot process instrumented class Foo. Please supply original non-instrumented classes.", + e.getMessage()); + } } @Test diff --git a/org.jacoco.core.test/src/org/jacoco/core/runtime/InjectedClassRuntimeTest.java b/org.jacoco.core.test/src/org/jacoco/core/runtime/InjectedClassRuntimeTest.java index 64b8462dd5..c4edff1567 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/runtime/InjectedClassRuntimeTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/runtime/InjectedClassRuntimeTest.java @@ -17,10 +17,10 @@ import java.lang.reflect.InvocationTargetException; +import org.junit.AssumptionViolatedException; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; import org.junit.rules.TestName; /** diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementExecutorTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementExecutorTest.java index 3aa3540fad..2fb0a2b086 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementExecutorTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementExecutorTest.java @@ -13,6 +13,7 @@ package org.jacoco.core.test.validation; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.IOException; import java.util.Arrays; @@ -21,18 +22,13 @@ import java.util.Map; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Unit tests for {@link StatementExecutor}. */ public class StatementExecutorTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - private Map> invocations; @Before @@ -63,29 +59,36 @@ public void should_call_method_with_int_argument() { @Test public void should_preserve_AssertionError() { - exception.expect(AssertionError.class); - exception.expectMessage("Original AssertionError."); StatementExecutor executor = new StatementExecutor(this); - - executor.visitInvocation("ctx", "target3"); + try { + executor.visitInvocation("ctx", "target3"); + fail("exception expected"); + } catch (AssertionError e) { + assertEquals("Original AssertionError.", e.getMessage()); + } } @Test public void should_wrap_other_exceptions() { - exception.expect(RuntimeException.class); - exception.expectMessage("Invocation error (ctx)"); StatementExecutor executor = new StatementExecutor(this); - - executor.visitInvocation("ctx", "target4"); + try { + executor.visitInvocation("ctx", "target4"); + fail("exception expected"); + } catch (RuntimeException e) { + assertEquals("Invocation error (ctx)", e.getMessage()); + assertEquals("Original IOException.", e.getCause().getMessage()); + } } @Test public void should_throw_RuntimeException_when_method_cannot_be_invoked() { - exception.expect(RuntimeException.class); - exception.expectMessage("Invocation error (ctx)"); StatementExecutor executor = new StatementExecutor(this); - - executor.visitInvocation("ctx", "doesNotExist"); + try { + executor.visitInvocation("ctx", "doesNotExist"); + fail("exception expected"); + } catch (RuntimeException e) { + assertEquals("Invocation error (ctx)", e.getMessage()); + } } public void target1(String a, String b, String c) { diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementParserTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementParserTest.java index 7f418ec60a..f7c9dd3f06 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementParserTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/StatementParserTest.java @@ -13,6 +13,7 @@ package org.jacoco.core.test.validation; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.IOException; import java.util.ArrayList; @@ -22,9 +23,7 @@ import org.jacoco.core.test.validation.StatementParser.IStatementVisitor; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Unit tests for {@link StatementParser} @@ -36,9 +35,6 @@ public class StatementParserTest { private List actualInvocations; private List expectedInvocations; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setup() { actualInvocations = new ArrayList(); @@ -106,28 +102,43 @@ public void should_parse_multiple_invocations() throws IOException { @Test public void should_fail_when_parenthesis_is_missing() throws IOException { - exception.expect(IOException.class); - StatementParser.parse("bad(", visitor, "Foo.java"); + try { + StatementParser.parse("bad(", visitor, "Foo.java"); + fail("exception expected"); + } catch (IOException e) { + // expected + } } @Test public void should_fail_when_argument1_is_missing() throws IOException { - exception.expect(IOException.class); - StatementParser.parse("bad(,2)", visitor, "Foo.java"); + try { + StatementParser.parse("bad(,2)", visitor, "Foo.java"); + fail("exception expected"); + } catch (IOException e) { + // expected + } } @Test public void should_fail_when_argument2_is_missing() throws IOException { - exception.expect(IOException.class); - StatementParser.parse("bad(1,)", visitor, "Foo.java"); + try { + StatementParser.parse("bad(1,)", visitor, "Foo.java"); + fail("exception expected"); + } catch (IOException e) { + // expected + } } @Test public void should_give_context_info_when_parsing_fails() throws IOException { - exception.expect(IOException.class); - exception.expectMessage("Invalid syntax (Foo.java:32)"); - StatementParser.parse("bad", visitor, "Foo.java:32"); + try { + StatementParser.parse("bad", visitor, "Foo.java:32"); + fail("exception expected"); + } catch (IOException e) { + assertEquals("Invalid syntax (Foo.java:32)", e.getMessage()); + } } private void expectInvocation(String ctx, String name, Object... args) { diff --git a/org.jacoco.core.test/src/org/jacoco/core/tools/ExecDumpClientTest.java b/org.jacoco.core.test/src/org/jacoco/core/tools/ExecDumpClientTest.java index c23f0a6718..54f6496985 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/tools/ExecDumpClientTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/tools/ExecDumpClientTest.java @@ -33,9 +33,7 @@ import org.jacoco.core.runtime.RemoteControlWriter; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Unit tests for {@link ExecDumpClient}. @@ -50,9 +48,6 @@ public class ExecDumpClientTest { private ServerSocket server; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setup() { callbacks = new ArrayList(); @@ -136,11 +131,13 @@ public void testReset() throws IOException { @Test public void should_throw_IOException_when_server_closes_connection_without_response() throws IOException { - exception.expect(IOException.class); - exception.expectMessage("Socket closed unexpectedly."); - int port = createNopServer(); - client.dump((String) null, port); + try { + client.dump((String) null, port); + fail("exception expected"); + } catch (IOException e) { + assertEquals("Socket closed unexpectedly.", e.getMessage()); + } } private int getFreePort() throws IOException { diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java b/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java index ba88034225..5beed738cd 100644 --- a/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java +++ b/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java @@ -12,10 +12,10 @@ *******************************************************************************/ package org.jacoco.examples; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.containsString; import java.io.ByteArrayOutputStream; import java.io.PrintStream; diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java b/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java index 82000b6a8d..c4a2645a89 100644 --- a/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java +++ b/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java @@ -12,8 +12,8 @@ *******************************************************************************/ package org.jacoco.examples; +import static org.hamcrest.CoreMatchers.containsString; import static org.jacoco.examples.ConsoleOutput.containsLine; -import static org.junit.matchers.JUnitMatchers.containsString; import java.io.File; import java.io.FileOutputStream;