1818import de .linsin .github .rest .domain .Issue ;
1919import de .linsin .github .rest .resource .IssueResponse ;
2020import de .linsin .github .rest .resource .IssuesResponse ;
21+ import de .linsin .github .rest .resource .CommentIssueResponse ;
2122import de .linsin .github .rest .domain .Repository ;
23+ import de .linsin .github .rest .domain .Comment ;
2224import static org .easymock .classextension .EasyMock .*;
2325import static org .easymock .EasyMock .eq ;
2426import org .junit .After ;
@@ -253,10 +255,7 @@ public void reopen_issue_null_repo_passed() {
253255
254256 @ Test
255257 public void edit_issue () {
256- Issue issue = new Issue ();
257- issue .setNumber (1 );
258- issue .setTitle ("test" );
259- issue .setBody ("test body" );
258+ Issue issue = setupTestIssue ();
260259 Repository repo = setupTestRepo ();
261260 IssueResponse response = new IssueResponse ();
262261 response .setIssue (issue );
@@ -267,6 +266,14 @@ public void edit_issue() {
267266 verify (mockRestTemplate );
268267 }
269268
269+ private Issue setupTestIssue () {
270+ Issue issue = new Issue ();
271+ issue .setNumber (1 );
272+ issue .setTitle ("test" );
273+ issue .setBody ("test body" );
274+ return issue ;
275+ }
276+
270277 @ Test (expected = IllegalArgumentException .class )
271278 public void edit_issue_no_number_in_issue () {
272279 classUnderTest .edit (setupTestRepo (), new Issue ());
@@ -294,13 +301,66 @@ public void edit_issue_null_issue_passed() {
294301
295302 @ Test (expected = NullPointerException .class )
296303 public void edit_issue_null_repo_passed () {
297- Issue issue = new Issue ();
298- issue .setNumber (1 );
299- issue .setTitle ("test" );
300- issue .setBody ("test body" );
304+ Issue issue = setupTestIssue ();
301305 classUnderTest .edit (null , issue );
302306 }
303307
308+ @ Test
309+ public void comment_issue () {
310+ Repository repo = setupTestRepo ();
311+ Issue issue = setupTestIssue ();
312+ Comment comment = new Comment ();
313+ comment .setComment ("hello moto" );
314+
315+ CommentIssueResponse response = new CommentIssueResponse ();
316+ response .setComment (comment );
317+ expect (mockRestTemplate .postForObject (eq (IssueBrowser .COMMENT_ISSUE_URL ), anyObject (), eq (CommentIssueResponse .class ), eq (repo .getOwner ()),
318+ eq (repo .getName ()), eq (String .valueOf (issue .getNumber ())))).andReturn (response );
319+ replay (mockRestTemplate );
320+ assertNotNull (classUnderTest .comment (repo , issue , comment ));
321+ verify (mockRestTemplate );
322+ }
323+
324+ @ Test (expected = IllegalArgumentException .class )
325+ public void comment_issue_no_number_in_issue () {
326+ Repository repo = setupTestRepo ();
327+ Issue issue = new Issue ();
328+ Comment comment = new Comment ();
329+ comment .setComment ("hello moto" );
330+ classUnderTest .comment (repo , issue , comment );
331+ }
332+
333+ @ Test (expected = IllegalArgumentException .class )
334+ public void comment_issue_no_comment_text () {
335+ Repository repo = setupTestRepo ();
336+ Issue issue = setupTestIssue ();
337+ Comment comment = new Comment ();
338+ classUnderTest .comment (repo , issue , comment );
339+ }
340+
341+ @ Test (expected = NullPointerException .class )
342+ public void comment_issue_null_repo_passed () {
343+ Issue issue = setupTestIssue ();
344+ Comment comment = new Comment ();
345+ comment .setComment ("hello moto" );
346+ classUnderTest .comment (null , issue , comment );
347+ }
348+
349+ @ Test (expected = NullPointerException .class )
350+ public void comment_issue_null_issue_passed () {
351+ Repository repo = setupTestRepo ();
352+ Comment comment = new Comment ();
353+ comment .setComment ("hello moto" );
354+ classUnderTest .comment (repo , null , comment );
355+ }
356+
357+ @ Test (expected = NullPointerException .class )
358+ public void comment_issue_null_comment_passed () {
359+ Repository repo = setupTestRepo ();
360+ Issue issue = setupTestIssue ();
361+ classUnderTest .comment (repo , issue , null );
362+ }
363+
304364 private Repository setupTestRepo () {
305365 Repository repo = new Repository ();
306366 repo .setName ("area51" );
0 commit comments