1
0
Fork 0

Merge pull request #118 from mikulucky/master

Changed Version merge and copy methods to throw a JiraException
master
Bob Carroll 2016-03-09 07:41:24 -08:00
commit eb0c510ed5
15 changed files with 528 additions and 68 deletions

View File

@ -2,3 +2,4 @@ Bob Carroll <bob.carroll@alum.rit.edu> @rcarz
Kyle Chaplin <chaplinkyle@gmail.com> @chaplinkyle
Alesandro Lang <info@alesandro-lang.com> @alesandroLang
Javier Molina <javinovich@gmail.com> @javinovich
Joseph McCarthy <luckymikuhatsune@gmail.com>

15
pom.xml
View File

@ -71,5 +71,20 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -19,10 +19,7 @@
package net.rcarz.jiraclient;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import java.util.List;
import java.util.Map;
/**

View File

@ -160,7 +160,7 @@ public class Version extends Resource {
* @param version
* The version to merge
*/
public void mergeWith(Version version) {
public void mergeWith(Version version) throws JiraException {
JSONObject req = new JSONObject();
req.put("description", version.getDescription());
@ -172,7 +172,7 @@ public class Version extends Resource {
try {
restclient.put(Resource.getBaseUri() + "version/" + id, req);
} catch (Exception ex) {
throw new RuntimeException("Failed to merge", ex);
throw new JiraException("Failed to merge", ex);
}
}
@ -182,7 +182,7 @@ public class Version extends Resource {
* @param project
* The project the version will be copied to
*/
public void copyTo(Project project) {
public void copyTo(Project project) throws JiraException {
JSONObject req = new JSONObject();
req.put("description", getDescription());
@ -196,7 +196,7 @@ public class Version extends Resource {
try {
restclient.post(Resource.getBaseUri() + "version/", req);
} catch (Exception ex) {
throw new RuntimeException("Failed to copy to project '" + project.getKey() + "'", ex);
throw new JiraException("Failed to copy to project '" + project.getKey() + "'", ex);
}
}

View File

@ -29,7 +29,6 @@ import java.util.Map;
*/
public class Votes extends Resource {
private String name = null;
private int votes = 0;
private boolean hasVoted = false;

View File

@ -19,6 +19,7 @@
package net.rcarz.jiraclient;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

View File

@ -2,9 +2,13 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertSame;
import static org.mockito.Matchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
public class IssueTypeTest {
@ -25,6 +29,46 @@ public class IssueTypeTest {
assertEquals(issueType.getDescription(), "This is a test issue type.");
}
@Test
public void testFields() throws Exception {
final JSONObject testJSON = getTestJSON();
final JSONObject fields = new JSONObject();
fields.put("key1","key1Value");
fields.put("key2","key2Value");
testJSON.put("fields", fields);
IssueType issueType = new IssueType(null, testJSON);
assertEquals(2,issueType.getFields().size());
assertSame("key1Value",issueType.getFields().getString("key1"));
assertSame("key2Value",issueType.getFields().getString("key2"));
}
@Test
public void testLoadIssueType() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
when(restClient.get(anyString())).thenReturn(getTestJSON());
IssueType issueType = IssueType.get(restClient,"someID");
assertFalse(issueType.isSubtask());
assertEquals(issueType.getName(), "Story");
assertEquals(issueType.getId(), "7");
assertEquals(issueType.getIconUrl(), "https://brainbubble.atlassian.net/images/icons/issuetypes/story.png");
assertEquals(issueType.getDescription(), "This is a test issue type.");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromRestException() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
when(mockRestClient.get(anyString())).thenThrow(RestException.class);
IssueType.get(mockRestClient, "issueNumber");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
IssueType.get(mockRestClient,"issueNumber");
}
@Test
public void testIssueTypeToString(){
IssueType issueType = new IssueType(null, getTestJSON());

View File

@ -2,12 +2,15 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
public class StatusTest {
@ -24,6 +27,30 @@ public class StatusTest {
assertEquals(status.getId(), statusID);
}
@Test
public void testGetStatus() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
when(restClient.get(anyString())).thenReturn(getTestJSON());
Status status = Status.get(restClient,"someID");
assertEquals(status.getDescription(), description);
assertEquals(status.getIconUrl(), iconURL);
assertEquals(status.getName(), "Open");
assertEquals(status.getId(), statusID);
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromRestException() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
when(mockRestClient.get(anyString())).thenThrow(RestException.class);
Status.get(mockRestClient, "issueNumber");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
Status.get(mockRestClient,"issueNumber");
}
private JSONObject getTestJSON() {
JSONObject json = new JSONObject();
json.put("description", description);

View File

@ -1,24 +1,141 @@
package net.rcarz.jiraclient;
import static junit.framework.Assert.assertEquals;
import net.sf.json.JSONObject;
import org.junit.Test;
import java.sql.Time;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertSame;
public class TimeTrackingTest {
private Issue issue = new Issue(null, Utils.getTestIssue());
private TimeTracking time = issue.getTimeTracking();
private Issue issue = new Issue(null, Utils.getTestIssue());
private TimeTracking time = issue.getTimeTracking();
@Test
public void testAttributeMappings() {
assertEquals("1w", time.getOriginalEstimate());
assertEquals(144000, time.getOriginalEstimateSeconds());
@Test
public void testAttributeMappings() {
assertEquals("1w", time.getOriginalEstimate());
assertEquals(144000, time.getOriginalEstimateSeconds());
assertEquals("2d", time.getRemainingEstimate());
assertEquals(57600, time.getRemainingEstimateSeconds());
assertEquals("2d", time.getRemainingEstimate());
assertEquals(57600, time.getRemainingEstimateSeconds());
assertEquals("3d", time.getTimeSpent());
assertEquals(86400, time.getTimeSpentSeconds());
}
assertEquals("3d", time.getTimeSpent());
assertEquals(86400, time.getTimeSpentSeconds());
}
@Test
public void testCreateTimeTracking() throws Exception {
final JSONObject testJson = new JSONObject();
testJson.put("originalEstimate", "1 day");
testJson.put("remainingEstimate", "2 days");
testJson.put("timeSpent", "3 days");
testJson.put("originalEstimateSeconds", 12);
testJson.put("remainingEstimateSeconds", 10);
testJson.put("timeSpentSeconds", 14);
TimeTracking timeTracking = new TimeTracking(testJson);
assertEquals("1 day", timeTracking.getOriginalEstimate());
assertEquals("2 days", timeTracking.getRemainingEstimate());
assertEquals("3 days", timeTracking.getTimeSpent());
assertEquals(14, timeTracking.getTimeSpentSeconds());
assertEquals(12, timeTracking.getOriginalEstimateSeconds());
assertEquals(10, timeTracking.getRemainingEstimateSeconds());
}
@Test
public void testGettersAndSetters() throws Exception {
final JSONObject testJson = new JSONObject();
testJson.put("originalEstimate", "1 day");
testJson.put("remainingEstimate", "2 days");
testJson.put("timeSpent", "3 days");
testJson.put("originalEstimateSeconds", 12);
testJson.put("remainingEstimateSeconds", 10);
testJson.put("timeSpentSeconds", 14);
TimeTracking timeTracking = new TimeTracking(testJson);
assertEquals("1 day", timeTracking.getOriginalEstimate());
assertEquals("2 days", timeTracking.getRemainingEstimate());
assertEquals("3 days", timeTracking.getTimeSpent());
assertEquals(14, timeTracking.getTimeSpentSeconds());
assertEquals(12, timeTracking.getOriginalEstimateSeconds());
assertEquals(10, timeTracking.getRemainingEstimateSeconds());
timeTracking.setOriginalEstimate("10 days");
timeTracking.setOrignalEstimateSeconds(1000);
timeTracking.setRemainingEstimate("5 days");
timeTracking.setRemainingEstimateSeconds(5904);
assertEquals("10 days", timeTracking.getOriginalEstimate());
assertEquals("5 days", timeTracking.getRemainingEstimate());
assertEquals("3 days", timeTracking.getTimeSpent());
assertEquals(14, timeTracking.getTimeSpentSeconds());
assertEquals(1000, timeTracking.getOriginalEstimateSeconds());
assertEquals(5904, timeTracking.getRemainingEstimateSeconds());
}
@Test
public void testEmptyValues() throws Exception {
TimeTracking timeTracking = new TimeTracking();
assertNull(timeTracking.getOriginalEstimate());
assertNull(timeTracking.getRemainingEstimate());
assertNull(timeTracking.getTimeSpent());
}
@Test
public void testTimeTrackingFromTimeTracking() throws Exception {
final JSONObject testJson = new JSONObject();
testJson.put("originalEstimate", "1 day");
testJson.put("remainingEstimate", "2 days");
testJson.put("timeSpent", "3 days");
testJson.put("originalEstimateSeconds", 12);
testJson.put("remainingEstimateSeconds", 10);
testJson.put("timeSpentSeconds", 14);
TimeTracking timeTracking = new TimeTracking(testJson);
assertEquals("1 day", timeTracking.getOriginalEstimate());
assertEquals("2 days", timeTracking.getRemainingEstimate());
assertEquals("3 days", timeTracking.getTimeSpent());
assertEquals(14, timeTracking.getTimeSpentSeconds());
assertEquals(12, timeTracking.getOriginalEstimateSeconds());
assertEquals(10, timeTracking.getRemainingEstimateSeconds());
TimeTracking updated = new TimeTracking(timeTracking);
assertEquals("1 day", updated.getOriginalEstimate());
assertEquals("2 days", updated.getRemainingEstimate());
assertEquals("3 days", updated.getTimeSpent());
assertEquals(14, updated.getTimeSpentSeconds());
assertEquals(12, updated.getOriginalEstimateSeconds());
assertEquals(10, updated.getRemainingEstimateSeconds());
}
@Test
public void testToJSONObject() throws Exception {
final JSONObject testJson = new JSONObject();
testJson.put("originalEstimate", "1 day");
testJson.put("remainingEstimate", "2 days");
testJson.put("originalEstimateSeconds", 12);
testJson.put("remainingEstimateSeconds", 10);
TimeTracking timeTracking = new TimeTracking(testJson);
final JSONObject jsonObject = timeTracking.toJsonObject();
assertEquals(testJson,jsonObject);
}
}

View File

@ -45,6 +45,14 @@ public class TransitionTest {
assertEquals("Done", transition.toString());
}
@Test
public void testGetFields() throws Exception {
Transition transition = new Transition(new RestClient(null, new URI("/123/asd")), getTestJson());
final Map fields = transition.getFields();
Assert.assertEquals(2,fields.size());
}
public static JSONObject getTestJson() {
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON(
"{\n" +

View File

@ -2,6 +2,7 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import java.io.IOException;
import java.net.URI;
@ -10,6 +11,9 @@ import java.util.Map;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
public class UserTest {
@ -64,4 +68,43 @@ public class UserTest {
User user = new User(new RestClient(null, new URI("/123/asd")), getTestJSON());
assertEquals(username, user.toString());
}
@Test(expected = JiraException.class)
public void testGetUserJSONError() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
when(restClient.get(anyString(),anyMap())).thenReturn(null);
User.get(restClient, "username");
}
@Test(expected = JiraException.class)
public void testGetUserRestError() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
when(restClient.get(anyString(),anyMap())).thenThrow(Exception.class);
User.get(restClient, "username");
}
@Test
public void testGetUser() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
when(restClient.get(anyString(),anyMap())).thenReturn(getTestJSON());
final User user = User.get(restClient, "username");
assertEquals(user.getName(), username);
assertEquals(user.getDisplayName(), displayName);
assertEquals(user.getEmail(), email);
assertEquals(user.getId(), userID);
Map<String, String> avatars = user.getAvatarUrls();
assertEquals("https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=16", avatars.get("16x16"));
assertEquals("https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=24", avatars.get("24x24"));
assertEquals("https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=32", avatars.get("32x32"));
assertEquals("https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=48", avatars.get("48x48"));
assertTrue(user.isActive());
}
}

View File

@ -2,58 +2,148 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest(JSONObject.class)
public class VersionTest {
@Test
public void testVersionInit(){
Version version = new Version(null,null);
public void testVersionInit() {
new Version(null, null);
}
@Test
public void testVersionJSON(){
Version version = new Version(null,getTestJSON());
public void testVersionJSON() {
Version version = new Version(null, getTestJSON());
assertEquals(version.getId(),"10200");
assertEquals(version.getName(),"1.0");
assertEquals(version.getId(), "10200");
assertEquals(version.getName(), "1.0");
assertFalse(version.isArchived());
assertFalse(version.isReleased());
assertEquals(version.getReleaseDate(),"2013-12-01");
assertEquals(version.getDescription(),"First Full Functional Build");
assertEquals(version.getReleaseDate(), "2013-12-01");
assertEquals(version.getDescription(), "First Full Functional Build");
}
@Test
public void testVersionToString(){
Version version = new Version(null,getTestJSON());
assertEquals(version.toString(),"1.0");
public void testGetVersion() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(restClient.get(anyString())).thenReturn(getTestJSON());
Version version = Version.get(restClient, "id");
assertEquals(version.getId(), "10200");
assertEquals(version.getName(), "1.0");
assertFalse(version.isArchived());
assertFalse(version.isReleased());
assertEquals(version.getReleaseDate(), "2013-12-01");
assertEquals(version.getDescription(), "First Full Functional Build");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromRestException() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(mockRestClient.get(anyString())).thenThrow(RestException.class);
Version.get(mockRestClient, "id");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
Version.get(mockRestClient, "id");
}
private JSONObject getTestJSON() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id","10200");
jsonObject.put("description","First Full Functional Build");
jsonObject.put("name","1.0");
jsonObject.put("archived",false);
jsonObject.put("released",false);
jsonObject.put("releaseDate","2013-12-01");
jsonObject.put("id", "10200");
jsonObject.put("description", "First Full Functional Build");
jsonObject.put("name", "1.0");
jsonObject.put("archived", false);
jsonObject.put("released", false);
jsonObject.put("releaseDate", "2013-12-01");
return jsonObject;
}
@Test
public void testMergeWith() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject mockJSON = PowerMockito.mock(JSONObject.class);
Version version = new Version(mockRestClient,mockJSON);
version.mergeWith(new Version(mockRestClient,mockJSON));
verify(mockRestClient, times(1)).put(anyString(), any(JSONObject.class));
}
@Test(expected = JiraException.class)
public void testMergeWithFailed() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject mockJSON = PowerMockito.mock(JSONObject.class);
when(mockRestClient.put(anyString(),any(JSONObject.class))).thenThrow(Exception.class);
Version version = new Version(mockRestClient,mockJSON);
version.mergeWith(new Version(mockRestClient,mockJSON));
}
@Test
public void testCopyTo() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject mockJSON = PowerMockito.mock(JSONObject.class);
Version version = new Version(mockRestClient,getTestJSON());
version.copyTo(new Project(mockRestClient,mockJSON));
verify(mockRestClient, times(1)).post(anyString(),any(JSONObject.class));
}
@Test(expected = JiraException.class)
public void testCopyToFailed() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject mockJSON = PowerMockito.mock(JSONObject.class);
when(mockRestClient.post(anyString(), any(JSONObject.class))).thenThrow(Exception.class);
Version version = new Version(mockRestClient,getTestJSON());
version.copyTo(new Project(mockRestClient,mockJSON));
}
@Test
public void testToString() throws Exception {
Version version = new Version(null, getTestJSON());
assertEquals(version.toString(), "1.0");
}
@Test
public void testGetName() throws Exception {
Version version = new Version(null, getTestJSON());
assertEquals(version.getName(), "1.0");
}
@Test
public void testIsArchived() throws Exception {
Version version = new Version(null, getTestJSON());
assertFalse(version.isArchived());
}
@Test
public void testIsReleased() throws Exception {
Version version = new Version(null, getTestJSON());
assertFalse(version.isReleased());
}
@Test
public void testGetReleaseDate() throws Exception {
Version version = new Version(null, getTestJSON());
assertEquals("2013-12-01",version.getReleaseDate());
}
@Test
public void testGetDescription() throws Exception {
Version version = new Version(null, getTestJSON());
assertEquals("First Full Functional Build",version.getDescription());
}
}
/**
"fixVersions": [
{
"self": "https://brainbubble.atlassian.net/rest/api/2/version/10200",
"id": "10200",
"description": "First Full Functional Build",
"name": "1.0",
"archived": false,
"released": false,
"releaseDate": "2013-12-01"
}
],
**/

View File

@ -2,15 +2,69 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.*;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
public class VotesTest {
@Test
public void testVotesInit(){
Votes votes = new Votes(null,null);
new Votes(null,null);
}
@Test
public void testVoteMap() throws Exception {
final JSONObject json = new JSONObject();
json.put("self","someURL");
json.put("id","1111");
json.put("votes",12);
json.put("hasVoted",true);
Votes votes = new Votes(null, json);
assertTrue(votes.hasVoted());
assertEquals("1111",votes.getId());
assertEquals(12,votes.getVotes());
assertEquals("someURL",votes.getSelf());
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromRestException() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(mockRestClient.get(anyString())).thenThrow(RestException.class);
Votes.get(mockRestClient, "issueNumber");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
Votes.get(mockRestClient,"issueNumber");
}
@Test
public void testGetVotesFromID() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject returnedFromService = new JSONObject();
returnedFromService.put("self", "someURL");
returnedFromService.put("id", "1111");
returnedFromService.put("votes", 12);
returnedFromService.put("hasVoted", true);
PowerMockito.when(mockRestClient.get(anyString())).thenReturn(returnedFromService);
final Votes votes = Votes.get(mockRestClient, "issueNumber");
assertTrue(votes.hasVoted());
assertEquals("1111",votes.getId());
assertEquals(12,votes.getVotes());
assertEquals("someURL",votes.getSelf());
}
@Test
@ -25,9 +79,14 @@ public class VotesTest {
@Test
public void testGetToString(){
Votes votes = new Votes(null,getTestJSON());
final JSONObject json = new JSONObject();
json.put("self","someURL");
json.put("id","1111");
json.put("votes",12);
json.put("hasVoted",true);
Votes votes = new Votes(null, json);
assertEquals(votes.toString(),"0");
assertEquals(votes.toString(),"12");
}
private JSONObject getTestJSON() {
@ -40,12 +99,3 @@ public class VotesTest {
return jsonObject;
}
}
/**
"votes": {
"self": "https://brainbubble.atlassian.net/rest/api/2/issue/FILTA-43/votes",
"votes": 0,
"hasVoted": false
},
**/

View File

@ -2,9 +2,11 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static org.mockito.Matchers.anyString;
public class WatchesTest {
@ -23,6 +25,32 @@ public class WatchesTest {
assertEquals(watches.getSelf(), "https://brainbubble.atlassian.net/rest/api/2/issue/FILTA-43/watchers");
}
@Test(expected = JiraException.class)
public void testGetWatchersNullReturned() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(restClient.get(anyString())).thenReturn(null);
Watches.get(restClient, "someID");
}
@Test(expected = JiraException.class)
public void testGetWatchersGetThrows() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(restClient.get(anyString())).thenThrow(Exception.class);
Watches.get(restClient, "someID");
}
@Test
public void testGetWatchers() throws Exception {
final RestClient restClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(restClient.get(anyString())).thenReturn(getTestJSON());
final Watches watches = Watches.get(restClient, "someID");
assertFalse(watches.isWatching());
assertEquals(watches.getWatchCount(), 0);
assertEquals(watches.getId(), "10");
assertEquals(watches.getSelf(), "https://brainbubble.atlassian.net/rest/api/2/issue/FILTA-43/watchers");
}
@Test
public void testWatchesToString() {
Watches watches = new Watches(null, getTestJSON());

View File

@ -1,19 +1,56 @@
package net.rcarz.jiraclient;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
public class WorklogTest {
private String author = "joseph";
private String started = "2015-08-17T00:00:00.000";
private String created = "2015-08-20T00:00:00.000";
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
@Test(expected = JiraException.class)
public void testJiraExceptionFromRestException() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
PowerMockito.when(mockRestClient.get(anyString())).thenThrow(RestException.class);
WorkLog.get(mockRestClient, "issueNumber", "someID");
}
@Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
WorkLog.get(mockRestClient,"issueNumber","someID");
}
@Test
public void testToString() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
final JSONObject mockJSONObject = new JSONObject();
String dateString = "2015-12-24";
mockJSONObject.put("created",dateString);
final JSONObject userJSON = new JSONObject();
userJSON.put("name","Joseph McCarthy");
mockJSONObject.put("author", userJSON);
String DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
final Date parse = df.parse(dateString, new ParsePosition(0));
WorkLog workLog = new WorkLog(mockRestClient,mockJSONObject);
assertEquals(parse.toString() + " by Joseph McCarthy",workLog.toString());
}
@Test
public void testWorklog() {
@ -24,8 +61,11 @@ public class WorklogTest {
assertEquals("comment for worklog 1", workLog.getComment());
assertEquals("6h", workLog.getTimeSpent());
assertEquals("45517", workLog.getId());
String author = "joseph";
assertEquals(author, workLog.getAuthor().getName());
String started = "2015-08-17T00:00:00.000";
assertEquals(started, simpleDateFormat.format(workLog.getStarted()));
String created = "2015-08-20T00:00:00.000";
assertEquals(created, simpleDateFormat.format(workLog.getCreatedDate()));
assertEquals(21600, workLog.getTimeSpentSeconds());
assertEquals(author, workLog.getUpdateAuthor().getName());