Skip to content

Commit

Permalink
try not using a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
William Welling committed Aug 3, 2022
1 parent e867063 commit da76900
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ public class GitHubMilestoneServiceTest extends CacheMockTests {
private static final String TEST_PROJECT2_NAME = "Test Project 2 Name";
private static final String TEST_PROJECT3_NAME = "Test Project 3 Name";
private static final String TEST_MILESTONE_TITLE = "Test Milestone Sprint Title";
private static final Long TEST_REPOSITORY1_ID = 1L;
private static final Long TEST_USER1_ID = 3L;

private static final String TEST_PROJECT_URL1 = "http://localhost/1";

private static final String TEST_PROJECT_TOKEN1 = "0123456789";

private Long testRepository1Id = 1L;
private Long testRepository2Id = 2L;
private Long testUser1Id = 3L;

private List<GHLabel> allTestLabels;
private List<GHLabel> testCard1Labels;
private List<GHLabel> testCard2Labels;
Expand Down Expand Up @@ -314,16 +316,15 @@ public void setUp() throws Exception {
lenient().when(issueBuilder.body(any(String.class))).thenReturn(issueBuilder);
lenient().when(issueBuilder.create()).thenReturn(testIssue1);

lenient().doReturn(String.valueOf(TEST_REPOSITORY1_ID)).when(testRepository1).getId();

lenient().when(testRepository1.getId()).thenReturn(testRepository1Id);
lenient().when(testRepository1.getName()).thenReturn(TEST_REPOSITORY1_NAME);
lenient().when(testRepository1.listProjects(any(ProjectStateFilter.class))).thenReturn(projectIterable);
lenient().when(testRepository1.listProjects()).thenReturn(projectIterable);
lenient().when(testRepository1.listLabels()).thenReturn(labelIterable);
lenient().when(testRepository1.getIssues(any(GHIssueState.class))).thenReturn(testIssueList);

lenient().when(testRepository2.getId()).thenReturn(TEST_REPOSITORY1_ID);
lenient().when(testRepository2.getName()).thenReturn(TEST_REPOSITORY1_NAME);
lenient().when(testRepository2.getId()).thenReturn(testRepository2Id);
lenient().when(testRepository2.getName()).thenReturn(TEST_REPOSITORY2_NAME);
lenient().when(testRepository2.getIssues(any(GHIssueState.class))).thenReturn(testIssueList);
lenient().when(testRepository2.listProjects()).thenReturn(projectIterable);
lenient().when(testRepository2.listLabels()).thenReturn(labelIterable);
Expand Down Expand Up @@ -384,7 +385,7 @@ public void setUp() throws Exception {
lenient().when(testCard4.getContent().getAssignees()).thenReturn(testUsers4);
lenient().when(testCard5.getContent().getAssignees()).thenReturn(testUsers5);

lenient().when(testUser1.getId()).thenReturn(TEST_USER1_ID);
lenient().when(testUser1.getId()).thenReturn(testUser1Id);
lenient().when(testUser1.getName()).thenReturn(TEST_USER1_NAME);
lenient().when(testUser1.getAvatarUrl()).thenReturn(TEST_USER1_AVATAR_PATH);
lenient().when(testUser2.getAvatarUrl()).thenReturn(TEST_USER2_AVATAR_PATH);
Expand All @@ -396,7 +397,7 @@ public void setUp() throws Exception {
lenient().when(testLabel4.getName()).thenReturn(DEFECT_LABEL);
lenient().when(testLabel5.getName()).thenReturn(TEST_UNUSED_LABEL_NAME);

lenient().when(testFeatureRequest.getProductId()).thenReturn(TEST_REPOSITORY1_ID);
lenient().when(testFeatureRequest.getProductId()).thenReturn(testRepository1Id);
lenient().when(testFeatureRequest.getTitle()).thenReturn(TEST_FEATURE_REQUEST_TITLE);
lenient().when(testFeatureRequest.getDescription()).thenReturn(TEST_FEATURE_REQUEST_DESCRIPTION);

Expand Down Expand Up @@ -483,9 +484,9 @@ public void testGetRemoteProjects() throws Exception {
public void testGetRemoteProjectByScopeId() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

RemoteProject project = gitHubMilestoneService.getRemoteProjectByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
RemoteProject project = gitHubMilestoneService.getRemoteProjectByScopeId(String.valueOf(testRepository1Id));
assertNotNull(project, "Didn't get the remote project");
assertEquals(String.valueOf(TEST_REPOSITORY1_ID), project.getId(), "Did not get the expected project");
assertEquals(String.valueOf(testRepository1Id), project.getId(), "Did not get the expected project");
assertEquals(1, project.getRequestCount(), "Number of Requests was incorrect");
assertEquals(2, project.getIssueCount(), "Number of Issues was incorrect");
assertEquals(1, project.getFeatureCount(), "Number of Features was incorrect");
Expand All @@ -496,7 +497,7 @@ public void testGetRemoteProjectByScopeId() throws Exception {
public void testGetActiveSprintsByProjectId() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

List<Sprint> activeSprints = gitHubMilestoneService.getActiveSprintsByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
List<Sprint> activeSprints = gitHubMilestoneService.getActiveSprintsByScopeId(String.valueOf(testRepository1Id));
assertEquals(3, activeSprints.size(), "Didn't get all active sprints");
}

Expand All @@ -512,7 +513,7 @@ public void testGetAdditionalActiveSprints() throws Exception {
public void testGetActiveSprintsByProjectIdType() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

List<Sprint> sprints = gitHubMilestoneService.getActiveSprintsByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
List<Sprint> sprints = gitHubMilestoneService.getActiveSprintsByScopeId(String.valueOf(testRepository1Id));

sprints.forEach(sprint -> {
assertEquals(ServiceType.GITHUB_MILESTONE.toString(), sprint.getType(), "Didn't get the correct Service Type for the Sprint");
Expand Down Expand Up @@ -541,7 +542,7 @@ public void testPush() throws Exception {
@Test
public void testGetMember() throws IOException {
Member member = gitHubMilestoneService.getMember(testUser1);
assertEquals(String.valueOf(TEST_USER1_ID), member.getId(), "Member ID is incorrect");
assertEquals(String.valueOf(testUser1Id), member.getId(), "Member ID is incorrect");
assertEquals(TEST_USER1_NAME, member.getName(), "Member Name is incorrect");
assertEquals(TEST_USER1_AVATAR_NAME, member.getAvatar(), "Member Avatar URL is incorrect");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ public class GitHubProjectServiceTest extends CacheMockTests {
private static final String TEST_USER3_AVATAR_PATH = "https://avatars2.githubusercontent.com/u/3333333?v=4";
private static final String TEST_USER1_AVATAR_NAME = "1234567";
private static final String TEST_COLUMN1_NAME = "Test Column 1";
private static final Long TEST_REPOSITORY1_ID = 1L;
private static final Long TEST_USER1_ID = 3L;

private static final String TEST_PROJECT_URL1 = "http://localhost/1";

private static final String TEST_PROJECT_TOKEN1 = "0123456789";

private Long testRepository1Id = 1L;
private Long testRepository2Id = 2L;
private Long testUser1Id = 3L;

private List<GHLabel> allTestLabels;
private List<GHLabel> testCard1Labels;
private List<GHLabel> testCard2Labels;
Expand Down Expand Up @@ -305,16 +307,15 @@ public void setUp() throws Exception {
lenient().when(issueBuilder.body(any(String.class))).thenReturn(issueBuilder);
lenient().when(issueBuilder.create()).thenReturn(testIssue1);

lenient().doReturn(String.valueOf(TEST_REPOSITORY1_ID)).when(testRepository1).getId();

lenient().when(testRepository1.getId()).thenReturn(testRepository1Id);
lenient().when(testRepository1.getName()).thenReturn(TEST_REPOSITORY1_NAME);
lenient().when(testRepository1.listProjects(any(ProjectStateFilter.class))).thenReturn(projectIterable);
lenient().when(testRepository1.listProjects()).thenReturn(projectIterable);
lenient().when(testRepository1.listLabels()).thenReturn(labelIterable);
lenient().when(testRepository1.getIssues(any(GHIssueState.class))).thenReturn(testIssueList);

lenient().when(testRepository2.getId()).thenReturn(TEST_REPOSITORY1_ID);
lenient().when(testRepository2.getName()).thenReturn(TEST_REPOSITORY1_NAME);
lenient().when(testRepository2.getId()).thenReturn(testRepository2Id);
lenient().when(testRepository2.getName()).thenReturn(TEST_REPOSITORY2_NAME);
lenient().when(testRepository2.getIssues(any(GHIssueState.class))).thenReturn(testIssueList);
lenient().when(testRepository2.listProjects()).thenReturn(projectIterable);
lenient().when(testRepository2.listLabels()).thenReturn(labelIterable);
Expand Down Expand Up @@ -367,7 +368,7 @@ public void setUp() throws Exception {
lenient().when(testCard4.getContent().getAssignees()).thenReturn(testUsers4);
lenient().when(testCard5.getContent().getAssignees()).thenReturn(testUsers5);

lenient().when(testUser1.getId()).thenReturn(TEST_USER1_ID);
lenient().when(testUser1.getId()).thenReturn(testUser1Id);
lenient().when(testUser1.getName()).thenReturn(TEST_USER1_NAME);
lenient().when(testUser1.getAvatarUrl()).thenReturn(TEST_USER1_AVATAR_PATH);
lenient().when(testUser2.getAvatarUrl()).thenReturn(TEST_USER2_AVATAR_PATH);
Expand All @@ -379,7 +380,7 @@ public void setUp() throws Exception {
lenient().when(testLabel4.getName()).thenReturn(DEFECT_LABEL);
lenient().when(testLabel5.getName()).thenReturn(TEST_UNUSED_LABEL_NAME);

lenient().when(testFeatureRequest.getProductId()).thenReturn(TEST_REPOSITORY1_ID);
lenient().when(testFeatureRequest.getProductId()).thenReturn(testRepository1Id);
lenient().when(testFeatureRequest.getTitle()).thenReturn(TEST_FEATURE_REQUEST_TITLE);
lenient().when(testFeatureRequest.getDescription()).thenReturn(TEST_FEATURE_REQUEST_DESCRIPTION);

Expand Down Expand Up @@ -466,9 +467,9 @@ public void testGetRemoteProjects() throws Exception {
public void testGetRemoteProjectByScopeId() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

RemoteProject project = gitHubProjectService.getRemoteProjectByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
RemoteProject project = gitHubProjectService.getRemoteProjectByScopeId(String.valueOf(testRepository1Id));
assertNotNull(project, "Didn't get the remote project");
assertEquals(String.valueOf(TEST_REPOSITORY1_ID), project.getId(), "Did not get the expected project");
assertEquals(String.valueOf(testRepository1Id), project.getId(), "Did not get the expected project");
assertEquals(1, project.getRequestCount(), "Number of Requests was incorrect");
assertEquals(2, project.getIssueCount(), "Number of Issues was incorrect");
assertEquals(1, project.getFeatureCount(), "Number of Features was incorrect");
Expand All @@ -479,7 +480,7 @@ public void testGetRemoteProjectByScopeId() throws Exception {
public void testGetActiveSprintsByProjectId() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

List<Sprint> activeSprints = gitHubProjectService.getActiveSprintsByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
List<Sprint> activeSprints = gitHubProjectService.getActiveSprintsByScopeId(String.valueOf(testRepository1Id));
assertEquals(3, activeSprints.size(), "Didn't get all active sprints");
}

Expand All @@ -495,7 +496,7 @@ public void testGetAdditionalActiveSprints() throws Exception {
public void testGetActiveSprintsByProjectIdType() throws Exception {
when(github.getRepositoryById(any(String.class))).thenReturn(testRepository1);

List<Sprint> sprints = gitHubProjectService.getActiveSprintsByScopeId(String.valueOf(TEST_REPOSITORY1_ID));
List<Sprint> sprints = gitHubProjectService.getActiveSprintsByScopeId(String.valueOf(testRepository1Id));

sprints.forEach(sprint -> {
assertEquals(ServiceType.GITHUB_PROJECT.toString(), sprint.getType(), "Didn't get the correct Service Type for the Sprint");
Expand Down Expand Up @@ -524,7 +525,7 @@ public void testPush() throws Exception {
@Test
public void testGetMember() throws IOException {
Member member = gitHubProjectService.getMember(testUser1);
assertEquals(String.valueOf(TEST_USER1_ID), member.getId(), "Member ID is incorrect");
assertEquals(String.valueOf(testUser1Id), member.getId(), "Member ID is incorrect");
assertEquals(TEST_USER1_NAME, member.getName(), "Member Name is incorrect");
assertEquals(TEST_USER1_AVATAR_NAME, member.getAvatar(), "Member Avatar URL is incorrect");
}
Expand Down

0 comments on commit da76900

Please sign in to comment.