use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldReturnNullResourceVariant2.
/**
* getResourceVariant() should return null when given resource doesn't exist
* in repository.
*
* @throws Exception
*/
@Test
public void shouldReturnNullResourceVariant2() throws Exception {
// when
IPackageFragment iPackage = project.createPackage("org.egit.test");
IType mainJava = project.createType(iPackage, "Main.java", "class Main {}");
try (Git git = new Git(repo)) {
git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
}
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitSyncCache cache = GitSyncCache.getAllData(dataSet, new NullProgressMonitor());
// given
GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(cache, dataSet);
// then
assertNull(grvt.getResourceVariant(mainJava.getResource()));
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldReturnTwoRoots.
/**
* When we have two or more project associated with repository, roots()
* method should return list of project. In this case we have two project
* associated with particular repository, therefore '2' value is expected.
*
* @throws Exception
*/
@Test
public void shouldReturnTwoRoots() throws Exception {
// when
// create second project
TestProject secondProject = new TestProject(true, "Project-2");
try {
IProject secondIProject = secondProject.project;
// add connect project with repository
new ConnectProviderOperation(secondIProject, gitDir).execute(null);
try (Git git = new Git(repo)) {
git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
}
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
// then
IResource[] roots = grvt.roots();
// sort in order to be able to assert the project instances
Arrays.sort(roots, new Comparator<IResource>() {
@Override
public int compare(IResource r1, IResource r2) {
String path1 = r1.getFullPath().toString();
String path2 = r2.getFullPath().toString();
return path1.compareTo(path2);
}
});
assertEquals(2, roots.length);
IResource actualProject = roots[0];
assertEquals(this.project.project, actualProject);
IResource actualProject1 = roots[1];
assertEquals(secondIProject, actualProject1);
} finally {
secondProject.dispose();
}
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldReturnNullResourceVariant.
/**
* Checks that getResourceVariant will not throw NPE for null argument. This
* method is called with null argument when local or remote resource does
* not exist.
*
* @throws Exception
*/
@Test
public void shouldReturnNullResourceVariant() throws Exception {
// when
try (Git git = new Git(repo)) {
git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
}
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(null, dataSet);
// then
assertNull(grvt.getResourceVariant(null));
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.
the class GitSubscriberResourceMappingContextTest method prepareContext.
private RemoteResourceMappingContext prepareContext(String srcRev, String dstRev) throws Exception {
GitSynchronizeData gsd = new GitSynchronizeData(repo, srcRev, dstRev, true);
GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsds);
subscriber.init(new NullProgressMonitor());
return new GitSubscriberResourceMappingContext(subscriber, gsds);
}
use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.
the class GitResourceVariantComparatorTest method shouldReturnFalseWhenShortContentIsDifferent.
/**
* Comparing two files that have same content length but having small
* difference inside content should return false.
*
* @throws Exception
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenShortContentIsDifferent() throws Exception {
// when
byte[] localContent = "very long long content".getBytes("UTF-8");
// this typo should be here
byte[] remoteContent = "very long lonk content".getBytes("UTF-8");
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
// given
IFile local = mock(IFile.class);
when(local.exists()).thenReturn(true);
when(local.getProject()).thenReturn(project.getProject());
when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
IStorage storage = mock(IStorage.class);
when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
IResourceVariant remote = mock(IResourceVariant.class);
when(remote.isContainer()).thenReturn(false);
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
// then
assertFalse(grvc.compare(local, remote));
}
Aggregations