summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 08:42:39 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 20:02:59 +0900
commitcc3cf93eee8a216852179e05330b6c092751ae00 (patch)
tree48a9e2f5c13851fc6921da2783e5fb71759fd09a
parenta7e20cc77fba99bf7243d1c0a48082a6a7398fa8 (diff)
downloadjgit-cc3cf93eee8a216852179e05330b6c092751ae00.tar.gz
jgit-cc3cf93eee8a216852179e05330b6c092751ae00.zip
DownloadTest: Use ExpectedException instead of try..catch..fail
Change-Id: I5547e64de6cea3d2200887b504245c69692f00b5 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java46
2 files changed, 21 insertions, 26 deletions
diff --git a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
index 60d50f6198..9d4181fb9a 100644
--- a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
@@ -34,5 +34,6 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)",
org.eclipse.jgit.util;version="[4.10.0,4.11.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.0.0,5.0.0)",
+ org.junit.rules;version="[4.11.0,5.0.0)",
org.junit.runner;version="[4.0.0,5.0.0)",
org.junit.runners;version="[4.0.0,5.0.0)"
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
index 69d1a04801..0f7004b5c4 100644
--- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
@@ -45,7 +45,6 @@ package org.eclipse.jgit.lfs.server.fs;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Path;
@@ -56,10 +55,15 @@ import org.apache.http.client.ClientProtocolException;
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
import org.eclipse.jgit.util.FileUtils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class DownloadTest extends LfsServerTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
@Test
public void testDownload() throws Exception {
String TEXT = "test";
@@ -76,15 +80,12 @@ public class DownloadTest extends LfsServerTest {
String TEXT = "test";
String id = putContent(TEXT).name().substring(0, 60);
Path f = Paths.get(getTempDirectory().toString(), "download");
- try {
- getContent(id, f);
- fail("expected RuntimeException");
- } catch (RuntimeException e) {
- String error = String.format(
- "Invalid pathInfo '/%s' does not match '/{SHA-256}'", id);
- assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
- e.getMessage());
- }
+ String error = String.format(
+ "Invalid pathInfo '/%s' does not match '/{SHA-256}'", id);
+ exception.expect(RuntimeException.class);
+ exception.expectMessage(
+ formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
+ getContent(id, f);
}
@Test
@@ -93,14 +94,11 @@ public class DownloadTest extends LfsServerTest {
String TEXT = "test";
String id = putContent(TEXT).name().replace('f', 'z');
Path f = Paths.get(getTempDirectory().toString(), "download");
- try {
- getContent(id, f);
- fail("expected RuntimeException");
- } catch (RuntimeException e) {
- String error = String.format("Invalid id: : %s", id);
- assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
- e.getMessage());
- }
+ String error = String.format("Invalid id: : %s", id);
+ exception.expect(RuntimeException.class);
+ exception.expectMessage(
+ formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
+ getContent(id, f);
}
@Test
@@ -109,14 +107,10 @@ public class DownloadTest extends LfsServerTest {
String TEXT = "test";
AnyLongObjectId id = LongObjectIdTestUtils.hash(TEXT);
Path f = Paths.get(getTempDirectory().toString(), "download");
- try {
- getContent(id, f);
- fail("expected RuntimeException");
- } catch (RuntimeException e) {
- String error = String.format("Object '%s' not found", id.getName());
- assertEquals(formatErrorMessage(SC_NOT_FOUND, error),
- e.getMessage());
- }
+ String error = String.format("Object '%s' not found", id.getName());
+ exception.expect(RuntimeException.class);
+ exception.expectMessage(formatErrorMessage(SC_NOT_FOUND, error));
+ getContent(id, f);
}
@SuppressWarnings("boxing")