-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(BranchService): add test that pinned branches and prs are shown …
…first
- Loading branch information
Showing
3 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
server/application-server/src/test/java/de/tum/cit/aet/helios/branch/BranchServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.tum.cit.aet.helios.branch; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import de.tum.cit.aet.helios.auth.AuthService; | ||
import de.tum.cit.aet.helios.gitrepo.GitRepository; | ||
import de.tum.cit.aet.helios.releasecandidate.ReleaseCandidateRepository; | ||
import de.tum.cit.aet.helios.userpreference.UserPreference; | ||
import de.tum.cit.aet.helios.userpreference.UserPreferenceRepository; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BranchServiceTest { | ||
|
||
@InjectMocks private BranchService branchService; | ||
@Mock private BranchRepository branchRepository; | ||
@Mock private ReleaseCandidateRepository releaseCandidateRepository; | ||
@Mock private UserPreferenceRepository userPreferenceRepository; | ||
@Mock private AuthService authService; | ||
|
||
@BeforeEach | ||
public void init() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
public void testPinnedBranchesAreShownFirst() { | ||
final GitRepository repo = new GitRepository(); | ||
repo.setRepositoryId(1L); | ||
|
||
final Branch b1 = new Branch(); | ||
b1.setName("branch1"); | ||
b1.setRepository(repo); | ||
|
||
final Branch b2 = new Branch(); | ||
b2.setName("branch2"); | ||
b2.setRepository(repo); | ||
|
||
final List<Branch> branches = List.of(b1, b2); | ||
|
||
final UserPreference userPreference = new UserPreference(); | ||
userPreference.setFavouriteBranches(Set.of(b2)); | ||
|
||
when(branchRepository.findAll()).thenReturn(branches); | ||
when(authService.getUserFromGithubId()).thenReturn(null); | ||
when(userPreferenceRepository.findByUser(null)).thenReturn(Optional.of(userPreference)); | ||
|
||
BranchInfoDto b1Dto = | ||
BranchInfoDto.fromBranchAndUserPreference(b1, Optional.of(userPreference)); | ||
BranchInfoDto b2Dto = | ||
BranchInfoDto.fromBranchAndUserPreference(b2, Optional.of(userPreference)); | ||
|
||
assertEquals(2, branchService.getAllBranches().size()); | ||
Assertions.assertIterableEquals(List.of(b2Dto, b1Dto), branchService.getAllBranches()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...cation-server/src/test/java/de/tum/cit/aet/helios/pullrequest/PullRequestServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package de.tum.cit.aet.helios.pullrequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import de.tum.cit.aet.helios.auth.AuthService; | ||
import de.tum.cit.aet.helios.gitrepo.GitRepository; | ||
import de.tum.cit.aet.helios.userpreference.UserPreference; | ||
import de.tum.cit.aet.helios.userpreference.UserPreferenceRepository; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class PullRequestServiceTest { | ||
|
||
@InjectMocks private PullRequestService pullRequestService; | ||
@Mock private PullRequestRepository pullRequestsRepository; | ||
@Mock private UserPreferenceRepository userPreferenceRepository; | ||
@Mock private AuthService authService; | ||
|
||
@BeforeEach | ||
public void init() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
public void testPinnedBranchesAreShownFirst() { | ||
final GitRepository repo = new GitRepository(); | ||
repo.setRepositoryId(1L); | ||
|
||
final PullRequest pr1 = new PullRequest(); | ||
pr1.setId(1L); | ||
pr1.setNumber(1); | ||
pr1.setRepository(repo); | ||
|
||
final PullRequest pr2 = new PullRequest(); | ||
pr2.setId(2L); | ||
pr2.setNumber(2); | ||
pr2.setRepository(repo); | ||
|
||
final List<PullRequest> prs = List.of(pr1, pr2); | ||
|
||
final UserPreference userPreference = new UserPreference(); | ||
userPreference.setFavouritePullRequests(Set.of(pr2)); | ||
|
||
when(pullRequestsRepository.findAllByOrderByUpdatedAtDesc()).thenReturn(prs); | ||
when(authService.getUserFromGithubId()).thenReturn(null); | ||
when(userPreferenceRepository.findByUser(null)).thenReturn(Optional.of(userPreference)); | ||
|
||
PullRequestBaseInfoDto pr1Dto = | ||
PullRequestBaseInfoDto.fromPullRequestAndUserPreference(pr1, Optional.of(userPreference)); | ||
|
||
PullRequestBaseInfoDto pr2Dto = | ||
PullRequestBaseInfoDto.fromPullRequestAndUserPreference(pr2, Optional.of(userPreference)); | ||
|
||
assertEquals(2, pullRequestService.getAllPullRequests().size()); | ||
Assertions.assertIterableEquals( | ||
List.of(pr2Dto, pr1Dto), pullRequestService.getAllPullRequests()); | ||
} | ||
} |