CommentsTest: Split testGetComment to 2 tests and use ExpectedException

The testGetComment method was testing the GetComment endpoint with two
cases: getting an existing comment and getting a non-existing comment.

Split it up into two separate tests, one for each case.

Remove the assertGetComment helper method, which was only used by the
testGetComment method. In the newly separated test for a non-existing
comment, use the ExpectedException rule instead.

Change-Id: I37d91508cbef103cc5530258cde1e32d36650994
This commit is contained in:
David Pursehouse
2015-06-02 17:51:00 +09:00
parent eabb396adb
commit c2fc22f650

View File

@@ -20,7 +20,6 @@ import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.fail;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
@@ -88,7 +87,9 @@ import org.easymock.IAnswer;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.PersonIdent;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import java.sql.Timestamp;
@@ -111,6 +112,9 @@ public class CommentsTest {
return NotesMigration.allEnabledConfig();
}
@Rule
public ExpectedException exception = ExpectedException.none();
private Injector injector;
private ReviewDb db;
private Project.NameKey project;
@@ -349,12 +353,19 @@ public class CommentsTest {
}
@Test
public void testGetComment() throws Exception {
public void testGetCommentExisting() throws Exception {
// test GetComment for existing comment
assertGetComment(revRes1, plc1, plc1.getKey().get());
String uuid = plc1.getKey().get();
CommentResource commentRes = comments.parse(revRes1, IdString.fromUrl(uuid));
CommentInfo actual = getComment.apply(commentRes);
assertComment(plc1, actual, true);
}
@Test
public void testGetCommentNotExisting() throws Exception {
// test GetComment for non-existent comment
assertGetComment(revRes1, null, "BadComment");
exception.expect(ResourceNotFoundException.class);
comments.parse(revRes1, IdString.fromUrl("BadComment"));
}
@Test
@@ -393,22 +404,6 @@ public class CommentsTest {
}};
}
private void assertGetComment(RevisionResource res, PatchLineComment expected,
String uuid) throws Exception {
try {
CommentResource commentRes = comments.parse(res, IdString.fromUrl(uuid));
if (expected == null) {
fail("Expected no comment");
}
CommentInfo actual = getComment.apply(commentRes);
assertComment(expected, actual, true);
} catch (ResourceNotFoundException e) {
if (expected != null) {
fail("Expected to find comment");
}
}
}
private void assertListComments(RevisionResource res,
Map<String, ? extends List<PatchLineComment>> expected) throws Exception {
assertCommentMap(comments.list().apply(res), expected, true);