diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java index a43747771c..c046056711 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java @@ -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> expected) throws Exception { assertCommentMap(comments.list().apply(res), expected, true);