Skip to content

Commit

Permalink
added issue bean tests and fixed return bug in issue bean
Browse files Browse the repository at this point in the history
Signed-off-by: Maxwell Brown <[email protected]>
  • Loading branch information
Galactus22625 committed Nov 2, 2024
1 parent 9a7b3ad commit 9336a1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String getProject() {
@JsonIgnore
public String getProjectName() {
if (fields != null && Objects.nonNull(((Map) fields.get(PROJECT)).get(NAME))) {
((Map) fields.get(PROJECT)).get(NAME).toString();
return ((Map) fields.get(PROJECT)).get(NAME).toString();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.KEY;
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.NAME;
import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.PROJECT;

@ExtendWith(MockitoExtension.class)
public class IssueBeanTest {
Expand Down Expand Up @@ -58,6 +62,14 @@ void testNullCases() {
assertEquals(issueBean.getUpdatedTimeMillis(), 0);
}

@Test
void testGivenDateField() {
Map<String, Object> fieldsTestObject = new HashMap<>();
fieldsTestObject.put("created", "2024-07-06T21:12:23.437-0700");
issueBean.setFields(fieldsTestObject);
assertEquals(issueBean.getCreatedTimeMillis(), 1720325543000L);
}

@Test
public void testStringSettersAndGetters() {
String self = "selfTest";
Expand Down Expand Up @@ -88,4 +100,19 @@ public void testMapSettersAndGetters() {
assertEquals(issueBean.getFields(), fieldsTestObject);
}

@Test
public void testFieldPropertyGetters() {
Map<String, Object> fieldsTestObject = new HashMap<>();
Map<String, Object> projectTestObject = new HashMap<>();
String projectName = "name of project";
String projectKey = "PROJKEY";
projectTestObject.put(KEY, projectKey);
projectTestObject.put(NAME, projectName);
fieldsTestObject.put(PROJECT, projectTestObject);

issueBean.setFields(fieldsTestObject);
assertEquals(projectKey, issueBean.getProject());
assertEquals(projectName, issueBean.getProjectName());
}

}

0 comments on commit 9336a1b

Please sign in to comment.