1313import com .atlassian .jira .user .ApplicationUser ;
1414import com .atlassian .jira .user .util .UserManager ;
1515import com .google .common .collect .ArrayListMultimap ;
16+ import de .codescape .jira .plugins .multiplesubtasks .model .CreatedSubtask ;
1617import de .codescape .jira .plugins .multiplesubtasks .model .Markers ;
1718import de .codescape .jira .plugins .multiplesubtasks .model .Subtask ;
1819import de .codescape .jira .plugins .multiplesubtasks .service .syntax .EstimateStringService ;
3132
3233import static de .codescape .jira .plugins .multiplesubtasks .model .Markers .CURRENT_MARKER ;
3334import static de .codescape .jira .plugins .multiplesubtasks .model .Markers .INHERIT_MARKER ;
35+ import static org .hamcrest .CoreMatchers .equalTo ;
36+ import static org .hamcrest .CoreMatchers .is ;
37+ import static org .hamcrest .MatcherAssert .assertThat ;
3438import static org .junit .Assert .fail ;
3539import static org .mockito .ArgumentMatchers .eq ;
3640import static org .mockito .Mockito .*;
@@ -229,7 +233,7 @@ public void shouldAllowToInheritPriorityExplicitly() {
229233 when (subtaskRequest .getSummary ()).thenReturn ("Inherit priority please" );
230234 when (subtaskRequest .getPriority ()).thenReturn (INHERIT_MARKER );
231235 subtasksRequest .add (subtaskRequest );
232- expectSubtasks (subtasksRequest );
236+ expectSubtasksFromInputString (subtasksRequest );
233237
234238 MutableIssue subtask = expectNewSubtaskIssue ();
235239
@@ -250,7 +254,7 @@ public void shouldAllowToInheritReporterFromParent() {
250254 when (subtaskRequest .getSummary ()).thenReturn ("Inherit reporter please" );
251255 when (subtaskRequest .getReporter ()).thenReturn (INHERIT_MARKER );
252256 subtasksRequest .add (subtaskRequest );
253- expectSubtasks (subtasksRequest );
257+ expectSubtasksFromInputString (subtasksRequest );
254258
255259 ApplicationUser reporter = mock (ApplicationUser .class );
256260 when (parent .getReporter ()).thenReturn (reporter );
@@ -269,7 +273,7 @@ public void shouldAllowToSetCurrentUserAsReporterExplicitly() {
269273 when (subtaskRequest .getSummary ()).thenReturn ("Inherit reporter please" );
270274 when (subtaskRequest .getReporter ()).thenReturn (CURRENT_MARKER );
271275 subtasksRequest .add (subtaskRequest );
272- expectSubtasks (subtasksRequest );
276+ expectSubtasksFromInputString (subtasksRequest );
273277
274278 MutableIssue subtask = expectNewSubtaskIssue ();
275279
@@ -285,7 +289,7 @@ public void shouldAllowToSetUserAsReporter() {
285289 when (subtaskRequest .getSummary ()).thenReturn ("Inherit reporter please" );
286290 when (subtaskRequest .getReporter ()).thenReturn ("codescape" );
287291 subtasksRequest .add (subtaskRequest );
288- expectSubtasks (subtasksRequest );
292+ expectSubtasksFromInputString (subtasksRequest );
289293
290294 ApplicationUser explicitUser = mock (ApplicationUser .class );
291295 when (userManager .getUserByName ("codescape" )).thenReturn (explicitUser );
@@ -304,7 +308,7 @@ public void shouldFallBackToCurrentUserAsReporterIfCustomUserDoesNotExist() {
304308 when (subtaskRequest .getSummary ()).thenReturn ("Inherit reporter please" );
305309 when (subtaskRequest .getReporter ()).thenReturn ("unknown" );
306310 subtasksRequest .add (subtaskRequest );
307- expectSubtasks (subtasksRequest );
311+ expectSubtasksFromInputString (subtasksRequest );
308312
309313 MutableIssue subtask = expectNewSubtaskIssue ();
310314
@@ -323,7 +327,7 @@ public void shouldAddKnownWatcher() throws Exception {
323327 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
324328 attributes .put (Subtask .Attributes .WATCHER , "known.user" );
325329 subtasks .add (new Subtask (attributes ));
326- expectSubtasks (subtasks );
330+ expectSubtasksFromInputString (subtasks );
327331
328332 // expect subtask to be created
329333 MutableIssue subtask = expectNewSubtaskIssue ();
@@ -349,7 +353,7 @@ public void shouldIgnoreUnknownWatchers() throws Exception {
349353 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
350354 attributes .put (Subtask .Attributes .WATCHER , "unknown.user" );
351355 subtasks .add (new Subtask (attributes ));
352- expectSubtasks (subtasks );
356+ expectSubtasksFromInputString (subtasks );
353357
354358 // expect subtask to be created
355359 MutableIssue subtask = expectNewSubtaskIssue ();
@@ -372,7 +376,7 @@ public void shouldUseCurrentUserAsWatcher() throws Exception {
372376 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
373377 attributes .put (Subtask .Attributes .WATCHER , Markers .CURRENT_MARKER );
374378 subtasks .add (new Subtask (attributes ));
375- expectSubtasks (subtasks );
379+ expectSubtasksFromInputString (subtasks );
376380
377381 // expect subtask to be created
378382 MutableIssue subtask = expectNewSubtaskIssue ();
@@ -396,7 +400,7 @@ public void shouldSetEstimateAndOriginalEstimateIfValidEstimateIsProvidedForSubt
396400 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
397401 attributes .put (Subtask .Attributes .ESTIMATE , "4d" );
398402 subtasks .add (new Subtask (attributes ));
399- expectSubtasks (subtasks );
403+ expectSubtasksFromInputString (subtasks );
400404
401405 // expect estimate service to resolve the long value
402406 when (estimateStringService .estimateStringToSeconds (eq ("4d" ))).thenReturn (999L );
@@ -418,7 +422,7 @@ public void shouldInheritEstimateFromParentIssue() {
418422 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
419423 attributes .put (Subtask .Attributes .ESTIMATE , INHERIT_MARKER );
420424 subtasks .add (new Subtask (attributes ));
421- expectSubtasks (subtasks );
425+ expectSubtasksFromInputString (subtasks );
422426
423427 Long parentEstimate = 42L ;
424428 when (parent .getEstimate ()).thenReturn (parentEstimate );
@@ -442,7 +446,7 @@ public void shouldNotSetEstimateWhenInheritEstimateFromParentIssueWithoutEstimat
442446 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
443447 attributes .put (Subtask .Attributes .ESTIMATE , INHERIT_MARKER );
444448 subtasks .add (new Subtask (attributes ));
445- expectSubtasks (subtasks );
449+ expectSubtasksFromInputString (subtasks );
446450
447451 when (parent .getEstimate ()).thenReturn (null );
448452
@@ -453,8 +457,30 @@ public void shouldNotSetEstimateWhenInheritEstimateFromParentIssueWithoutEstimat
453457 verify (subtask , times (0 )).setEstimate (anyLong ());
454458 }
455459
460+ /* multiple tasks */
461+
462+ @ Test
463+ public void shouldCreateMultipleTasks () {
464+ expectSubtasksFromInputString (randomSubtasks (100 ));
465+ expectNewSubtaskIssue ();
466+
467+ List <CreatedSubtask > createdSubtasks = subtasksCreationService .subtasksFromString (ISSUE_KEY , INPUT_STRING );
468+
469+ assertThat (createdSubtasks .size (), is (equalTo ((100 ))));
470+ }
471+
456472 /* helpers */
457473
474+ private List <Subtask > randomSubtasks (int numberOfSubtasks ) {
475+ ArrayList <Subtask > subtasks = new ArrayList <>();
476+ for (int j = 0 ; j <numberOfSubtasks ; j ++) {
477+ ArrayListMultimap <String , String > attributes = ArrayListMultimap .create ();
478+ attributes .put (Subtask .Attributes .SUMMARY , "random " + j +" of " + numberOfSubtasks );
479+ subtasks .add (new Subtask (attributes ));
480+ }
481+ return subtasks ;
482+ }
483+
458484 private void expectParentWithSummary (String summary ) {
459485 when (parent .getSummary ()).thenReturn (summary );
460486 }
@@ -464,7 +490,7 @@ private void expectSubtaskWithSummary(String summary) {
464490 ArrayListMultimap <String , String > attributes = ArrayListMultimap .create ();
465491 attributes .put (Subtask .Attributes .SUMMARY , summary );
466492 subtasks .add (new Subtask (attributes ));
467- expectSubtasks (subtasks );
493+ expectSubtasksFromInputString (subtasks );
468494 }
469495
470496 private void expectSubtaskWithDescription (String description ) {
@@ -473,10 +499,10 @@ private void expectSubtaskWithDescription(String description) {
473499 attributes .put (Subtask .Attributes .SUMMARY , "a task" );
474500 attributes .put (Subtask .Attributes .DESCRIPTION , description );
475501 subtasks .add (new Subtask (attributes ));
476- expectSubtasks (subtasks );
502+ expectSubtasksFromInputString (subtasks );
477503 }
478504
479- private void expectSubtasks (List <Subtask > subtasks ) {
505+ private void expectSubtasksFromInputString (List <Subtask > subtasks ) {
480506 when (subtasksSyntaxService .parseString (eq (INPUT_STRING ))).thenReturn (subtasks );
481507 }
482508
0 commit comments