DownloadTest: Use ExpectedException instead of try..catch..fail
Change-Id: I5547e64de6cea3d2200887b504245c69692f00b5 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
a7e20cc77f
commit
cc3cf93eee
|
@ -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.eclipse.jgit.util;version="[4.10.0,4.11.0)",
|
||||||
org.hamcrest.core;version="[1.1.0,2.0.0)",
|
org.hamcrest.core;version="[1.1.0,2.0.0)",
|
||||||
org.junit;version="[4.0.0,5.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.runner;version="[4.0.0,5.0.0)",
|
||||||
org.junit.runners;version="[4.0.0,5.0.0)"
|
org.junit.runners;version="[4.0.0,5.0.0)"
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
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.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -56,10 +55,15 @@
|
||||||
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";
|
||||||
|
@ -76,15 +80,12 @@ public void testDownloadInvalidPathInfo()
|
||||||
String TEXT = "test";
|
String TEXT = "test";
|
||||||
String id = putContent(TEXT).name().substring(0, 60);
|
String id = putContent(TEXT).name().substring(0, 60);
|
||||||
Path f = Paths.get(getTempDirectory().toString(), "download");
|
Path f = Paths.get(getTempDirectory().toString(), "download");
|
||||||
try {
|
|
||||||
getContent(id, f);
|
|
||||||
fail("expected RuntimeException");
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
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);
|
||||||
assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
|
exception.expect(RuntimeException.class);
|
||||||
e.getMessage());
|
exception.expectMessage(
|
||||||
}
|
formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
|
||||||
|
getContent(id, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,14 +94,11 @@ public void testDownloadInvalidId()
|
||||||
String TEXT = "test";
|
String TEXT = "test";
|
||||||
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");
|
||||||
try {
|
|
||||||
getContent(id, f);
|
|
||||||
fail("expected RuntimeException");
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
String error = String.format("Invalid id: : %s", id);
|
String error = String.format("Invalid id: : %s", id);
|
||||||
assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error),
|
exception.expect(RuntimeException.class);
|
||||||
e.getMessage());
|
exception.expectMessage(
|
||||||
}
|
formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error));
|
||||||
|
getContent(id, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -109,14 +107,10 @@ public void testDownloadNotFound()
|
||||||
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");
|
||||||
try {
|
|
||||||
getContent(id, f);
|
|
||||||
fail("expected RuntimeException");
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
String error = String.format("Object '%s' not found", id.getName());
|
String error = String.format("Object '%s' not found", id.getName());
|
||||||
assertEquals(formatErrorMessage(SC_NOT_FOUND, error),
|
exception.expect(RuntimeException.class);
|
||||||
e.getMessage());
|
exception.expectMessage(formatErrorMessage(SC_NOT_FOUND, error));
|
||||||
}
|
getContent(id, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
|
|
Loading…
Reference in New Issue