1
0
Fork 0

Implemented delete issue. Added Mockito dependency for test.

master
Andrey Kuzmin 2016-03-15 22:18:06 +03:00 committed by Bob Carroll
parent 3e557c9f5d
commit e2781229db
4 changed files with 36 additions and 8 deletions

View File

@ -5,3 +5,4 @@ Javier Molina <javinovich@gmail.com> @javinovich
Joseph McCarthy <luckymikuhatsune@gmail.com>
Magnus Lundberg <ludde89l@gmail.com>
Anders Kreinøe <anders@kreinoee.dk> @Kreinoee
Andrey Kuzmin <agkoozmin@gmail.com> @nach-o-man

View File

@ -85,6 +85,5 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,7 @@
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll (bob.carroll@alum.rit.edu)
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@ -876,7 +876,7 @@ public class Issue extends Resource {
restclient);
if (projects.isEmpty() || projects.get(0).getIssueTypes().isEmpty())
throw new JiraException("Project '"+ project + "' or issue type '" + issueType +
throw new JiraException("Project '"+ project + "' or issue type '" + issueType +
"' missing from create metadata. Do you have enough permissions?");
return projects.get(0).getIssueTypes().get(0).getFields();
@ -947,7 +947,7 @@ public class Issue extends Resource {
throw new JiraException("Failed add attachment to issue " + key, ex);
}
}
/**
* Adds a remote link to this issue.
*
@ -1248,7 +1248,7 @@ public class Issue extends Resource {
* <li>summary,comment - include just the summary and comments</li>
* <li>*all,-comment - include all fields</li>
* </ul>
*
*
* @param expand fields to expand when obtaining the issue
*
* @return an issue instance
@ -1329,10 +1329,10 @@ public class Issue extends Resource {
* <li>summary,comment - include just the summary and comments</li>
* <li>*all,-comment - include all fields</li>
* </ul>
*
*
* @param maxResults if non-<code>null</code>, defines the maximum number of
* results that can be returned
*
*
* @param startAt if non-<code>null</code>, defines the first issue to
* return
*
@ -1611,7 +1611,7 @@ public class Issue extends Resource {
public User getReporter() {
return reporter;
}
public List<RemoteLink> getRemoteLinks() throws JiraException {
JSONArray obj;
try {
@ -1696,5 +1696,17 @@ public class Issue extends Resource {
return updatedDate;
}
public boolean delete(final boolean deleteSubtasks) throws JiraException {
boolean result;
try {
URI uri = restclient.buildURI(getBaseUri() + "issue/" + this.key, new HashMap<String, String>() {{
put("deleteSubtasks", String.valueOf(deleteSubtasks));
}});
result = (restclient.delete(uri) == null);
} catch (Exception ex) {
throw new JiraException("Failed to delete issue " + key, ex);
}
return result;
}
}

View File

@ -5,6 +5,7 @@ import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
@ -16,6 +17,9 @@ import org.joda.time.DateTimeZone;
import org.junit.Assert;
import org.junit.Test;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
public class IssueTest {
/**
@ -199,4 +203,16 @@ public class IssueTest {
}
/**
* false is bu default so we test positive case only
*/
@Test
public void testDelete() throws Exception {
RestClient restClient = mock(RestClient.class);
URI uri = new URI("DUMMY");
when(restClient.buildURI(anyString(), any(Map.class))).thenReturn(uri);
when(restClient.delete(eq(uri))).thenReturn(null);
Issue issue = new Issue(restClient, Utils.getTestIssue());
Assert.assertTrue(issue.delete(true));
}
}