Search in sources :

Example 1 with RelationToRemote

use of com.virtuslab.gitmachete.backend.api.RelationToRemote in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveRelationToRemoteUnitTestSuite method deriveRelationToRemote_DivergedAndNewerThan.

@Test
@SneakyThrows
public void deriveRelationToRemote_DivergedAndNewerThan() {
    // given
    PowerMockito.doReturn(List.of(ORIGIN)).when(gitCoreRepository).deriveAllRemoteNames();
    PowerMockito.doReturn(Option.some(coreRemoteBranch)).when(coreLocalBranch).getRemoteTrackingBranch();
    PowerMockito.doReturn(coreLocalBranchCommit).when(coreLocalBranch).getPointedCommit();
    PowerMockito.doReturn(coreRemoteBranchCommit).when(coreRemoteBranch).getPointedCommit();
    val relativeCommitCount = GitCoreRelativeCommitCount.of(1, 1);
    PowerMockito.doReturn(Option.some(relativeCommitCount)).when(gitCoreRepository).deriveRelativeCommitCount(coreLocalBranchCommit, coreRemoteBranchCommit);
    Instant newerInstant = Instant.parse("2000-05-01T10:00:00Z");
    Instant olderInstant = newerInstant.minus(10, ChronoUnit.MINUTES);
    PowerMockito.doReturn(newerInstant).when(coreLocalBranchCommit).getCommitTime();
    PowerMockito.doReturn(olderInstant).when(coreRemoteBranchCommit).getCommitTime();
    // when
    RelationToRemote relationToRemote = invokeDeriveRelationToRemote(coreLocalBranch);
    // then
    Assert.assertEquals(SyncToRemoteStatus.DivergedFromAndNewerThanRemote, relationToRemote.getSyncToRemoteStatus());
}
Also used : lombok.val(lombok.val) Instant(java.time.Instant) RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with RelationToRemote

use of com.virtuslab.gitmachete.backend.api.RelationToRemote in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveRelationToRemoteUnitTestSuite method deriveRelationToRemote_NoRemotes.

@Test
@SneakyThrows
public void deriveRelationToRemote_NoRemotes() {
    // given
    PowerMockito.doReturn(List.empty()).when(gitCoreRepository).deriveAllRemoteNames();
    // when
    RelationToRemote relationToRemote = invokeDeriveRelationToRemote(coreLocalBranch);
    // then
    Assert.assertEquals(SyncToRemoteStatus.NoRemotes, relationToRemote.getSyncToRemoteStatus());
}
Also used : RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with RelationToRemote

use of com.virtuslab.gitmachete.backend.api.RelationToRemote in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveRelationToRemoteUnitTestSuite method deriveRelationToRemote_Ahead.

@Test
@SneakyThrows
public void deriveRelationToRemote_Ahead() {
    // given
    PowerMockito.doReturn(List.of(ORIGIN)).when(gitCoreRepository).deriveAllRemoteNames();
    PowerMockito.doReturn(Option.some(coreRemoteBranch)).when(coreLocalBranch).getRemoteTrackingBranch();
    PowerMockito.doReturn(coreLocalBranchCommit).when(coreLocalBranch).getPointedCommit();
    PowerMockito.doReturn(coreRemoteBranchCommit).when(coreRemoteBranch).getPointedCommit();
    val relativeCommitCount = GitCoreRelativeCommitCount.of(3, 0);
    PowerMockito.doReturn(Option.some(relativeCommitCount)).when(gitCoreRepository).deriveRelativeCommitCount(coreLocalBranchCommit, coreRemoteBranchCommit);
    // when
    RelationToRemote relationToRemote = invokeDeriveRelationToRemote(coreLocalBranch);
    // then
    Assert.assertEquals(SyncToRemoteStatus.AheadOfRemote, relationToRemote.getSyncToRemoteStatus());
}
Also used : lombok.val(lombok.val) RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with RelationToRemote

use of com.virtuslab.gitmachete.backend.api.RelationToRemote in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveRelationToRemoteUnitTestSuite method deriveRelationToRemote_Behind.

@Test
@SneakyThrows
public void deriveRelationToRemote_Behind() {
    // given
    PowerMockito.doReturn(List.of(ORIGIN)).when(gitCoreRepository).deriveAllRemoteNames();
    PowerMockito.doReturn(Option.some(coreRemoteBranch)).when(coreLocalBranch).getRemoteTrackingBranch();
    PowerMockito.doReturn(coreLocalBranchCommit).when(coreLocalBranch).getPointedCommit();
    PowerMockito.doReturn(coreRemoteBranchCommit).when(coreRemoteBranch).getPointedCommit();
    val relativeCommitCount = GitCoreRelativeCommitCount.of(0, 3);
    PowerMockito.doReturn(Option.some(relativeCommitCount)).when(gitCoreRepository).deriveRelativeCommitCount(coreLocalBranchCommit, coreRemoteBranchCommit);
    // when
    RelationToRemote relationToRemote = invokeDeriveRelationToRemote(coreLocalBranch);
    // then
    Assert.assertEquals(SyncToRemoteStatus.BehindRemote, relationToRemote.getSyncToRemoteStatus());
}
Also used : lombok.val(lombok.val) RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 5 with RelationToRemote

use of com.virtuslab.gitmachete.backend.api.RelationToRemote in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository_deriveRelationToRemoteUnitTestSuite method deriveRelationToRemote_Untracked.

@Test
@SneakyThrows
public void deriveRelationToRemote_Untracked() {
    // given
    PowerMockito.doReturn(List.of(ORIGIN)).when(gitCoreRepository).deriveAllRemoteNames();
    PowerMockito.doReturn(Option.none()).when(coreLocalBranch).getRemoteTrackingBranch();
    // when
    RelationToRemote relationToRemote = invokeDeriveRelationToRemote(coreLocalBranch);
    // then
    Assert.assertEquals(SyncToRemoteStatus.Untracked, relationToRemote.getSyncToRemoteStatus());
}
Also used : RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

RelationToRemote (com.virtuslab.gitmachete.backend.api.RelationToRemote)9 SneakyThrows (lombok.SneakyThrows)8 Test (org.junit.Test)8 lombok.val (lombok.val)6 Instant (java.time.Instant)3 IManagedBranchSnapshot (com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot)1 BranchItem (com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem)1