1
0
Fork 0

Added PowerMock scoped for Testing and increased the testing for the WorkLogObject

master
Joseph McCarthy 2015-12-25 01:01:24 +00:00
parent 12f11ce2c3
commit 57ac671ecb
2 changed files with 56 additions and 3 deletions

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

@ -1,19 +1,54 @@
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 java.text.SimpleDateFormat;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
@PrepareForTest(JSONObject.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);
WorkLog workLog = new WorkLog(mockRestClient,mockJSONObject);
assertEquals("Thu Dec 24 00:00:00 GMT 2015 by Joseph McCarthy",workLog.toString());
}
@Test
public void testWorklog() {
@ -24,8 +59,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());