]> source.dussan.org Git - jgit.git/commitdiff
Replace ExpectedException which was deprecated in junit 4.13 65/156365/5
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 21 Jan 2020 23:48:24 +0000 (00:48 +0100)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 24 Jan 2020 06:46:08 +0000 (15:46 +0900)
Change-Id: I64b0c057dd0a12aef2f3d56fa0c8a10e3b23fffd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
21 files changed:
WORKSPACE
lib/BUILD
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java
org.eclipse.jgit.test/BUILD
org.eclipse.jgit.test/META-INF/MANIFEST.MF
org.eclipse.jgit.test/pom.xml
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
pom.xml

index 8c3c27f75bd6f22ff261804420fb4d95fd417ac9..f456e4c31a1d1c3637b85788392faf189e4397f6 100644 (file)
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -177,6 +177,12 @@ maven_jar(
     sha1 = "497ddb32fd5d01f9dbe99a2ec790aeb931dff1b1",
 )
 
+maven_jar(
+    name = "assertj-core",
+    artifact = "org.assertj:assertj-core:3.14.0",
+    sha1 = "3b7b0fcac821f3d167764e9926573cd64f78f9e9",
+)
+
 BYTE_BUDDY_VERSION = "1.9.0"
 
 maven_jar(
index 058899fce665cdbee6f6e2fc64d55d9ccb0e72e3..6c974865ecea02ebac3f8428e645baa8f303ef7e 100644 (file)
--- a/lib/BUILD
+++ b/lib/BUILD
@@ -213,6 +213,15 @@ java_library(
     ],
 )
 
+java_library(
+    name = "assertj-core",
+    testonly = 1,
+    visibility = ["//visibility:public"],
+    exports = [
+        "@assertj-core//jar",
+    ],
+)
+
 java_library(
     name = "servlet-api",
     visibility = [
index 9a7c0776ad8f440a7fbee2ee3a03b8d6ac698bf5..51a7a8ddc11b242c6fb562e4e0c428333e2b63b6 100644 (file)
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -88,18 +89,12 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 import org.eclipse.jgit.transport.http.HttpConnectionFactory;
 import org.eclipse.jgit.util.HttpSupport;
 import org.eclipse.jgit.util.SystemReader;
-import org.hamcrest.Matchers;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
        private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        private AdvertiseRefsHook advertiseRefsHook;
 
        private Repository remoteRepository;
@@ -462,11 +457,12 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
                try (Repository dst = createBareRepository();
                                Transport t = Transport.open(dst, remoteURI)) {
                        assertFalse(dst.getObjectDatabase().has(A_txt));
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
+                       Exception e = assertThrows(TransportException.class,
+                                       () -> t.fetch(NullProgressMonitor.INSTANCE,
+                                                       Collections.singletonList(
+                                                                       new RefSpec(unreachableCommit.name()))));
+                       assertTrue(e.getMessage().contains(
                                        "want " + unreachableCommit.name() + " not valid"));
-                       t.fetch(NullProgressMonitor.INSTANCE, Collections
-                                       .singletonList(new RefSpec(unreachableCommit.name())));
                }
        }
 
@@ -484,11 +480,11 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
                try (Repository dst = createBareRepository();
                                Transport t = Transport.open(dst, remoteURI)) {
                        assertFalse(dst.getObjectDatabase().has(A_txt));
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + A.name() + " not valid"));
-                       t.fetch(NullProgressMonitor.INSTANCE, Collections
-                                       .singletonList(new RefSpec(A.name())));
+                       Exception e = assertThrows(TransportException.class,
+                                       () -> t.fetch(NullProgressMonitor.INSTANCE,
+                                                       Collections.singletonList(new RefSpec(A.name()))));
+                       assertTrue(
+                                       e.getMessage().contains("want " + A.name() + " not valid"));
                }
        }
 
index d295414496d85f838ff47b08eb6946d74c7d4353..8d32f9e75a70f2586011ad1d412f804cfd979312 100644 (file)
@@ -12,6 +12,7 @@ package org.eclipse.jgit.lfs.server.fs;
 import static org.apache.http.HttpStatus.SC_NOT_FOUND;
 import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 
 import java.io.IOException;
 import java.nio.file.Path;
@@ -22,15 +23,10 @@ import org.apache.http.client.ClientProtocolException;
 import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
 import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
 import org.eclipse.jgit.util.FileUtils;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class DownloadTest extends LfsServerTest {
 
-       @Rule
-       public ExpectedException exception = ExpectedException.none();
-
        @Test
        public void testDownload() throws Exception {
                String TEXT = "test";
@@ -49,10 +45,8 @@ public class DownloadTest extends LfsServerTest {
                Path f = Paths.get(getTempDirectory().toString(), "download");
                String error = String.format(
                                "Invalid pathInfo: '/%s' does not match '/{SHA-256}'", id);
-               exception.expect(RuntimeException.class);
-               exception.expectMessage(
-                               formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
-               getContent(id, f);
+               assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
+                               RuntimeException.class, () -> getContent(id, f));
        }
 
        @Test
@@ -62,22 +56,18 @@ public class DownloadTest extends LfsServerTest {
                String id = putContent(TEXT).name().replace('f', 'z');
                Path f = Paths.get(getTempDirectory().toString(), "download");
                String error = String.format("Invalid id: %s", id);
-               exception.expect(RuntimeException.class);
-               exception.expectMessage(
-                               formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
-               getContent(id, f);
+               assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
+                               RuntimeException.class, () -> getContent(id, f));
        }
 
        @Test
-       public void testDownloadNotFound()
-                       throws ClientProtocolException, IOException {
+       public void testDownloadNotFound() {
                String TEXT = "test";
                AnyLongObjectId id = LongObjectIdTestUtils.hash(TEXT);
                Path f = Paths.get(getTempDirectory().toString(), "download");
                String error = String.format("Object '%s' not found", id.getName());
-               exception.expect(RuntimeException.class);
-               exception.expectMessage(formatErrorMessage(SC_NOT_FOUND, error));
-               getContent(id, f);
+               assertThrows(formatErrorMessage(SC_NOT_FOUND, error),
+                               RuntimeException.class, () -> getContent(id, f));
        }
 
        @SuppressWarnings("boxing")
index 006039bdcacb452c8c92468782d7423d4938f294..ea304335835ee850db8294fc53f1597f81214789 100644 (file)
@@ -9,6 +9,7 @@
  */
 package org.eclipse.jgit.pgm;
 
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import org.eclipse.jgit.api.Git;
@@ -17,24 +18,18 @@ import org.eclipse.jgit.lib.CLIRepositoryTestCase;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.PersonIdent;
 import org.eclipse.jgit.revwalk.RevCommit;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class BlameTest extends CLIRepositoryTestCase {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        @Test
        public void testBlameNoHead() throws Exception {
                try (Git git = new Git(db)) {
                        writeTrashFile("inIndex.txt", "index");
                        git.add().addFilepattern("inIndex.txt").call();
                }
-               thrown.expect(Die.class);
-               thrown.expectMessage("no such ref: HEAD");
-               execute("git blame inIndex.txt");
+               assertThrows("no such ref: HEAD", Die.class,
+                               () -> execute("git blame inIndex.txt"));
        }
 
        @Test
@@ -68,9 +63,8 @@ public class BlameTest extends CLIRepositoryTestCase {
                        git.commit().setMessage("initial commit").call();
                }
                writeTrashFile("onlyInWorkingTree.txt", "not in repo");
-               thrown.expect(Die.class);
-               thrown.expectMessage("no such path 'onlyInWorkingTree.txt' in HEAD");
-               execute("git blame onlyInWorkingTree.txt");
+               assertThrows("no such path 'onlyInWorkingTree.txt' in HEAD", Die.class,
+                               () -> execute("git blame onlyInWorkingTree.txt"));
        }
 
        @Test
@@ -78,9 +72,8 @@ public class BlameTest extends CLIRepositoryTestCase {
                try (Git git = new Git(db)) {
                        git.commit().setMessage("initial commit").call();
                }
-               thrown.expect(Die.class);
-               thrown.expectMessage("no such path 'does_not_exist.txt' in HEAD");
-               execute("git blame does_not_exist.txt");
+               assertThrows("no such path 'does_not_exist.txt' in HEAD", Die.class,
+                               () -> execute("git blame does_not_exist.txt"));
        }
 
        @Test
@@ -88,9 +81,8 @@ public class BlameTest extends CLIRepositoryTestCase {
                try (Git git = new Git(db)) {
                        git.commit().setMessage("initial commit").call();
                }
-               thrown.expect(Die.class);
-               thrown.expectMessage("no such path 'sub/does_not_exist.txt' in HEAD");
-               execute("git blame sub/does_not_exist.txt");
+               assertThrows("no such path 'sub/does_not_exist.txt' in HEAD", Die.class,
+                               () -> execute("git blame sub/does_not_exist.txt"));
        }
 
        @Test
index 3d487960c452951d094fc8e43ab568891f135b56..b34ef2a7960e68a865ac567b12392c9d1883c688 100644 (file)
@@ -55,6 +55,7 @@ java_library(
     srcs = HELPERS,
     resources = DATA,
     deps = [
+        "//lib:assertj-core",
         "//lib:jsch",
         "//lib:junit",
         "//lib:mockito",
index 509ef0b05c232b2bb36e452afd821ebc66934a85..18f16d91f2d4612f4f36c902bec35a4b06604d7a 100644 (file)
@@ -17,6 +17,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
  org.apache.commons.compress.compressors.bzip2;version="[1.15.0,2.0)",
  org.apache.commons.compress.compressors.gzip;version="[1.15.0,2.0)",
  org.apache.commons.compress.compressors.xz;version="[1.15.0,2.0)",
+ org.assertj.core.api;version="[3.14.0,4.0.0)",
  org.bouncycastle.util.encoders;version="[1.61.0,2.0.0)",
  org.eclipse.jgit.annotations;version="[5.7.0,5.8.0)",
  org.eclipse.jgit.api;version="[5.7.0,5.8.0)",
@@ -72,6 +73,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
  org.eclipse.jgit.util.sha1;version="[5.7.0,5.8.0)",
  org.junit;version="[4.13,5.0.0)",
  org.junit.experimental.theories;version="[4.13,5.0.0)",
+ org.junit.function;version="[4.13.0,5.0.0)",
  org.junit.rules;version="[4.13,5.0.0)",
  org.junit.runner;version="[4.13,5.0.0)",
  org.junit.runners;version="[4.13,5.0.0)",
index 60e6818dcc56908f875a7503d4fb3b5af6022669..7ba19d4efadeb22a09cf9d5ef42ce564aa75d4d7 100644 (file)
       <version>[1.1.0,2.0.0)</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
index 6f7ec9a444b8bce1da825918a1978c027f477064..534ebd9c61a165c8ac2a0f104fe525baf8c9a5e0 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
@@ -25,9 +26,7 @@ import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.StoredConfig;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 /**
  * Unit tests of {@link RenameBranchCommand}
@@ -40,9 +39,6 @@ public class RenameBranchCommandTest extends RepositoryTestCase {
 
        private Git git;
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        @Override
        @Before
        public void setUp() throws Exception {
@@ -57,8 +53,8 @@ public class RenameBranchCommandTest extends RepositoryTestCase {
        @Test
        public void renameToExisting() throws Exception {
                assertNotNull(git.branchCreate().setName("foo").call());
-               thrown.expect(RefAlreadyExistsException.class);
-               git.branchRename().setOldName("master").setNewName("foo").call();
+               assertThrows(RefAlreadyExistsException.class, () -> git.branchRename()
+                               .setOldName("master").setNewName("foo").call());
        }
 
        @Test
index e612061abf5f4047bc92568e0bdd5bf06b2aacc7..2df0ba1b05ad520ac0a483232f178bc2155c985c 100644 (file)
@@ -40,23 +40,18 @@ package org.eclipse.jgit.internal.storage.dfs;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThrows;
 
 import org.eclipse.jgit.internal.JGitText;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class DfsBlockCacheConfigTest {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        @Test
        public void blockSizeNotPowerOfTwoExpectsException() {
-               thrown.expect(IllegalArgumentException.class);
-               thrown.expectMessage(is(JGitText.get().blockSizeNotPowerOf2));
-
-               new DfsBlockCacheConfig().setBlockSize(1000);
+               assertThrows(JGitText.get().blockSizeNotPowerOf2,
+                               IllegalArgumentException.class,
+                               () -> new DfsBlockCacheConfig().setBlockSize(1000));
        }
 
        @Test
index 770991e51300ffca916348b3ac980724da758c5c..72bff168317dd099b38c20d7387c7a6c41fac610 100644 (file)
@@ -12,6 +12,7 @@ package org.eclipse.jgit.internal.storage.file;
 
 import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -21,6 +22,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
+
 import org.eclipse.jgit.internal.storage.file.FileReftableStack.Segment;
 import org.eclipse.jgit.internal.storage.reftable.MergedReftable;
 import org.eclipse.jgit.internal.storage.reftable.RefCursor;
@@ -31,9 +33,7 @@ import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.util.FileUtils;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class FileReftableStackTest {
 
@@ -113,9 +113,6 @@ public class FileReftableStackTest {
                testCompaction(1024);
        }
 
-       @Rule
-       public final ExpectedException thrown = ExpectedException.none();
-
        @SuppressWarnings({ "resource", "unused" })
        @Test
        public void missingReftable() throws Exception {
@@ -143,9 +140,9 @@ public class FileReftableStackTest {
                                }
                        }
                }
-               thrown.expect(FileNotFoundException.class);
-               new FileReftableStack(new File(reftableDir, "refs"), reftableDir, null,
-                               () -> new Config());
+               assertThrows(FileNotFoundException.class,
+                               () -> new FileReftableStack(new File(reftableDir, "refs"),
+                                               reftableDir, null, () -> new Config()));
        }
 
        @Test
index 97c56385bd3480882f70c18d5d960d48673ef15c..d269457eb1f5a19a36a0c4f6b6537e421f8e8a20 100644 (file)
@@ -44,6 +44,7 @@ package org.eclipse.jgit.internal.storage.file;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -67,15 +68,10 @@ import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.util.FS;
 import org.junit.Assume;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class ObjectDirectoryTest extends RepositoryTestCase {
 
-       @Rule
-       public ExpectedException expectedEx = ExpectedException.none();
-
        @Test
        public void testConcurrentInsertionOfBlobsToTheSameNewFanOutDirectory()
                        throws Exception {
@@ -199,8 +195,7 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
        }
 
        @Test
-       public void testShallowFileCorrupt()
-                       throws Exception {
+       public void testShallowFileCorrupt() throws Exception {
                FileRepository repository = createBareRepository();
                ObjectDirectory dir = repository.getObjectDatabase();
 
@@ -210,11 +205,9 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
                                UTF_8.name())) {
                        writer.println(commit);
                }
-
-               expectedEx.expect(IOException.class);
-               expectedEx.expectMessage(MessageFormat
-                               .format(JGitText.get().badShallowLine, commit));
-               dir.getShallowCommits();
+               assertThrows(
+                               MessageFormat.format(JGitText.get().badShallowLine, commit),
+                               IOException.class, () -> dir.getShallowCommits());
        }
 
        private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
index a6a8a17b2c987f09ce24475edb7f52d966c9ddd7..49e8a7be666b59a99305fbafa2fcc14ebed835ab 100644 (file)
@@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -53,13 +54,9 @@ import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
 import org.eclipse.jgit.util.FS;
 import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.IO;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class T0003_BasicTest extends SampleDataRepositoryTestCase {
-       @Rule
-       public ExpectedException expectedException = ExpectedException.none();
 
        @Test
        public void test001_Initalize() {
@@ -311,10 +308,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                // We won't create a tree entry with an empty filename
                //
                final TreeFormatter formatter = new TreeFormatter();
-               expectedException.expect(IllegalArgumentException.class);
-               expectedException.expectMessage(JGitText.get().invalidTreeZeroLengthName);
-               formatter.append("", FileMode.TREE,
-                               ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904"));
+               assertThrows(JGitText.get().invalidTreeZeroLengthName,
+                               IllegalArgumentException.class,
+                               () -> formatter.append("", FileMode.TREE, ObjectId.fromString(
+                                               "4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
        }
 
        @Test
index a80d8b3779efe16c6722b5b872400d9f22671be5..9b5691775f8014e90d87bcf9401b4f3c53ae9a5e 100644 (file)
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -58,7 +59,6 @@ import org.eclipse.jgit.util.SystemReader;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 
 /**
@@ -75,9 +75,6 @@ public class ConfigTest {
 
        private static final String REFS_BACKUP = "+refs/heads/*:refs/remotes/backup/*";
 
-       @Rule
-       public ExpectedException expectedEx = ExpectedException.none();
-
        @Rule
        public TemporaryFolder tmp = new TemporaryFolder();
 
@@ -721,24 +718,22 @@ public class ConfigTest {
        }
 
        @Test
-       public void testIncludeInvalidName() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
-               parse("[include]\nbar\n");
+       public void testIncludeInvalidName() {
+               assertThrows(JGitText.get().invalidLineInConfigFile,
+                               ConfigInvalidException.class, () -> parse("[include]\nbar\n"));
        }
 
        @Test
-       public void testIncludeNoValue() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
-               parse("[include]\npath\n");
+       public void testIncludeNoValue() {
+               assertThrows(JGitText.get().invalidLineInConfigFile,
+                               ConfigInvalidException.class, () -> parse("[include]\npath\n"));
        }
 
        @Test
-       public void testIncludeEmptyValue() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
-               parse("[include]\npath=\n");
+       public void testIncludeEmptyValue() {
+               assertThrows(JGitText.get().invalidLineInConfigFile,
+                               ConfigInvalidException.class,
+                               () -> parse("[include]\npath=\n"));
        }
 
        @Test
@@ -1269,25 +1264,24 @@ public class ConfigTest {
        }
 
        @Test
-       public void testTimeUnitInvalid() throws ConfigInvalidException {
-               expectedEx.expect(IllegalArgumentException.class);
-               expectedEx
-                               .expectMessage("Invalid time unit value: a.a=1 monttthhh");
-               parseTime("1 monttthhh", DAYS);
+       public void testTimeUnitInvalid() {
+               assertThrows("Invalid time unit value: a.a=1 monttthhh",
+                               IllegalArgumentException.class,
+                               () -> parseTime("1 monttthhh", DAYS));
        }
 
        @Test
        public void testTimeUnitInvalidWithSection() throws ConfigInvalidException {
                Config c = parse("[a \"b\"]\na=1 monttthhh\n");
-               expectedEx.expect(IllegalArgumentException.class);
-               expectedEx.expectMessage("Invalid time unit value: a.b.a=1 monttthhh");
-               c.getTimeUnit("a", "b", "a", 0, DAYS);
+               assertThrows("Invalid time unit value: a.b.a=1 monttthhh",
+                               IllegalArgumentException.class,
+                               () -> c.getTimeUnit("a", "b", "a", 0, DAYS));
        }
 
        @Test
-       public void testTimeUnitNegative() throws ConfigInvalidException {
-               expectedEx.expect(IllegalArgumentException.class);
-               parseTime("-1", MILLISECONDS);
+       public void testTimeUnitNegative() {
+               assertThrows(IllegalArgumentException.class,
+                               () -> parseTime("-1", MILLISECONDS));
        }
 
        @Test
@@ -1430,10 +1424,10 @@ public class ConfigTest {
        }
 
        @Test
-       public void testInvalidGroupHeader() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage(JGitText.get().badGroupHeader);
-               parse("[foo \"bar\" ]\nfoo=bar\n");
+       public void testInvalidGroupHeader() {
+               assertThrows(JGitText.get().badGroupHeader,
+                               ConfigInvalidException.class,
+                               () -> parse("[foo \"bar\" ]\nfoo=bar\n"));
        }
 
        @Test
@@ -1447,17 +1441,15 @@ public class ConfigTest {
        }
 
        @Test
-       public void testCrCharContinuation() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage("Bad escape: \\u000d");
-               parseEscapedValue("tr\\\rue");
+       public void testCrCharContinuation() {
+               assertThrows("Bad escape: \\u000d", ConfigInvalidException.class,
+                               () -> parseEscapedValue("tr\\\rue"));
        }
 
        @Test
-       public void testCrEOFContinuation() throws ConfigInvalidException {
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage("Bad escape: \\u000d");
-               parseEscapedValue("tr\\\r");
+       public void testCrEOFContinuation() {
+               assertThrows("Bad escape: \\u000d", ConfigInvalidException.class,
+                               () -> parseEscapedValue("tr\\\r"));
        }
 
        @Test
index 11ed8fdf0df76b44b833ce6e4746ae78049e7a5f..5c44c9c44d00a20323b1e10f7334ce296b3e1b9a 100644 (file)
@@ -34,6 +34,7 @@ import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE;
 import static org.eclipse.jgit.util.RawParseUtils.decode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 
 import java.text.MessageFormat;
@@ -41,9 +42,7 @@ import java.text.MessageFormat;
 import org.eclipse.jgit.errors.CorruptObjectException;
 import org.eclipse.jgit.internal.JGitText;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class ObjectCheckerTest {
        private static final ObjectChecker SECRET_KEY_CHECKER = new ObjectChecker() {
@@ -84,9 +83,6 @@ public class ObjectCheckerTest {
 
        private ObjectChecker checker;
 
-       @Rule
-       public final ExpectedException thrown = ExpectedException.none();
-
        @Before
        public void setUp() throws Exception {
                checker = new ObjectChecker();
@@ -116,9 +112,9 @@ public class ObjectCheckerTest {
        }
 
        @Test
-       public void testCheckBlobCorrupt() throws CorruptObjectException {
-               thrown.expect(CorruptObjectException.class);
-               SECRET_KEY_CHECKER.check(OBJ_BLOB, encodeASCII("key = \"secret_key\""));
+       public void testCheckBlobCorrupt() {
+               assertThrows(CorruptObjectException.class, () -> SECRET_KEY_CHECKER
+                               .check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")));
        }
 
        @Test
@@ -129,11 +125,9 @@ public class ObjectCheckerTest {
        }
 
        @Test
-       public void testCheckBlobWithBlobObjectCheckerCorrupt()
-                       throws CorruptObjectException {
-               thrown.expect(CorruptObjectException.class);
-               SECRET_KEY_BLOB_CHECKER.check(OBJ_BLOB,
-                               encodeASCII("key = \"secret_key\""));
+       public void testCheckBlobWithBlobObjectCheckerCorrupt() {
+               assertThrows(CorruptObjectException.class, () -> SECRET_KEY_BLOB_CHECKER
+                               .check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")));
        }
 
        @Test
index b5ab9d2acdda17fd70f8a4dec8898df973d03c0a..054eb9c5ad620cf1da15b2e6b8aa4094e78e4046 100644 (file)
@@ -17,6 +17,7 @@ import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -44,36 +45,30 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class BundleWriterTest extends SampleDataRepositoryTestCase {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        @Test
        public void testEmptyBundleFails() throws Exception {
                Repository newRepo = createBareRepository();
-               thrown.expect(TransportException.class);
-               fetchFromBundle(newRepo, new byte[0]);
+               assertThrows(TransportException.class,
+                               () -> fetchFromBundle(newRepo, new byte[0]));
        }
 
        @Test
        public void testNonBundleFails() throws Exception {
                Repository newRepo = createBareRepository();
-               thrown.expect(TransportException.class);
-               fetchFromBundle(newRepo, "Not a bundle file".getBytes(UTF_8));
+               assertThrows(TransportException.class, () -> fetchFromBundle(newRepo,
+                               "Not a bundle file".getBytes(UTF_8)));
        }
 
        @Test
        public void testGarbageBundleFails() throws Exception {
                Repository newRepo = createBareRepository();
-               thrown.expect(TransportException.class);
-               fetchFromBundle(newRepo,
+               assertThrows(TransportException.class, () -> fetchFromBundle(newRepo,
                                (TransportBundle.V2_BUNDLE_SIGNATURE + '\n' + "Garbage")
-                                               .getBytes(UTF_8));
+                                               .getBytes(UTF_8)));
        }
 
        @Test
index f9300cd0fc83ab1f1670619255823052ce1b5cb1..038ce717b33213e94e8a1c1c50aac73bc372e468 100644 (file)
@@ -14,6 +14,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasItems;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -27,15 +28,10 @@ import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class ProtocolV2ParserTest {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        private TestRepository<InMemoryRepository> testRepo;
 
        @Before
@@ -236,8 +232,8 @@ public class ProtocolV2ParserTest {
                ProtocolV2Parser parser = new ProtocolV2Parser(
                                ConfigBuilder.start().allowFilter().done());
 
-               thrown.expect(PackProtocolException.class);
-               parser.parseFetchRequest(pckIn);
+               assertThrows(PackProtocolException.class,
+                               () -> parser.parseFetchRequest(pckIn));
        }
 
        @Test
@@ -247,8 +243,8 @@ public class ProtocolV2ParserTest {
                ProtocolV2Parser parser = new ProtocolV2Parser(
                                ConfigBuilder.getDefault());
 
-               thrown.expect(PackProtocolException.class);
-               parser.parseFetchRequest(pckIn);
+               assertThrows(PackProtocolException.class,
+                               () -> parser.parseFetchRequest(pckIn));
        }
 
        @Test
index f15fa48644809631e94b56798f3c2a478acd642a..cc910b3b9f55bf497c42f8ec0914c3229c0479bb 100644 (file)
@@ -9,12 +9,15 @@
  */
 package org.eclipse.jgit.transport;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowableOfType;
+
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.eclipse.jgit.errors.PackProtocolException;
+import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
 import org.eclipse.jgit.errors.TransportException;
 import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
 import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
@@ -25,17 +28,11 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevBlob;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.transport.UploadPack.RequestValidator;
-import org.hamcrest.Matchers;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public abstract class RequestValidatorTestCase {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        private RevCommit reachableCommit;
 
        private RevCommit tipAdvertisedCommit;
@@ -111,156 +108,165 @@ public abstract class RequestValidatorTestCase {
        protected abstract boolean isUnreachableBlobValid();
 
        @Test
-       public void validateReachableCommitWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateReachableCommitWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(reachableCommit));
                if (!isReachableCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers
-                                       .containsString(
-                                                       "want " + reachableCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + reachableCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(reachableCommit));
+               c.call();
        }
 
        @Test
-       public void validateReachableCommitWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateReachableCommitWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(reachableCommit));
                if (!isReachableCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + reachableCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + reachableCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(reachableCommit));
+               c.call();
        }
 
        @Test
-       public void validateAdvertisedTipWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateAdvertisedTipWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(tipAdvertisedCommit));
                if (!isAdvertisedTipValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + tipAdvertisedCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + tipAdvertisedCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(tipAdvertisedCommit));
+               c.call();
        }
 
        @Test
-       public void validateAdvertisedTipWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateAdvertisedTipWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(tipAdvertisedCommit));
                if (!isAdvertisedTipValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + tipAdvertisedCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + tipAdvertisedCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(tipAdvertisedCommit));
+               c.call();
        }
 
        @Test
-       public void validateUnadvertisedTipWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnadvertisedTipWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(tipUnadvertisedCommit));
                if (!isUnadvertisedTipCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + tipUnadvertisedCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + tipUnadvertisedCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(tipUnadvertisedCommit));
+               c.call();
        }
 
        @Test
-       public void validateUnadvertisedTipWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnadvertisedTipWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(tipUnadvertisedCommit));
                if (!isUnadvertisedTipCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + tipUnadvertisedCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + tipUnadvertisedCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(tipUnadvertisedCommit));
+               c.call();
        }
 
        @Test
-       public void validateUnreachableCommitWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnreachableCommitWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(unreachableCommit));
                if (!isUnreachableCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + unreachableCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + unreachableCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(unreachableCommit));
+               c.call();
        }
 
        @Test
-       public void validateUnreachableCommitWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnreachableCommitWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(unreachableCommit));
                if (!isUnreachableCommitValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + unreachableCommit.name() + " not valid"));
-
+                       assertTransportException(c,
+                                       "want " + unreachableCommit.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(unreachableCommit));
+               c.call();
        }
 
        @Test
-       public void validateReachableBlobWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateReachableBlobWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(reachableBlob));
                if (!isReachableBlobValid_withBitmaps()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + reachableBlob.name() + " not valid"));
+                       assertTransportException(c,
+                                       "want " + reachableBlob.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(reachableBlob));
+               c.call();
        }
 
        @Test
-       public void validateReachableBlobWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateReachableBlobWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(reachableBlob));
                if (!isReachableBlobValid_withoutBitmaps()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + reachableBlob.name() + " not valid"));
+                       assertTransportException(c,
+                                       "want " + reachableBlob.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(reachableBlob));
+               c.call();
        }
 
        @Test
-       public void validateUnreachableBlobWithBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnreachableBlobWithBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithBitmaps()),
+                               Arrays.asList(unreachableBlob));
                if (!isUnreachableBlobValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + unreachableBlob.name() + " not valid"));
+                       assertTransportException(c,
+                                       "want " + unreachableBlob.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
-                               Arrays.asList(unreachableBlob));
+               c.call();
        }
 
        @Test
-       public void validateUnreachableBlobWithoutBitmaps()
-                       throws PackProtocolException, IOException {
+       public void validateUnreachableBlobWithoutBitmaps() throws Throwable {
+               ThrowingCallable c = () -> createValidator().checkWants(
+                               getUploadPack(getRepoWithoutBitmaps()),
+                               Arrays.asList(unreachableBlob));
                if (!isUnreachableBlobValid()) {
-                       thrown.expect(TransportException.class);
-                       thrown.expectMessage(Matchers.containsString(
-                                       "want " + unreachableBlob.name() + " not valid"));
+                       assertTransportException(c,
+                                       "want " + unreachableBlob.name() + " not valid");
+                       return;
                }
-               createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
-                               Arrays.asList(unreachableBlob));
+               c.call();
+       }
+
+       private void assertTransportException(ThrowingCallable c,
+                       String messageContent) throws AssertionError {
+               assertThat(catchThrowableOfType(c, TransportException.class))
+                               .hasMessageContaining(messageContent);
        }
 
        private UploadPack getUploadPack(Repository repository) throws IOException {
index 8b4c05b802a85057805e8dc2900f2ba3d76e1dbf..271176264083504d5ed5180c001665d8f720bab5 100644 (file)
@@ -32,9 +32,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
 import org.eclipse.jgit.transport.resolver.UploadPackFactory;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 /**
  * Test combinations of:
@@ -46,9 +44,6 @@ import org.junit.rules.ExpectedException;
  */
 public class UploadPackReachabilityTest {
 
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-
        private URIish uri;
 
        private TestProtocol<Object> testProtocol;
index 7ea96dd9d7b37e0616f3df979372aee80d9abc7e..1c2d8d7f65a211d2308ad7626061921375f06e8b 100644 (file)
@@ -13,16 +13,12 @@ package org.eclipse.jgit.util;
 import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 
 import org.eclipse.jgit.errors.BinaryBlobException;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class RawParseUtils_LineMapTest {
-       @Rule
-       public ExpectedException exception = ExpectedException.none();
-
 
        @Test
        public void testEmpty() throws Exception {
@@ -62,8 +58,8 @@ public class RawParseUtils_LineMapTest {
        @Test
        public void testLineMapOrBinary() throws Exception {
                final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
-               exception.expect(BinaryBlobException.class);
-               RawParseUtils.lineMapOrBinary(buf, 3, buf.length);
+               assertThrows(BinaryBlobException.class,
+                               () -> RawParseUtils.lineMapOrBinary(buf, 3, buf.length));
        }
 
        @Test
diff --git a/pom.xml b/pom.xml
index 6cf7b3592a3c4ea789692026644cdfdcc9ddab56..0e1e98fa60c47548c7275a19c9241042ba513350 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <version>${bouncycastle-version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.assertj</groupId>
+        <artifactId>assertj-core</artifactId>
+        <version>3.14.0</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>