Replace ExpectedException which was deprecated in junit 4.13

Change-Id: I64b0c057dd0a12aef2f3d56fa0c8a10e3b23fffd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2020-01-22 00:48:24 +01:00 committed by David Pursehouse
parent b5cabfbff2
commit 8ada9048c5
21 changed files with 252 additions and 294 deletions

View File

@ -177,6 +177,12 @@ maven_jar(
sha1 = "497ddb32fd5d01f9dbe99a2ec790aeb931dff1b1", sha1 = "497ddb32fd5d01f9dbe99a2ec790aeb931dff1b1",
) )
maven_jar(
name = "assertj-core",
artifact = "org.assertj:assertj-core:3.14.0",
sha1 = "3b7b0fcac821f3d167764e9926573cd64f78f9e9",
)
BYTE_BUDDY_VERSION = "1.9.0" BYTE_BUDDY_VERSION = "1.9.0"
maven_jar( maven_jar(

View File

@ -213,6 +213,15 @@ java_library(
], ],
) )
java_library(
name = "assertj-core",
testonly = 1,
visibility = ["//visibility:public"],
exports = [
"@assertj-core//jar",
],
)
java_library( java_library(
name = "servlet-api", name = "servlet-api",
visibility = [ visibility = [

View File

@ -18,6 +18,7 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -88,18 +89,12 @@
import org.eclipse.jgit.transport.http.HttpConnectionFactory; import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.eclipse.jgit.util.HttpSupport; import org.eclipse.jgit.util.HttpSupport;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase { public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding"; private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
@Rule
public ExpectedException thrown = ExpectedException.none();
private AdvertiseRefsHook advertiseRefsHook; private AdvertiseRefsHook advertiseRefsHook;
private Repository remoteRepository; private Repository remoteRepository;
@ -462,11 +457,12 @@ public void testFetchBySHA1Unreachable() throws Exception {
try (Repository dst = createBareRepository(); try (Repository dst = createBareRepository();
Transport t = Transport.open(dst, remoteURI)) { Transport t = Transport.open(dst, remoteURI)) {
assertFalse(dst.getObjectDatabase().has(A_txt)); assertFalse(dst.getObjectDatabase().has(A_txt));
thrown.expect(TransportException.class); Exception e = assertThrows(TransportException.class,
thrown.expectMessage(Matchers.containsString( () -> t.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(
new RefSpec(unreachableCommit.name()))));
assertTrue(e.getMessage().contains(
"want " + unreachableCommit.name() + " not valid")); "want " + unreachableCommit.name() + " not valid"));
t.fetch(NullProgressMonitor.INSTANCE, Collections
.singletonList(new RefSpec(unreachableCommit.name())));
} }
} }
@ -484,11 +480,11 @@ protected Map<String, Ref> getAdvertisedRefs(Repository repository,
try (Repository dst = createBareRepository(); try (Repository dst = createBareRepository();
Transport t = Transport.open(dst, remoteURI)) { Transport t = Transport.open(dst, remoteURI)) {
assertFalse(dst.getObjectDatabase().has(A_txt)); assertFalse(dst.getObjectDatabase().has(A_txt));
thrown.expect(TransportException.class); Exception e = assertThrows(TransportException.class,
thrown.expectMessage(Matchers.containsString( () -> t.fetch(NullProgressMonitor.INSTANCE,
"want " + A.name() + " not valid")); Collections.singletonList(new RefSpec(A.name()))));
t.fetch(NullProgressMonitor.INSTANCE, Collections assertTrue(
.singletonList(new RefSpec(A.name()))); e.getMessage().contains("want " + A.name() + " not valid"));
} }
} }

View File

@ -12,6 +12,7 @@
import static org.apache.http.HttpStatus.SC_NOT_FOUND; import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY; import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -22,15 +23,10 @@
import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils; import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class DownloadTest extends LfsServerTest { public class DownloadTest extends LfsServerTest {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test @Test
public void testDownload() throws Exception { public void testDownload() throws Exception {
String TEXT = "test"; String TEXT = "test";
@ -49,10 +45,8 @@ public void testDownloadInvalidPathInfo()
Path f = Paths.get(getTempDirectory().toString(), "download"); Path f = Paths.get(getTempDirectory().toString(), "download");
String error = String.format( String error = String.format(
"Invalid pathInfo: '/%s' does not match '/{SHA-256}'", id); "Invalid pathInfo: '/%s' does not match '/{SHA-256}'", id);
exception.expect(RuntimeException.class); assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
exception.expectMessage( RuntimeException.class, () -> getContent(id, f));
formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
getContent(id, f);
} }
@Test @Test
@ -62,22 +56,18 @@ public void testDownloadInvalidId()
String id = putContent(TEXT).name().replace('f', 'z'); String id = putContent(TEXT).name().replace('f', 'z');
Path f = Paths.get(getTempDirectory().toString(), "download"); Path f = Paths.get(getTempDirectory().toString(), "download");
String error = String.format("Invalid id: %s", id); String error = String.format("Invalid id: %s", id);
exception.expect(RuntimeException.class); assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
exception.expectMessage( RuntimeException.class, () -> getContent(id, f));
formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
getContent(id, f);
} }
@Test @Test
public void testDownloadNotFound() public void testDownloadNotFound() {
throws ClientProtocolException, IOException {
String TEXT = "test"; String TEXT = "test";
AnyLongObjectId id = LongObjectIdTestUtils.hash(TEXT); AnyLongObjectId id = LongObjectIdTestUtils.hash(TEXT);
Path f = Paths.get(getTempDirectory().toString(), "download"); Path f = Paths.get(getTempDirectory().toString(), "download");
String error = String.format("Object '%s' not found", id.getName()); String error = String.format("Object '%s' not found", id.getName());
exception.expect(RuntimeException.class); assertThrows(formatErrorMessage(SC_NOT_FOUND, error),
exception.expectMessage(formatErrorMessage(SC_NOT_FOUND, error)); RuntimeException.class, () -> getContent(id, f));
getContent(id, f);
} }
@SuppressWarnings("boxing") @SuppressWarnings("boxing")

View File

@ -9,6 +9,7 @@
*/ */
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@ -17,24 +18,18 @@
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class BlameTest extends CLIRepositoryTestCase { public class BlameTest extends CLIRepositoryTestCase {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testBlameNoHead() throws Exception { public void testBlameNoHead() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
writeTrashFile("inIndex.txt", "index"); writeTrashFile("inIndex.txt", "index");
git.add().addFilepattern("inIndex.txt").call(); git.add().addFilepattern("inIndex.txt").call();
} }
thrown.expect(Die.class); assertThrows("no such ref: HEAD", Die.class,
thrown.expectMessage("no such ref: HEAD"); () -> execute("git blame inIndex.txt"));
execute("git blame inIndex.txt");
} }
@Test @Test
@ -68,9 +63,8 @@ public void testBlameUnstaged() throws Exception {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
} }
writeTrashFile("onlyInWorkingTree.txt", "not in repo"); writeTrashFile("onlyInWorkingTree.txt", "not in repo");
thrown.expect(Die.class); assertThrows("no such path 'onlyInWorkingTree.txt' in HEAD", Die.class,
thrown.expectMessage("no such path 'onlyInWorkingTree.txt' in HEAD"); () -> execute("git blame onlyInWorkingTree.txt"));
execute("git blame onlyInWorkingTree.txt");
} }
@Test @Test
@ -78,9 +72,8 @@ public void testBlameNonExisting() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
} }
thrown.expect(Die.class); assertThrows("no such path 'does_not_exist.txt' in HEAD", Die.class,
thrown.expectMessage("no such path 'does_not_exist.txt' in HEAD"); () -> execute("git blame does_not_exist.txt"));
execute("git blame does_not_exist.txt");
} }
@Test @Test
@ -88,9 +81,8 @@ public void testBlameNonExistingInSubdir() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
} }
thrown.expect(Die.class); assertThrows("no such path 'sub/does_not_exist.txt' in HEAD", Die.class,
thrown.expectMessage("no such path 'sub/does_not_exist.txt' in HEAD"); () -> execute("git blame sub/does_not_exist.txt"));
execute("git blame sub/does_not_exist.txt");
} }
@Test @Test

View File

@ -55,6 +55,7 @@ java_library(
srcs = HELPERS, srcs = HELPERS,
resources = DATA, resources = DATA,
deps = [ deps = [
"//lib:assertj-core",
"//lib:jsch", "//lib:jsch",
"//lib:junit", "//lib:junit",
"//lib:mockito", "//lib:mockito",

View 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.bzip2;version="[1.15.0,2.0)",
org.apache.commons.compress.compressors.gzip;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.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.bouncycastle.util.encoders;version="[1.61.0,2.0.0)",
org.eclipse.jgit.annotations;version="[5.7.0,5.8.0)", org.eclipse.jgit.annotations;version="[5.7.0,5.8.0)",
org.eclipse.jgit.api;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.eclipse.jgit.util.sha1;version="[5.7.0,5.8.0)",
org.junit;version="[4.13,5.0.0)", org.junit;version="[4.13,5.0.0)",
org.junit.experimental.theories;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.rules;version="[4.13,5.0.0)",
org.junit.runner;version="[4.13,5.0.0)", org.junit.runner;version="[4.13,5.0.0)",
org.junit.runners;version="[4.13,5.0.0)", org.junit.runners;version="[4.13,5.0.0)",

View File

@ -65,6 +65,11 @@
<version>[1.1.0,2.0.0)</version> <version>[1.1.0,2.0.0)</version>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -14,6 +14,7 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
@ -25,9 +26,7 @@
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
/** /**
* Unit tests of {@link RenameBranchCommand} * Unit tests of {@link RenameBranchCommand}
@ -40,9 +39,6 @@ public class RenameBranchCommandTest extends RepositoryTestCase {
private Git git; private Git git;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -57,8 +53,8 @@ public void setUp() throws Exception {
@Test @Test
public void renameToExisting() throws Exception { public void renameToExisting() throws Exception {
assertNotNull(git.branchCreate().setName("foo").call()); assertNotNull(git.branchCreate().setName("foo").call());
thrown.expect(RefAlreadyExistsException.class); assertThrows(RefAlreadyExistsException.class, () -> git.branchRename()
git.branchRename().setOldName("master").setNewName("foo").call(); .setOldName("master").setNewName("foo").call());
} }
@Test @Test

View File

@ -40,23 +40,18 @@
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class DfsBlockCacheConfigTest { public class DfsBlockCacheConfigTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void blockSizeNotPowerOfTwoExpectsException() { public void blockSizeNotPowerOfTwoExpectsException() {
thrown.expect(IllegalArgumentException.class); assertThrows(JGitText.get().blockSizeNotPowerOf2,
thrown.expectMessage(is(JGitText.get().blockSizeNotPowerOf2)); IllegalArgumentException.class,
() -> new DfsBlockCacheConfig().setBlockSize(1000));
new DfsBlockCacheConfig().setBlockSize(1000);
} }
@Test @Test

View File

@ -12,6 +12,7 @@
import static org.eclipse.jgit.lib.Ref.Storage.PACKED; import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
@ -21,6 +22,7 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.jgit.internal.storage.file.FileReftableStack.Segment; import org.eclipse.jgit.internal.storage.file.FileReftableStack.Segment;
import org.eclipse.jgit.internal.storage.reftable.MergedReftable; import org.eclipse.jgit.internal.storage.reftable.MergedReftable;
import org.eclipse.jgit.internal.storage.reftable.RefCursor; import org.eclipse.jgit.internal.storage.reftable.RefCursor;
@ -31,9 +33,7 @@
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class FileReftableStackTest { public class FileReftableStackTest {
@ -113,9 +113,6 @@ public void testCompaction1024() throws Exception {
testCompaction(1024); testCompaction(1024);
} }
@Rule
public final ExpectedException thrown = ExpectedException.none();
@SuppressWarnings({ "resource", "unused" }) @SuppressWarnings({ "resource", "unused" })
@Test @Test
public void missingReftable() throws Exception { public void missingReftable() throws Exception {
@ -143,9 +140,9 @@ public void missingReftable() throws Exception {
} }
} }
} }
thrown.expect(FileNotFoundException.class); assertThrows(FileNotFoundException.class,
new FileReftableStack(new File(reftableDir, "refs"), reftableDir, null, () -> new FileReftableStack(new File(reftableDir, "refs"),
() -> new Config()); reftableDir, null, () -> new Config()));
} }
@Test @Test

View File

@ -44,6 +44,7 @@
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
@ -67,15 +68,10 @@
import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ObjectDirectoryTest extends RepositoryTestCase { public class ObjectDirectoryTest extends RepositoryTestCase {
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Test @Test
public void testConcurrentInsertionOfBlobsToTheSameNewFanOutDirectory() public void testConcurrentInsertionOfBlobsToTheSameNewFanOutDirectory()
throws Exception { throws Exception {
@ -199,8 +195,7 @@ public void testShallowFile()
} }
@Test @Test
public void testShallowFileCorrupt() public void testShallowFileCorrupt() throws Exception {
throws Exception {
FileRepository repository = createBareRepository(); FileRepository repository = createBareRepository();
ObjectDirectory dir = repository.getObjectDatabase(); ObjectDirectory dir = repository.getObjectDatabase();
@ -210,11 +205,9 @@ public void testShallowFileCorrupt()
UTF_8.name())) { UTF_8.name())) {
writer.println(commit); writer.println(commit);
} }
assertThrows(
expectedEx.expect(IOException.class); MessageFormat.format(JGitText.get().badShallowLine, commit),
expectedEx.expectMessage(MessageFormat IOException.class, () -> dir.getShallowCommits());
.format(JGitText.get().badShallowLine, commit));
dir.getShallowCommits();
} }
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir( private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(

View File

@ -19,6 +19,7 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -53,13 +54,9 @@
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class T0003_BasicTest extends SampleDataRepositoryTestCase { public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test @Test
public void test001_Initalize() { public void test001_Initalize() {
@ -311,10 +308,10 @@ public void test002_CreateBadTree() throws Exception {
// We won't create a tree entry with an empty filename // We won't create a tree entry with an empty filename
// //
final TreeFormatter formatter = new TreeFormatter(); final TreeFormatter formatter = new TreeFormatter();
expectedException.expect(IllegalArgumentException.class); assertThrows(JGitText.get().invalidTreeZeroLengthName,
expectedException.expectMessage(JGitText.get().invalidTreeZeroLengthName); IllegalArgumentException.class,
formatter.append("", FileMode.TREE, () -> formatter.append("", FileMode.TREE, ObjectId.fromString(
ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")); "4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
} }
@Test @Test

View File

@ -29,6 +29,7 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -58,7 +59,6 @@
import org.junit.After; import org.junit.After;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
/** /**
@ -75,9 +75,6 @@ public class ConfigTest {
private static final String REFS_BACKUP = "+refs/heads/*:refs/remotes/backup/*"; private static final String REFS_BACKUP = "+refs/heads/*:refs/remotes/backup/*";
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Rule @Rule
public TemporaryFolder tmp = new TemporaryFolder(); public TemporaryFolder tmp = new TemporaryFolder();
@ -721,24 +718,22 @@ public void testReadMultipleValuesForName() throws ConfigInvalidException {
} }
@Test @Test
public void testIncludeInvalidName() throws ConfigInvalidException { public void testIncludeInvalidName() {
expectedEx.expect(ConfigInvalidException.class); assertThrows(JGitText.get().invalidLineInConfigFile,
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); ConfigInvalidException.class, () -> parse("[include]\nbar\n"));
parse("[include]\nbar\n");
} }
@Test @Test
public void testIncludeNoValue() throws ConfigInvalidException { public void testIncludeNoValue() {
expectedEx.expect(ConfigInvalidException.class); assertThrows(JGitText.get().invalidLineInConfigFile,
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); ConfigInvalidException.class, () -> parse("[include]\npath\n"));
parse("[include]\npath\n");
} }
@Test @Test
public void testIncludeEmptyValue() throws ConfigInvalidException { public void testIncludeEmptyValue() {
expectedEx.expect(ConfigInvalidException.class); assertThrows(JGitText.get().invalidLineInConfigFile,
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); ConfigInvalidException.class,
parse("[include]\npath=\n"); () -> parse("[include]\npath=\n"));
} }
@Test @Test
@ -1269,25 +1264,24 @@ public void testTimeUnitDefaultValue() throws ConfigInvalidException {
} }
@Test @Test
public void testTimeUnitInvalid() throws ConfigInvalidException { public void testTimeUnitInvalid() {
expectedEx.expect(IllegalArgumentException.class); assertThrows("Invalid time unit value: a.a=1 monttthhh",
expectedEx IllegalArgumentException.class,
.expectMessage("Invalid time unit value: a.a=1 monttthhh"); () -> parseTime("1 monttthhh", DAYS));
parseTime("1 monttthhh", DAYS);
} }
@Test @Test
public void testTimeUnitInvalidWithSection() throws ConfigInvalidException { public void testTimeUnitInvalidWithSection() throws ConfigInvalidException {
Config c = parse("[a \"b\"]\na=1 monttthhh\n"); Config c = parse("[a \"b\"]\na=1 monttthhh\n");
expectedEx.expect(IllegalArgumentException.class); assertThrows("Invalid time unit value: a.b.a=1 monttthhh",
expectedEx.expectMessage("Invalid time unit value: a.b.a=1 monttthhh"); IllegalArgumentException.class,
c.getTimeUnit("a", "b", "a", 0, DAYS); () -> c.getTimeUnit("a", "b", "a", 0, DAYS));
} }
@Test @Test
public void testTimeUnitNegative() throws ConfigInvalidException { public void testTimeUnitNegative() {
expectedEx.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class,
parseTime("-1", MILLISECONDS); () -> parseTime("-1", MILLISECONDS));
} }
@Test @Test
@ -1430,10 +1424,10 @@ public void testDropBackslashFromInvalidEscapeSequenceInSubsectionName()
} }
@Test @Test
public void testInvalidGroupHeader() throws ConfigInvalidException { public void testInvalidGroupHeader() {
expectedEx.expect(ConfigInvalidException.class); assertThrows(JGitText.get().badGroupHeader,
expectedEx.expectMessage(JGitText.get().badGroupHeader); ConfigInvalidException.class,
parse("[foo \"bar\" ]\nfoo=bar\n"); () -> parse("[foo \"bar\" ]\nfoo=bar\n"));
} }
@Test @Test
@ -1447,17 +1441,15 @@ public void testLfContinuation() throws ConfigInvalidException {
} }
@Test @Test
public void testCrCharContinuation() throws ConfigInvalidException { public void testCrCharContinuation() {
expectedEx.expect(ConfigInvalidException.class); assertThrows("Bad escape: \\u000d", ConfigInvalidException.class,
expectedEx.expectMessage("Bad escape: \\u000d"); () -> parseEscapedValue("tr\\\rue"));
parseEscapedValue("tr\\\rue");
} }
@Test @Test
public void testCrEOFContinuation() throws ConfigInvalidException { public void testCrEOFContinuation() {
expectedEx.expect(ConfigInvalidException.class); assertThrows("Bad escape: \\u000d", ConfigInvalidException.class,
expectedEx.expectMessage("Bad escape: \\u000d"); () -> parseEscapedValue("tr\\\r"));
parseEscapedValue("tr\\\r");
} }
@Test @Test

View File

@ -34,6 +34,7 @@
import static org.eclipse.jgit.util.RawParseUtils.decode; import static org.eclipse.jgit.util.RawParseUtils.decode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -41,9 +42,7 @@
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ObjectCheckerTest { public class ObjectCheckerTest {
private static final ObjectChecker SECRET_KEY_CHECKER = new ObjectChecker() { private static final ObjectChecker SECRET_KEY_CHECKER = new ObjectChecker() {
@ -84,9 +83,6 @@ public void endBlob(AnyObjectId id)
private ObjectChecker checker; private ObjectChecker checker;
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
checker = new ObjectChecker(); checker = new ObjectChecker();
@ -116,9 +112,9 @@ public void testCheckBlobNotCorrupt() throws CorruptObjectException {
} }
@Test @Test
public void testCheckBlobCorrupt() throws CorruptObjectException { public void testCheckBlobCorrupt() {
thrown.expect(CorruptObjectException.class); assertThrows(CorruptObjectException.class, () -> SECRET_KEY_CHECKER
SECRET_KEY_CHECKER.check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")); .check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")));
} }
@Test @Test
@ -129,11 +125,9 @@ public void testCheckBlobWithBlobObjectCheckerNotCorrupt()
} }
@Test @Test
public void testCheckBlobWithBlobObjectCheckerCorrupt() public void testCheckBlobWithBlobObjectCheckerCorrupt() {
throws CorruptObjectException { assertThrows(CorruptObjectException.class, () -> SECRET_KEY_BLOB_CHECKER
thrown.expect(CorruptObjectException.class); .check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")));
SECRET_KEY_BLOB_CHECKER.check(OBJ_BLOB,
encodeASCII("key = \"secret_key\""));
} }
@Test @Test

View File

@ -17,6 +17,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -44,36 +45,30 @@
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class BundleWriterTest extends SampleDataRepositoryTestCase { public class BundleWriterTest extends SampleDataRepositoryTestCase {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testEmptyBundleFails() throws Exception { public void testEmptyBundleFails() throws Exception {
Repository newRepo = createBareRepository(); Repository newRepo = createBareRepository();
thrown.expect(TransportException.class); assertThrows(TransportException.class,
fetchFromBundle(newRepo, new byte[0]); () -> fetchFromBundle(newRepo, new byte[0]));
} }
@Test @Test
public void testNonBundleFails() throws Exception { public void testNonBundleFails() throws Exception {
Repository newRepo = createBareRepository(); Repository newRepo = createBareRepository();
thrown.expect(TransportException.class); assertThrows(TransportException.class, () -> fetchFromBundle(newRepo,
fetchFromBundle(newRepo, "Not a bundle file".getBytes(UTF_8)); "Not a bundle file".getBytes(UTF_8)));
} }
@Test @Test
public void testGarbageBundleFails() throws Exception { public void testGarbageBundleFails() throws Exception {
Repository newRepo = createBareRepository(); Repository newRepo = createBareRepository();
thrown.expect(TransportException.class); assertThrows(TransportException.class, () -> fetchFromBundle(newRepo,
fetchFromBundle(newRepo,
(TransportBundle.V2_BUNDLE_SIGNATURE + '\n' + "Garbage") (TransportBundle.V2_BUNDLE_SIGNATURE + '\n' + "Garbage")
.getBytes(UTF_8)); .getBytes(UTF_8)));
} }
@Test @Test

View File

@ -14,6 +14,7 @@
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -27,15 +28,10 @@
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ProtocolV2ParserTest { public class ProtocolV2ParserTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private TestRepository<InMemoryRepository> testRepo; private TestRepository<InMemoryRepository> testRepo;
@Before @Before
@ -236,8 +232,8 @@ public void testFetchMustNotHaveMultipleFilters() throws IOException {
ProtocolV2Parser parser = new ProtocolV2Parser( ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done()); ConfigBuilder.start().allowFilter().done());
thrown.expect(PackProtocolException.class); assertThrows(PackProtocolException.class,
parser.parseFetchRequest(pckIn); () -> parser.parseFetchRequest(pckIn));
} }
@Test @Test
@ -247,8 +243,8 @@ public void testFetchFilterWithoutAllowFilter() throws IOException {
ProtocolV2Parser parser = new ProtocolV2Parser( ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault()); ConfigBuilder.getDefault());
thrown.expect(PackProtocolException.class); assertThrows(PackProtocolException.class,
parser.parseFetchRequest(pckIn); () -> parser.parseFetchRequest(pckIn));
} }
@Test @Test

View File

@ -9,12 +9,15 @@
*/ */
package org.eclipse.jgit.transport; 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.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
@ -25,17 +28,11 @@
import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.UploadPack.RequestValidator; import org.eclipse.jgit.transport.UploadPack.RequestValidator;
import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public abstract class RequestValidatorTestCase { public abstract class RequestValidatorTestCase {
@Rule
public ExpectedException thrown = ExpectedException.none();
private RevCommit reachableCommit; private RevCommit reachableCommit;
private RevCommit tipAdvertisedCommit; private RevCommit tipAdvertisedCommit;
@ -111,156 +108,165 @@ public void setUp() throws Exception {
protected abstract boolean isUnreachableBlobValid(); protected abstract boolean isUnreachableBlobValid();
@Test @Test
public void validateReachableCommitWithBitmaps() public void validateReachableCommitWithBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
if (!isReachableCommitValid()) { getUploadPack(getRepoWithBitmaps()),
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers
.containsString(
"want " + reachableCommit.name() + " not valid"));
}
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
Arrays.asList(reachableCommit)); Arrays.asList(reachableCommit));
}
@Test
public void validateReachableCommitWithoutBitmaps()
throws PackProtocolException, IOException {
if (!isReachableCommitValid()) { if (!isReachableCommitValid()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + reachableCommit.name() + " not valid");
"want " + reachableCommit.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), c.call();
}
@Test
public void validateReachableCommitWithoutBitmaps() throws Throwable {
ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(reachableCommit)); Arrays.asList(reachableCommit));
if (!isReachableCommitValid()) {
assertTransportException(c,
"want " + reachableCommit.name() + " not valid");
return;
}
c.call();
} }
@Test @Test
public void validateAdvertisedTipWithBitmaps() public void validateAdvertisedTipWithBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
if (!isAdvertisedTipValid()) { getUploadPack(getRepoWithBitmaps()),
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers.containsString(
"want " + tipAdvertisedCommit.name() + " not valid"));
}
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
Arrays.asList(tipAdvertisedCommit)); Arrays.asList(tipAdvertisedCommit));
}
@Test
public void validateAdvertisedTipWithoutBitmaps()
throws PackProtocolException, IOException {
if (!isAdvertisedTipValid()) { if (!isAdvertisedTipValid()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + tipAdvertisedCommit.name() + " not valid");
"want " + tipAdvertisedCommit.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), c.call();
}
@Test
public void validateAdvertisedTipWithoutBitmaps() throws Throwable {
ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(tipAdvertisedCommit)); Arrays.asList(tipAdvertisedCommit));
if (!isAdvertisedTipValid()) {
assertTransportException(c,
"want " + tipAdvertisedCommit.name() + " not valid");
return;
}
c.call();
} }
@Test @Test
public void validateUnadvertisedTipWithBitmaps() public void validateUnadvertisedTipWithBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
if (!isUnadvertisedTipCommitValid()) { getUploadPack(getRepoWithBitmaps()),
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers.containsString(
"want " + tipUnadvertisedCommit.name() + " not valid"));
}
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
Arrays.asList(tipUnadvertisedCommit)); Arrays.asList(tipUnadvertisedCommit));
}
@Test
public void validateUnadvertisedTipWithoutBitmaps()
throws PackProtocolException, IOException {
if (!isUnadvertisedTipCommitValid()) { if (!isUnadvertisedTipCommitValid()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + tipUnadvertisedCommit.name() + " not valid");
"want " + tipUnadvertisedCommit.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), c.call();
}
@Test
public void validateUnadvertisedTipWithoutBitmaps() throws Throwable {
ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(tipUnadvertisedCommit)); Arrays.asList(tipUnadvertisedCommit));
} if (!isUnadvertisedTipCommitValid()) {
assertTransportException(c,
@Test "want " + tipUnadvertisedCommit.name() + " not valid");
public void validateUnreachableCommitWithBitmaps() return;
throws PackProtocolException, IOException {
if (!isUnreachableCommitValid()) {
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers.containsString(
"want " + unreachableCommit.name() + " not valid"));
} }
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), c.call();
Arrays.asList(unreachableCommit));
} }
@Test @Test
public void validateUnreachableCommitWithoutBitmaps() public void validateUnreachableCommitWithBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithBitmaps()),
Arrays.asList(unreachableCommit));
if (!isUnreachableCommitValid()) { if (!isUnreachableCommitValid()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + unreachableCommit.name() + " not valid");
"want " + unreachableCommit.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), c.call();
Arrays.asList(unreachableCommit));
} }
@Test @Test
public void validateReachableBlobWithBitmaps() public void validateUnreachableCommitWithoutBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(unreachableCommit));
if (!isUnreachableCommitValid()) {
assertTransportException(c,
"want " + unreachableCommit.name() + " not valid");
return;
}
c.call();
}
@Test
public void validateReachableBlobWithBitmaps() throws Throwable {
ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithBitmaps()),
Arrays.asList(reachableBlob));
if (!isReachableBlobValid_withBitmaps()) { if (!isReachableBlobValid_withBitmaps()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + reachableBlob.name() + " not valid");
"want " + reachableBlob.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), c.call();
Arrays.asList(reachableBlob));
} }
@Test @Test
public void validateReachableBlobWithoutBitmaps() public void validateReachableBlobWithoutBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(reachableBlob));
if (!isReachableBlobValid_withoutBitmaps()) { if (!isReachableBlobValid_withoutBitmaps()) {
thrown.expect(TransportException.class); assertTransportException(c,
thrown.expectMessage(Matchers.containsString( "want " + reachableBlob.name() + " not valid");
"want " + reachableBlob.name() + " not valid")); return;
} }
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), c.call();
Arrays.asList(reachableBlob));
} }
@Test @Test
public void validateUnreachableBlobWithBitmaps() public void validateUnreachableBlobWithBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
if (!isUnreachableBlobValid()) { getUploadPack(getRepoWithBitmaps()),
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers.containsString(
"want " + unreachableBlob.name() + " not valid"));
}
createValidator().checkWants(getUploadPack(getRepoWithBitmaps()),
Arrays.asList(unreachableBlob)); Arrays.asList(unreachableBlob));
if (!isUnreachableBlobValid()) {
assertTransportException(c,
"want " + unreachableBlob.name() + " not valid");
return;
}
c.call();
} }
@Test @Test
public void validateUnreachableBlobWithoutBitmaps() public void validateUnreachableBlobWithoutBitmaps() throws Throwable {
throws PackProtocolException, IOException { ThrowingCallable c = () -> createValidator().checkWants(
if (!isUnreachableBlobValid()) { getUploadPack(getRepoWithoutBitmaps()),
thrown.expect(TransportException.class);
thrown.expectMessage(Matchers.containsString(
"want " + unreachableBlob.name() + " not valid"));
}
createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()),
Arrays.asList(unreachableBlob)); Arrays.asList(unreachableBlob));
if (!isUnreachableBlobValid()) {
assertTransportException(c,
"want " + unreachableBlob.name() + " not valid");
return;
}
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 { private UploadPack getUploadPack(Repository repository) throws IOException {

View File

@ -32,9 +32,7 @@
import org.eclipse.jgit.transport.resolver.UploadPackFactory; import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
/** /**
* Test combinations of: * Test combinations of:
@ -46,9 +44,6 @@
*/ */
public class UploadPackReachabilityTest { public class UploadPackReachabilityTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private URIish uri; private URIish uri;
private TestProtocol<Object> testProtocol; private TestProtocol<Object> testProtocol;

View File

@ -13,16 +13,12 @@
import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import org.eclipse.jgit.errors.BinaryBlobException; import org.eclipse.jgit.errors.BinaryBlobException;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
public class RawParseUtils_LineMapTest { public class RawParseUtils_LineMapTest {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test @Test
public void testEmpty() throws Exception { public void testEmpty() throws Exception {
@ -62,8 +58,8 @@ public void testNulByte() {
@Test @Test
public void testLineMapOrBinary() throws Exception { public void testLineMapOrBinary() throws Exception {
final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1); final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
exception.expect(BinaryBlobException.class); assertThrows(BinaryBlobException.class,
RawParseUtils.lineMapOrBinary(buf, 3, buf.length); () -> RawParseUtils.lineMapOrBinary(buf, 3, buf.length));
} }
@Test @Test

View File

@ -775,6 +775,11 @@
<version>${bouncycastle-version}</version> <version>${bouncycastle-version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>