Skip to content

Commit

Permalink
Upgrade JUnit to 4.13 (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Mar 3, 2020
1 parent 3b95f61 commit c73490e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion org.jacoco.build/pom.xml
Expand Up @@ -142,7 +142,7 @@
<asm.version>7.2</asm.version>
<ant.version>1.7.1</ant.version>
<args4j.version>2.0.28</args4j.version>
<junit.version>4.8.2</junit.version>
<junit.version>4.13</junit.version>
<googlecodeprettify.version>20100721</googlecodeprettify.version>

<!-- ================== -->
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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}.
Expand Down
Expand Up @@ -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}.
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;

/**
Expand Down
Expand Up @@ -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;
Expand All @@ -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<String, List<?>> invocations;

@Before
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -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;
Expand All @@ -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}
Expand All @@ -36,9 +35,6 @@ public class StatementParserTest {
private List<String> actualInvocations;
private List<String> expectedInvocations;

@Rule
public ExpectedException exception = ExpectedException.none();

@Before
public void setup() {
actualInvocations = new ArrayList<String>();
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -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}.
Expand All @@ -50,9 +48,6 @@ public class ExecDumpClientTest {

private ServerSocket server;

@Rule
public ExpectedException exception = ExpectedException.none();

@Before
public void setup() {
callbacks = new ArrayList<String>();
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit c73490e

Please sign in to comment.