diff --git a/src/test/java/net/rcarz/jiraclient/VotesTest.java b/src/test/java/net/rcarz/jiraclient/VotesTest.java index d4e9b2f..00ed16a 100644 --- a/src/test/java/net/rcarz/jiraclient/VotesTest.java +++ b/src/test/java/net/rcarz/jiraclient/VotesTest.java @@ -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 - }, - **/ diff --git a/src/test/java/net/rcarz/jiraclient/WorklogTest.java b/src/test/java/net/rcarz/jiraclient/WorklogTest.java index 91ff60f..1e6a9f3 100644 --- a/src/test/java/net/rcarz/jiraclient/WorklogTest.java +++ b/src/test/java/net/rcarz/jiraclient/WorklogTest.java @@ -4,7 +4,6 @@ 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 java.text.SimpleDateFormat; @@ -28,7 +27,7 @@ public class WorklogTest { @Test(expected = JiraException.class) public void testJiraExceptionFromNonJSON() throws Exception { final RestClient mockRestClient = PowerMockito.mock(RestClient.class); - WorkLog.get(mockRestClient,"issueNumber","someID"); + WorkLog.get(mockRestClient, "issueNumber", "someID"); } @Test @@ -37,15 +36,14 @@ public class WorklogTest { final JSONObject mockJSONObject = new JSONObject(); String dateString = "2015-12-24"; - mockJSONObject.put("created",dateString); + mockJSONObject.put("created", dateString); final JSONObject userJSON = new JSONObject(); - userJSON.put("name","Joseph McCarthy"); + userJSON.put("name", "Joseph McCarthy"); mockJSONObject.put("author", userJSON); - - WorkLog workLog = new WorkLog(mockRestClient,mockJSONObject); - assertEquals("Thu Dec 24 00:00:00 GMT 2015 by Joseph McCarthy",workLog.toString()); + WorkLog workLog = new WorkLog(mockRestClient, mockJSONObject); + assertEquals("Thu Dec 24 00:00:00 GMT 2015 by Joseph McCarthy", workLog.toString()); } @Test