From 4d1f9282d7af97f103ae69efa93b32f54f789986 Mon Sep 17 00:00:00 2001 From: Joseph McCarthy Date: Sat, 26 Dec 2015 21:55:57 +0000 Subject: [PATCH] Increase coverage for WatchesTest.java --- .../net/rcarz/jiraclient/WatchesTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/net/rcarz/jiraclient/WatchesTest.java b/src/test/java/net/rcarz/jiraclient/WatchesTest.java index 012aeda..f7580f8 100644 --- a/src/test/java/net/rcarz/jiraclient/WatchesTest.java +++ b/src/test/java/net/rcarz/jiraclient/WatchesTest.java @@ -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());