Search in sources :

Example 1 with GitModelCommit

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit in project egit by eclipse.

the class GitChangeSetSorter method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    if (e1 instanceof GitModelBlob && !(e2 instanceof GitModelBlob))
        return 1;
    if (e2 instanceof GitModelBlob && !(e1 instanceof GitModelBlob))
        return -1;
    if (e1 instanceof GitModelWorkingTree)
        return -1;
    if (e2 instanceof GitModelWorkingTree)
        return 1;
    if (e1 instanceof GitModelCache)
        return -2;
    if (e2 instanceof GitModelCache)
        return 2;
    if ((e1 instanceof GitModelTree && e2 instanceof GitModelTree) || (e1 instanceof GitModelBlob && e2 instanceof GitModelBlob))
        return super.compare(viewer, e1, e2);
    if (e1 instanceof GitModelTree && e2 instanceof GitModelCommit)
        return 1;
    if (e1 instanceof GitModelCommit && e2 instanceof GitModelCommit) {
        Commit rc1 = ((GitModelCommit) e1).getCachedCommitObj();
        Commit rc2 = ((GitModelCommit) e2).getCachedCommitObj();
        return rc2.getCommitDate().compareTo(rc1.getCommitDate());
    }
    return super.compare(viewer, e1, e2);
}
Also used : GitModelCache(org.eclipse.egit.ui.internal.synchronize.model.GitModelCache) Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob) GitModelWorkingTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)

Example 2 with GitModelCommit

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit in project egit by eclipse.

the class GitChangeSetSorterTest method workingTreeShouldBeLessThanCommit.

@Test
public void workingTreeShouldBeLessThanCommit() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCommit commit = mock(GitModelCommit.class);
    GitModelWorkingTree workingTree = mock(GitModelWorkingTree.class);
    // when
    int actual = sorter.compare(viewer, workingTree, commit);
    // then
    assertTrue(actual < 0);
}
Also used : GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) GitModelWorkingTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree) Test(org.junit.Test)

Example 3 with GitModelCommit

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit in project egit by eclipse.

the class GitChangeSetSorterTest method shouldOrderCommitsByCommitDate.

/*
	 * Test for commit chronological order
	 */
@Test
public void shouldOrderCommitsByCommitDate() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCommit commit1 = mock(GitModelCommit.class);
    GitModelCommit commit2 = mock(GitModelCommit.class);
    Commit mockCommit1 = mock(Commit.class);
    Commit mockCommit2 = mock(Commit.class);
    when(mockCommit1.getCommitDate()).thenReturn(new Date(333333L));
    when(mockCommit2.getCommitDate()).thenReturn(new Date(555555L));
    when(commit1.getCachedCommitObj()).thenReturn(mockCommit1);
    when(commit2.getCachedCommitObj()).thenReturn(mockCommit2);
    // when
    int actual1 = sorter.compare(viewer, commit1, commit2);
    int actual2 = sorter.compare(viewer, commit2, commit1);
    // then
    assertTrue(actual1 > 0);
    assertTrue(actual2 < 0);
}
Also used : Commit(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) Date(java.util.Date) Test(org.junit.Test)

Example 4 with GitModelCommit

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit in project egit by eclipse.

the class GitChangeSetSorterTest method commitTreeShouldBeLessThanBlob.

@Test
public void commitTreeShouldBeLessThanBlob() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCommit commit = mock(GitModelCommit.class);
    GitModelBlob blob = mock(GitModelBlob.class);
    // when
    int actual = sorter.compare(viewer, commit, blob);
    // then
    assertTrue(actual < 0);
}
Also used : GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob) Test(org.junit.Test)

Example 5 with GitModelCommit

use of org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit in project egit by eclipse.

the class GitChangeSetSorterTest method commitTreeShouldBeGreaterThanCache.

@Test
public void commitTreeShouldBeGreaterThanCache() {
    // given
    Viewer viewer = mock(Viewer.class);
    GitChangeSetSorter sorter = new GitChangeSetSorter();
    GitModelCommit commit = mock(GitModelCommit.class);
    GitModelCache cache = mock(GitModelCache.class);
    // when
    int actual = sorter.compare(viewer, commit, cache);
    // then
    assertTrue(actual > 0);
}
Also used : GitModelCache(org.eclipse.egit.ui.internal.synchronize.model.GitModelCache) GitModelCommit(org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit) CommonViewer(org.eclipse.ui.navigator.CommonViewer) Viewer(org.eclipse.jface.viewers.Viewer) Test(org.junit.Test)

Aggregations

GitModelCommit (org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit)11 Viewer (org.eclipse.jface.viewers.Viewer)8 CommonViewer (org.eclipse.ui.navigator.CommonViewer)8 Test (org.junit.Test)8 Commit (org.eclipse.egit.core.synchronize.GitCommitsModelCache.Commit)3 GitModelBlob (org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)3 GitModelCache (org.eclipse.egit.ui.internal.synchronize.model.GitModelCache)3 GitModelWorkingTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree)3 GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 GitChangeSetModelProvider (org.eclipse.egit.ui.internal.synchronize.GitChangeSetModelProvider)1