Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d63cb29ea48228f2aaa13021bf054eafda46e279 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
/*******************************************************************************
 *  Copyright (c) 2011 Christian Trutz
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *    Christian Trutz - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.egit.github.core.Comment;
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.IssueEvent;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.RepositoryIssue;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
import org.eclipse.egit.github.core.client.GitHubResponse;
import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.service.IssueService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

/**
 * Unit tests of {@link IssueService}
 */
@RunWith(MockitoJUnitRunner.class)
public class IssueServiceTest {

	@Mock
	private GitHubClient gitHubClient;

	@Mock
	private GitHubResponse response;

	private IssueService issueService;

	/**
	 * Test case set up
	 *
	 * @throws IOException
	 */
	@Before
	public void before() throws IOException {
		doReturn(response).when(gitHubClient).get(any(GitHubRequest.class));
		issueService = new IssueService(gitHubClient);
	}

	/**
	 * Create issue service with null client
	 */
	@Test(expected = IllegalArgumentException.class)
	public void constructorNullArgument() {
		new IssueService(null);
	}

	/**
	 * Create issue service default constructor
	 */
	@Test
	public void defaultConstructor() {
		assertNotNull(new IssueService().getClient());
	}

	/**
	 * Get issue with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueNullUser() throws IOException {
		issueService.getIssue(null, "not null", "not null");
	}

	/**
	 * Get issue with null repository id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueNullRepositoryId() throws IOException {
		issueService.getIssue(null, 1);
	}

	/**
	 * Get issue with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueEmptyUser() throws IOException {
		issueService.getIssue("", "repo", "not null");
	}

	/**
	 * Get issue with null name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueNullRepositoryName() throws IOException {
		issueService.getIssue("not null", null, "not null");
	}

	/**
	 * Get issue with empty name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueEmptyRepositoryName() throws IOException {
		issueService.getIssue("user", "", "not null");
	}

	/**
	 * Get issue with null id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueNullId() throws IOException {
		issueService.getIssue("not null", "not null", null);
	}

	/**
	 * Get issue with empty id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssueEmptyId() throws IOException {
		issueService.getIssue("not null", "not null", "");
	}

	/**
	 * Get issue with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssue() throws IOException {
		issueService.getIssue("tu", "tr", 3);
		GitHubRequest request = new GitHubRequest();
		request.setUri("/repos/tu/tr/issues/3");
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issue with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssueWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.getIssue(id, 3);
		GitHubRequest request = new GitHubRequest();
		request.setUri("/repos/tu/tr/issues/3");
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issue comments with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsNullUser() throws IOException {
		issueService.getComments(null, "not null", 1);
	}

	/**
	 * Get issue comments with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsEmptyUser() throws IOException {
		issueService.getComments("", "not null", 2);
	}

	/**
	 * Get issue comments with null name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsNullRepositoryName() throws IOException {
		issueService.getComments("not null", null, 3);
	}

	/**
	 * Get issue comments with null repository id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsNullRepositoryId() throws IOException {
		issueService.getComments(null, 3);
	}

	/**
	 * Get issue comments with empty name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsEmptyRepositoryName() throws IOException {
		issueService.getComments("not null", "", 3);
	}

	/**
	 * Get issue comments with null issue id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsNullId() throws IOException {
		issueService.getComments("not null", "not null", null);
	}

	/**
	 * Get issue comments with empty issue id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getCommentsEmptyId() throws IOException {
		issueService.getComments("not null", "not null", "");
	}

	/**
	 * Get issue comments with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getComments() throws IOException {
		issueService.getComments("tu", "tr", 4);
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils.page("/repos/tu/tr/issues/4/comments"));
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issue comments with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getCommentsWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.getComments(id, 4);
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils.page("/repos/tu/tr/issues/4/comments"));
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issues with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssuesNullUser() throws IOException {
		issueService.getIssues(null, "not null", null);
	}

	/**
	 * Get issues with null repository id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssuesNullRepositoryId() throws IOException {
		issueService.getIssues(null, null);
	}

	/**
	 * Get issues with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssuesEmptyUser() throws IOException {
		issueService.getIssues("", "not null", null);
	}

	/**
	 * Get issues with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssuesNullRepositoryName() throws IOException {
		issueService.getIssues("not null", null, null);
	}

	/**
	 * Get issues with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getIssuesEmptyRepositoryName() throws IOException {
		issueService.getIssues("not null", "", null);
	}

	/**
	 * Get issues with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssues() throws IOException {
		issueService.getIssues("tu", "tr", null);
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils.page("/repos/tu/tr/issues"));
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issues with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssuesRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.getIssues(id, null);
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils.page("/repos/tu/tr/issues"));
		verify(gitHubClient).get(request);
	}

	/**
	 * Create issue with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createIssueNullUser() throws IOException {
		issueService.createIssue(null, "not null", new Issue());
	}

	/**
	 * Create issue with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createIssueEmptyUser() throws IOException {
		issueService.createIssue("", "not null", new Issue());
	}

	/**
	 * Create issue with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createIssueNullRepositoryName() throws IOException {
		issueService.createIssue("not null", null, null);
	}

	/**
	 * Create issue with empty repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createIssueEmptyRepositoryName() throws IOException {
		issueService.createIssue("not null", "", new Issue());
	}

	/**
	 * Create issue with null issue
	 *
	 * @throws IOException
	 */
	@Test
	public void createIssueNullIssue() throws IOException {
		issueService.createIssue("test_user", "test_repository", null);
		verify(gitHubClient).post("/repos/test_user/test_repository/issues",
				new HashMap<String, String>(), Issue.class);
	}

	/**
	 * Create issue with null issue
	 *
	 * @throws IOException
	 */
	@Test
	public void createIssueNullIssueWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.createIssue(id, null);
		verify(gitHubClient).post("/repos/tu/tr/issues",
				new HashMap<String, String>(), Issue.class);
	}

	/**
	 * Edit issue with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueNullUser() throws IOException {
		issueService.editIssue(null, "not null", new Issue());
	}

	/**
	 * Edit issue with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueEmptyUser() throws IOException {
		issueService.editIssue("", "not null", new Issue());
	}

	/**
	 * Edit issue with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueNullRepositoryName() throws IOException {
		issueService.editIssue("not null", null, new Issue());
	}

	/**
	 * Edit issue with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueEmptyRepositoryName() throws IOException {
		issueService.editIssue("not null", "", new Issue());
	}

	/**
	 * Edit issue with null issue
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueNullIssue() throws IOException {
		issueService.editIssue("not null", "not null", null);
	}

	/**
	 * Edit issue with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void editIssue() throws IOException {
		Issue issue = new Issue();
		issue.setNumber(1);
		issue.setTitle("test_title");
		issue.setBody("test_body");
		issue.setState("test_state");
		issueService.editIssue("test_user", "test_repository", issue);

		Map<String, String> params = new HashMap<String, String>();
		params.put(IssueService.FIELD_TITLE, "test_title");
		params.put(IssueService.FIELD_BODY, "test_body");
		params.put(IssueService.FILTER_STATE, "test_state");
		verify(gitHubClient).post("/repos/test_user/test_repository/issues/1",
				params, Issue.class);
	}

	/**
	 * Edit issue with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void editIssueWithRepositoryId() throws IOException {
		Issue issue = new Issue();
		issue.setNumber(1);
		issue.setTitle("test_title");
		issue.setBody("test_body");
		issue.setState("test_state");
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.editIssue(id, issue);

		Map<String, String> params = new HashMap<String, String>();
		params.put(IssueService.FIELD_TITLE, "test_title");
		params.put(IssueService.FIELD_BODY, "test_body");
		params.put(IssueService.FILTER_STATE, "test_state");
		verify(gitHubClient).post("/repos/tu/tr/issues/1", params, Issue.class);
	}

	/**
	 * Create issue comment with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentNullUser() throws IOException {
		issueService.createComment(null, "not null", 1, "not null");
	}

	/**
	 * Create issue comment with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentEmptyUser() throws IOException {
		issueService.createComment("", "not null", 2, "not null");
	}

	/**
	 * Create issue comment with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentNullRepositoryName() throws IOException {
		issueService.createComment("not null", null, 3, "not null");
	}

	/**
	 * Create issue comment with empty repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentEmptyRepositoryName() throws IOException {
		issueService.createComment("not null", "", 4, "not null");
	}

	/**
	 * Create issue comment with null issue id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentNullIssueId() throws IOException {
		issueService.createComment("not null", "not null", null, "not null");
	}

	/**
	 * Create issue comment with empty issue id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createCommentEmptyIssueId() throws IOException {
		issueService.createComment("not null", "not null", "", "not null");
	}

	/**
	 * Create issue comment with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void createComment() throws IOException {
		issueService.createComment("test_user", "test_repository", 1,
				"test_comment");

		Map<String, String> params = new HashMap<String, String>();
		params.put(IssueService.FIELD_BODY, "test_comment");
		verify(gitHubClient).post(
				"/repos/test_user/test_repository/issues/1/comments", params,
				Comment.class);
	}

	/**
	 * Create issue comment with valid parameters
	 *
	 * @throws IOException
	 */
	@Test
	public void createCommentWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("tu", "tr");
		issueService.createComment(id, 1, "test_comment");

		Map<String, String> params = new HashMap<String, String>();
		params.put(IssueService.FIELD_BODY, "test_comment");
		verify(gitHubClient).post("/repos/tu/tr/issues/1/comments", params,
				Comment.class);
	}

	/**
	 * Delete comment with null user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentNullUser() throws IOException {
		issueService.deleteComment(null, "repo", 1);
	}

	/**
	 * Delete comment with empty user
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentEmptyUser() throws IOException {
		issueService.deleteComment("", "repo", 1);
	}

	/**
	 * Delete comment with null repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentNullRepositoryName() throws IOException {
		issueService.deleteComment("user", null, 1);
	}

	/**
	 * Delete comment with empty repository name
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentEmptyRepositoryName() throws IOException {
		issueService.deleteComment("user", "", 1);
	}

	/**
	 * Delete comment with null comment id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentNullId() throws IOException {
		issueService.deleteComment("user", "repo", null);
	}

	/**
	 * Delete comment with empty comment id
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void deleteCommentEmptyId() throws IOException {
		issueService.deleteComment("user", "repo", "");
	}

	/**
	 * Delete issue comment
	 *
	 * @throws IOException
	 */
	@Test
	public void deleteComment() throws IOException {
		issueService.deleteComment("user", "repo", 1);
		verify(gitHubClient).delete("/repos/user/repo/issues/comments/1");
	}

	/**
	 * Delete issue comment
	 *
	 * @throws IOException
	 */
	@Test
	public void deleteCommentWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.deleteComment(id, 1);
		verify(gitHubClient).delete("/repos/user/repo/issues/comments/1");
	}

	/**
	 * Page issues for current user
	 *
	 * @throws IOException
	 */
	@Test
	public void pageIssues() throws IOException {
		PageIterator<RepositoryIssue> iterator = issueService.pageIssues();
		assertNotNull(iterator);
		assertTrue(iterator.hasNext());
		assertEquals(Utils.page("/issues"), iterator.getRequest().generateUri());
	}

	/**
	 * Page issues for repository
	 *
	 * @throws IOException
	 */
	@Test
	public void pageRepsitoryIssues() throws IOException {
		PageIterator<Issue> iterator = issueService.pageIssues("user", "repo");
		assertNotNull(iterator);
		assertTrue(iterator.hasNext());
		assertEquals(Utils.page("/repos/user/repo/issues"), iterator
				.getRequest().generateUri());
	}

	/**
	 * Page issues for repository
	 *
	 * @throws IOException
	 */
	@Test
	public void pageRepsitoryIssuesWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		PageIterator<Issue> iterator = issueService.pageIssues(id);
		assertNotNull(iterator);
		assertTrue(iterator.hasNext());
		assertEquals(Utils.page("/repos/user/repo/issues"), iterator
				.getRequest().generateUri());
	}

	/**
	 * Get issues for current user
	 *
	 * @throws IOException
	 */
	@Test
	public void getCurrentUserIssues() throws IOException {
		List<RepositoryIssue> issues = issueService.getIssues();
		assertNotNull(issues);
		assertTrue(issues.isEmpty());
	}

	/**
	 * Page all issue events for repository
	 *
	 * @throws IOException
	 */
	@Test
	public void pageEvents() throws IOException {
		PageIterator<IssueEvent> iter = issueService.pageEvents("user", "repo");
		assertNotNull(iter);
		assertTrue(iter.hasNext());
		assertEquals(Utils.page("/repos/user/repo/issues/events"), iter
				.getRequest().generateUri());
	}

	/**
	 * Page issue events for repository
	 *
	 * @throws IOException
	 */
	@Test
	public void pageIssueEvents() throws IOException {
		PageIterator<IssueEvent> iter = issueService.pageIssueEvents("user",
				"repo", 16);
		assertNotNull(iter);
		assertTrue(iter.hasNext());
		assertEquals(Utils.page("/repos/user/repo/issues/16/events"), iter
				.getRequest().generateUri());
	}

	/**
	 * Get issue event
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssueEvent() throws IOException {
		issueService.getIssueEvent("user", "repo", 4399);
		GitHubRequest request = new GitHubRequest();
		request.setUri("/repos/user/repo/issues/events/4399");
		verify(gitHubClient).get(request);
	}

	/**
	 * Get issue comment
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssueComment() throws IOException {
		issueService.getComment("user", "repo", 38);
		GitHubRequest request = new GitHubRequest();
		request.setUri("/repos/user/repo/issues/comments/38");
		verify(gitHubClient).get(request);
	}

	/**
	 * Edit issue comment with null comment
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void editIssueCommentNullComment() throws IOException {
		issueService.editComment("user", "repo", null);
	}

	/**
	 * Edit issue comment
	 *
	 * @throws IOException
	 */
	@Test
	public void editIssueComment() throws IOException {
		Comment comment = new Comment().setId(29).setBody("new body");
		issueService.editComment("user", "repo", comment);
		verify(gitHubClient).post("/repos/user/repo/issues/comments/29",
				comment, Comment.class);
	}

	/**
	 * Edit issue comment
	 *
	 * @throws IOException
	 */
	@Test
	public void editIssueCommentWithRepositoryId() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		Comment comment = new Comment().setId(44).setBody("new body");
		issueService.editComment(id, comment);
		verify(gitHubClient).post("/repos/user/repo/issues/comments/44",
				comment, Comment.class);
	}

	/**
	 * Search issues with null repository
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void searchIssuesNullRepository() throws IOException {
		issueService.searchIssues(null, "open", "test");
	}

	/**
	 * Search issues with null query
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void searchIssueNullQuery() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, "open", null);
	}

	/**
	 * Search issues with empty query
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void searchIssueEmptyQuery() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, "open", "");
	}

	/**
	 * Search issues with null state
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void searchIssueNullState() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, null, "test");
	}

	/**
	 * Search issues with empty state
	 *
	 * @throws IOException
	 */
	@Test(expected = IllegalArgumentException.class)
	public void searchIssueEmptyState() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, "", "test");
	}

	/**
	 * Search issues
	 *
	 * @throws IOException
	 */
	@Test
	public void searchIssues() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, "closed", "test");
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils
				.page("/legacy/issues/search/user/repo/closed/test"));
		verify(gitHubClient).get(request);
	}

	/**
	 * Search issues with query that needs escaping
	 *
	 * @throws IOException
	 */
	@Test
	public void searchEscaped() throws IOException {
		RepositoryId id = new RepositoryId("user", "repo");
		issueService.searchIssues(id, "open", "a and a.");
		GitHubRequest request = new GitHubRequest();
		request.setUri(Utils
				.page("/legacy/issues/search/user/repo/open/a%20and%20a%2E"));
		verify(gitHubClient).get(request);
	}
}

Back to the top