@Test
  public void testRemoveSubTasks() throws Exception {
    setUpIssue();
    final AtomicInteger deleteIssueCalled = new AtomicInteger(0);
    DefaultIssueDeleteHelper tested = newMockDeleteIssueHelper(deleteIssueCalled);

    final MockGenericValue subTask1 =
        createIssueGV(2L, PROJECT_ID, "sub task 1", "TST-10", null, null);
    final MutableIssue subTaskIssue1 = createNiceMock(MutableIssue.class);
    expect(subTaskIssue1.getId()).andReturn(2L).anyTimes();
    expect(subTaskIssue1.getGenericValue()).andReturn(subTask1).anyTimes();
    final MockGenericValue subTask2 =
        createIssueGV(3L, PROJECT_ID, "sub task 2", "TST-11", null, null);
    final MutableIssue subTaskIssue2 = createNiceMock(MutableIssue.class);
    expect(subTaskIssue2.getId()).andReturn(3L).anyTimes();
    expect(subTaskIssue2.getGenericValue()).andReturn(subTask2).anyTimes();

    replay(subTaskIssue1, subTaskIssue2);
    expect(mockIssueManager.getIssueObject(2L)).andReturn(subTaskIssue1);
    expect(mockIssueManager.getIssueObject(3L)).andReturn(subTaskIssue2);

    final MockGenericValue mockLinkGV1 =
        new DbIndependentMockGenericValue(
            "IssueLink", ImmutableMap.<String, Object>of("destination", 2L));
    final IssueLink issueLink1 = new IssueLink(mockLinkGV1, null, mockIssueManager);
    final MockGenericValue mockLinkGV2 =
        new DbIndependentMockGenericValue(
            "IssueLink", ImmutableMap.<String, Object>of("destination", 3L));
    final IssueLink issueLink2 = new IssueLink(mockLinkGV2, null, mockIssueManager);
    expect(mockSubTaskManager.getSubTaskIssueLinks(ISSUE_ID))
        .andReturn(ImmutableList.of(issueLink1, issueLink2));

    replayMocks();

    tested.removeSubTasks(null, issue, EventDispatchOption.ISSUE_DELETED, true);

    assertEquals(2, deleteIssueCalled.get());
    verifyMocks();
  }
 private void defaultSubtaskSetup() {
   expect(mockSubTaskManager.getSubTaskIssueLinks(ISSUE_ID))
       .andReturn(Collections.<IssueLink>emptyList());
 }