summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/BUILD1
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF12
-rw-r--r--org.eclipse.jgit.test/pom.xml5
-rw-r--r--org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java46
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java132
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java17
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java36
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java70
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java206
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java8
29 files changed, 370 insertions, 323 deletions
diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD
index 3d487960c4..b34ef2a796 100644
--- a/org.eclipse.jgit.test/BUILD
+++ b/org.eclipse.jgit.test/BUILD
@@ -55,6 +55,7 @@ java_library(
srcs = HELPERS,
resources = DATA,
deps = [
+ "//lib:assertj-core",
"//lib:jsch",
"//lib:junit",
"//lib:mockito",
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index d8f6bcfe28..18f16d91f2 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -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)",
@@ -70,11 +71,12 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.eclipse.jgit.util;version="[5.7.0,5.8.0)",
org.eclipse.jgit.util.io;version="[5.7.0,5.8.0)",
org.eclipse.jgit.util.sha1;version="[5.7.0,5.8.0)",
- org.junit;version="[4.12,5.0.0)",
- org.junit.experimental.theories;version="[4.12,5.0.0)",
- org.junit.rules;version="[4.12,5.0.0)",
- org.junit.runner;version="[4.12,5.0.0)",
- org.junit.runners;version="[4.12,5.0.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)",
org.mockito;version="[2.23.0,3.0.0)",
org.mockito.invocation;version="[2.23.0,3.0.0)",
org.mockito.junit;version="[2.23.0,3.0.0)",
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index 60e6818dcc..7ba19d4efa 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -66,6 +66,11 @@
</dependency>
<dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java
deleted file mode 100644
index cd0a6f1061..0000000000
--- a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2019, Google LLC and others
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Distribution License v. 1.0 which is available at
- * https://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-package org.eclipse.jgit.lib;
-
-/** Assertion methods. */
-public class MoreAsserts {
- /**
- * Simple version of assertThrows that will be introduced in JUnit 4.13.
- *
- * @param expected
- * Expected throwable class
- * @param r
- * Runnable that is expected to throw an exception.
- * @return The thrown exception.
- */
- public static <T extends Throwable> T assertThrows(Class<T> expected,
- ThrowingRunnable r) {
- try {
- r.run();
- } catch (Throwable actual) {
- if (expected.isAssignableFrom(actual.getClass())) {
- @SuppressWarnings("unchecked")
- T toReturn = (T) actual;
- return toReturn;
- }
- throw new AssertionError("Expected " + expected.getSimpleName()
- + ", but got " + actual.getClass().getSimpleName(), actual);
- }
- throw new AssertionError(
- "Expected " + expected.getSimpleName() + " to be thrown");
- }
-
- public interface ThrowingRunnable {
- void run() throws Throwable;
- }
-
- private MoreAsserts() {
- }
-}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java
index 6f7ec9a444..534ebd9c61 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java
new file mode 100644
index 0000000000..a07f37009e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2019 Alex Jitianu <alex_jitianu@sync.ro> and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.api;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Policy;
+import java.util.Collections;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.WriterAppender;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests that using a SecurityManager does not result in errors logged.
+ */
+public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase {
+
+ /**
+ * Collects all logging sent to the logging system.
+ */
+ private final StringWriter errorOutputWriter = new StringWriter();
+
+ /**
+ * Appender to intercept all logging sent to the logging system.
+ */
+ private WriterAppender appender;
+
+ private SecurityManager originalSecurityManager;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ originalSecurityManager = System.getSecurityManager();
+
+ appender = new WriterAppender(
+ new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN),
+ errorOutputWriter);
+
+ Logger.getRootLogger().addAppender(appender);
+
+ refreshPolicyAllPermission(Policy.getPolicy());
+ System.setSecurityManager(new SecurityManager());
+ super.setUp();
+ }
+
+ /**
+ * If a SecurityManager is active a lot of {@link java.io.FilePermission}
+ * errors are thrown and logged while initializing a repository.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCreateNewRepos_MissingPermissions() throws Exception {
+ File wcTree = new File(getTemporaryDirectory(),
+ "CreateNewRepositoryTest_testCreateNewRepos");
+
+ File marker = new File(getTemporaryDirectory(), "marker");
+ Files.write(marker.toPath(), Collections.singletonList("Can write"));
+ assertTrue("Can write in test directory", marker.isFile());
+ FileUtils.delete(marker);
+ assertFalse("Can delete in test direcory", marker.exists());
+
+ Git git = Git.init().setBare(false)
+ .setDirectory(new File(wcTree.getAbsolutePath())).call();
+
+ addRepoToClose(git.getRepository());
+
+ assertEquals("", errorOutputWriter.toString());
+ }
+
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ System.setSecurityManager(originalSecurityManager);
+ Logger.getRootLogger().removeAppender(appender);
+ super.tearDown();
+ }
+
+ /**
+ * Refresh the Java Security Policy.
+ *
+ * @param policy
+ * the policy object
+ *
+ * @throws IOException
+ * if the temporary file that contains the policy could not be
+ * created
+ */
+ private static void refreshPolicyAllPermission(Policy policy)
+ throws IOException {
+ // Starting with an all permissions policy.
+ String policyString = "grant { permission java.security.AllPermission; };";
+
+ // Do not use TemporaryFilesFactory, it will create a dependency cycle
+ Path policyFile = Files.createTempFile("testpolicy", ".txt");
+
+ try {
+ Files.write(policyFile, Collections.singletonList(policyString));
+ System.setProperty("java.security.policy",
+ policyFile.toUri().toURL().toString());
+ policy.refresh();
+ } finally {
+ try {
+ Files.delete(policyFile);
+ } catch (IOException e) {
+ // Do not log; the test tests for no logging having occurred
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
index 3886c15958..f8c7dae7df 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
@@ -13,9 +13,9 @@ import static org.eclipse.jgit.diff.DiffEntry.DEV_NULL;
import static org.eclipse.jgit.util.FileUtils.delete;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -26,8 +26,8 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java
index e612061abf..2df0ba1b05 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java
index 770991e513..72bff16831 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
index 74f1aea6fc..8baa3cc341 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
@@ -10,13 +10,13 @@
package org.eclipse.jgit.internal.storage.file;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
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.assertSame;
-import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
index 97c56385bd..d269457eb1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
@@ -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(
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
index 8e438bc0e0..8c56480fe1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
@@ -45,15 +45,14 @@ package org.eclipse.jgit.internal.storage.file;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
-
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index a6a8a17b2c..49e8a7be66 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
index f73dfedaec..009914b35c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
@@ -13,16 +13,16 @@ package org.eclipse.jgit.internal.storage.reftable;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
-import static org.eclipse.jgit.lib.MoreAsserts.assertThrows;
import static org.eclipse.jgit.lib.Ref.Storage.NEW;
import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
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.assertSame;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java
index 5a7a034ad0..6c8c3ba61b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java
@@ -9,6 +9,10 @@
*/
package org.eclipse.jgit.internal.transport.http;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@@ -27,10 +31,8 @@ import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.jgit.internal.storage.file.LockFile;
-import org.eclipse.jgit.internal.transport.http.NetscapeCookieFile;
import org.eclipse.jgit.util.http.HttpCookiesMatcher;
import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -81,11 +83,10 @@ public class NetscapeCookieFileTest {
cookie = new HttpCookie("key3", "valueFromSet2");
cookiesExpectedMergedSet.add(cookie);
- Assert.assertThat(
- NetscapeCookieFile.mergeCookies(cookieSet1, cookieSet2),
+ assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, cookieSet2),
HttpCookiesMatcher.containsInOrder(cookiesExpectedMergedSet));
- Assert.assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, null),
+ assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, null),
HttpCookiesMatcher.containsInOrder(cookieSet1));
}
@@ -110,8 +111,7 @@ public class NetscapeCookieFileTest {
String expectedExpiration = String
.valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000));
- Assert.assertThat(
- Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
+ assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
CoreMatchers
.equalTo(Arrays.asList("mydomain.com\tTRUE\t/\tTRUE\t"
+ expectedExpiration + "\tkey2\tvalue")));
@@ -136,8 +136,7 @@ public class NetscapeCookieFileTest {
String expectedExpiration = String
.valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000));
- Assert.assertThat(
- Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
+ assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
CoreMatchers.equalTo(
Arrays.asList("domain.com\tTRUE\t/my/path\tFALSE\t"
+ expectedExpiration + "\tkey2\tvalue2")));
@@ -154,7 +153,7 @@ public class NetscapeCookieFileTest {
// now imitate another process/thread holding the lock file
LockFile lockFile = new LockFile(tmpFile.toFile());
try {
- Assert.assertTrue("Could not acquire lock", lockFile.lock());
+ assertTrue("Could not acquire lock", lockFile.lock());
cookieFile.write(baseUrl);
} finally {
lockFile.unlock();
@@ -184,7 +183,7 @@ public class NetscapeCookieFileTest {
List<String> lines = Files.readAllLines(tmpFile,
StandardCharsets.US_ASCII);
- Assert.assertEquals("Expected 3 lines", 3, lines.size());
+ assertEquals("Expected 3 lines", 3, lines.size());
assertStringMatchesPatternWithInexactNumber(lines.get(0),
"some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey1\tvalueFromSimple2",
JAN_01_2030_NOON, 1000);
@@ -202,12 +201,12 @@ public class NetscapeCookieFileTest {
long delta) {
java.util.regex.Matcher matcher = Pattern.compile(pattern)
.matcher(string);
- Assert.assertTrue("Given string '" + string + "' does not match '"
- + pattern + "'", matcher.matches());
+ assertTrue("Given string '" + string + "' does not match '" + pattern
+ + "'", matcher.matches());
// extract numeric value
Long actualNumericValue = Long.decode(matcher.group(1));
- Assert.assertTrue(
+ assertTrue(
"Value is supposed to be close to " + expectedNumericValue
+ " but is " + actualNumericValue + ".",
Math.abs(expectedNumericValue - actualNumericValue) <= delta);
@@ -238,8 +237,7 @@ public class NetscapeCookieFileTest {
}
Set<HttpCookie> actualCookies = new NetscapeCookieFile(tmpFile,
creationDate).getCookies(true);
- Assert.assertThat(actualCookies,
- HttpCookiesMatcher.containsInOrder(cookies));
+ assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies));
}
@Test
@@ -259,8 +257,7 @@ public class NetscapeCookieFileTest {
NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate);
}
// compare original file with newly written one, they should not differ
- Assert.assertEquals(Files.readAllLines(tmpFile),
- Files.readAllLines(tmpFile2));
+ assertEquals(Files.readAllLines(tmpFile), Files.readAllLines(tmpFile2));
}
@Test
@@ -289,8 +286,7 @@ public class NetscapeCookieFileTest {
Set<HttpCookie> actualCookies = new NetscapeCookieFile(tmpFile, creationDate)
.getCookies(true);
- Assert.assertThat(actualCookies,
- HttpCookiesMatcher.containsInOrder(cookies));
+ assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies));
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index a80d8b3779..9b5691775f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -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;
/**
@@ -76,9 +76,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();
@After
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index 11ed8fdf0d..5c44c9c44d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
index 32dc7eb122..cec69c4998 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
@@ -11,12 +11,12 @@
package org.eclipse.jgit.lib;
import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
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.assertSame;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index b5ab9d2acd..054eb9c5ad 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
index b55c91f34f..965a2faf8e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
@@ -10,8 +10,8 @@
package org.eclipse.jgit.transport;
import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
index e16b84fec6..038ce717b3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
@@ -9,12 +9,13 @@
*/
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds;
+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.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -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
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java
index f15fa48644..cc910b3b9f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java
@@ -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 {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
index 7fe5b5981d..b84b6b2e0b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
@@ -9,6 +9,8 @@
*/
package org.eclipse.jgit.transport;
+import static org.hamcrest.MatcherAssert.assertThat;
+
import java.io.File;
import java.io.IOException;
import java.net.HttpCookie;
@@ -120,7 +122,7 @@ public class TransportHttpTest extends SampleDataRepositoryTestCase {
cookie.setMaxAge(1234);
expectedCookies.add(cookie);
- Assert.assertThat(
+ assertThat(
new NetscapeCookieFile(cookieFile.toPath())
.getCookies(true),
HttpCookiesMatcher.containsInOrder(expectedCookies, 5));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java
index 2c9712c996..2711762640 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java
@@ -9,10 +9,10 @@
*/
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.MoreAsserts.assertThrows;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
@@ -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;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java
index 99fe214cd1..37c87057dd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java
@@ -10,8 +10,8 @@
package org.eclipse.jgit.transport;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertThat;
import java.util.List;
import java.util.stream.Collectors;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 108e5edb78..ea86563da8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -1,6 +1,6 @@
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.MoreAsserts.assertThrows;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItems;
@@ -9,7 +9,7 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java
index f6dd9adc08..c9fd0c9b1c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java
@@ -9,11 +9,12 @@
*/
package org.eclipse.jgit.util;
+import static org.hamcrest.MatcherAssert.assertThat;
+
import java.util.LinkedHashMap;
import java.util.Map;
import org.hamcrest.collection.IsIterableContainingInOrder;
-import org.junit.Assert;
import org.junit.Test;
public class LRUMapTest {
@@ -38,8 +39,7 @@ public class LRUMapTest {
expectedMap.put(0, 0);
expectedMap.put(3, 3);
- Assert.assertThat(map.entrySet(),
- IsIterableContainingInOrder
- .contains(expectedMap.entrySet().toArray()));
+ assertThat(map.entrySet(), IsIterableContainingInOrder
+ .contains(expectedMap.entrySet().toArray()));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
index 7ea96dd9d7..1c2d8d7f65 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
@@ -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/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java
index 024f0f3b00..567880f478 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java
@@ -149,7 +149,9 @@ public class TimeoutOutputStreamTest {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- throw new InterruptedIOException();
+ InterruptedIOException e1 = new InterruptedIOException();
+ e1.initCause(e);
+ throw e1;
}
}
}
@@ -202,7 +204,9 @@ public class TimeoutOutputStreamTest {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- throw new InterruptedIOException();
+ InterruptedIOException e1 = new InterruptedIOException();
+ e1.initCause(e);
+ throw e1;
}
}
}