1
0
Fork 0

Cleaned up imports and increased test coverage for VotesTest.java

master
Joseph McCarthy 2015-12-25 01:17:12 +00:00
parent 8c22cfae67
commit 69d55ee363
2 changed files with 69 additions and 21 deletions

View File

@ -2,15 +2,69 @@ package net.rcarz.jiraclient;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.junit.Test; 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.*;
import static junit.framework.Assert.assertFalse; import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
public class VotesTest { public class VotesTest {
@Test @Test
public void testVotesInit(){ 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 @Test
@ -25,9 +79,14 @@ public class VotesTest {
@Test @Test
public void testGetToString(){ 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() { private JSONObject getTestJSON() {
@ -40,12 +99,3 @@ public class VotesTest {
return jsonObject; return jsonObject;
} }
} }
/**
"votes": {
"self": "https://brainbubble.atlassian.net/rest/api/2/issue/FILTA-43/votes",
"votes": 0,
"hasVoted": false
},
**/

View File

@ -4,7 +4,6 @@ import net.sf.json.JSONObject;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -28,7 +27,7 @@ public class WorklogTest {
@Test(expected = JiraException.class) @Test(expected = JiraException.class)
public void testJiraExceptionFromNonJSON() throws Exception { public void testJiraExceptionFromNonJSON() throws Exception {
final RestClient mockRestClient = PowerMockito.mock(RestClient.class); final RestClient mockRestClient = PowerMockito.mock(RestClient.class);
WorkLog.get(mockRestClient,"issueNumber","someID"); WorkLog.get(mockRestClient, "issueNumber", "someID");
} }
@Test @Test
@ -37,15 +36,14 @@ public class WorklogTest {
final JSONObject mockJSONObject = new JSONObject(); final JSONObject mockJSONObject = new JSONObject();
String dateString = "2015-12-24"; String dateString = "2015-12-24";
mockJSONObject.put("created",dateString); mockJSONObject.put("created", dateString);
final JSONObject userJSON = new JSONObject(); final JSONObject userJSON = new JSONObject();
userJSON.put("name","Joseph McCarthy"); userJSON.put("name", "Joseph McCarthy");
mockJSONObject.put("author", userJSON); mockJSONObject.put("author", userJSON);
WorkLog workLog = new WorkLog(mockRestClient, mockJSONObject);
WorkLog workLog = new WorkLog(mockRestClient,mockJSONObject); assertEquals("Thu Dec 24 00:00:00 GMT 2015 by Joseph McCarthy", workLog.toString());
assertEquals("Thu Dec 24 00:00:00 GMT 2015 by Joseph McCarthy",workLog.toString());
} }
@Test @Test