use of org.eclipse.core.resources.IStorage in project egit by eclipse.
the class GitResourceVariantComparatorTest method shouldReturnTrueWhenLongContentLengthIsDifferent.
/**
* Compare two 'large' files that have same content length and content
* should return true.
*
* @throws Exception
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenLongContentLengthIsDifferent() throws Exception {
// when
byte[] localContent = new byte[8192];
Arrays.fill(localContent, (byte) 'a');
byte[] remoteContent = new byte[8192];
Arrays.fill(remoteContent, (byte) 'a');
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
assertTrue(grvc.compare(local, remote));
}
use of org.eclipse.core.resources.IStorage in project egit by eclipse.
the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentLengthIsDifferent.
/**
* Comparing two 'large' files that have different length but same content
* should return false.
* <p>
* This and previous three test cases cover almost the same functionality
* but they are covering all return points in compare methods that can be
* used when comparing files content
*
* @throws Exception
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentLengthIsDifferent() throws Exception {
// when
byte[] localContent = new byte[8192];
Arrays.fill(localContent, (byte) 'a');
byte[] remoteContent = new byte[8200];
Arrays.fill(remoteContent, (byte) 'a');
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));
}
use of org.eclipse.core.resources.IStorage in project egit by eclipse.
the class GitResourceVariantComparatorTest method shouldReturnFalseWhenContentLengthIsDifferent.
/**
* Compare() should return false when comparing two files with different
* content length
*
* @throws Exception
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenContentLengthIsDifferent() throws Exception {
// when
byte[] shortContent = "short content".getBytes("UTF-8");
byte[] longContent = "very long long 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(longContent));
IStorage storage = mock(IStorage.class);
when(storage.getContents()).thenReturn(new ByteArrayInputStream(shortContent));
IResourceVariant remote = mock(IResourceVariant.class);
when(remote.isContainer()).thenReturn(false);
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
// then
assertFalse(grvc.compare(local, remote));
}
use of org.eclipse.core.resources.IStorage in project egit by eclipse.
the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentIsDifferent.
/**
* Comparing two 'large' files that have same length and almost identical
* content should return false.
*
* @throws Exception
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentIsDifferent() throws Exception {
// when
byte[] localContent = new byte[8192];
Arrays.fill(localContent, (byte) 'a');
byte[] remoteContent = new byte[8192];
Arrays.fill(remoteContent, (byte) 'a');
remoteContent[8101] = 'b';
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));
}
use of org.eclipse.core.resources.IStorage in project egit by eclipse.
the class IndexFileRevisionTest method readContents.
private static String readContents(IndexFileRevision revision) throws Exception {
IStorage storage = revision.getStorage(null);
InputStream in = storage.getContents();
ByteBuffer buffer = IO.readWholeStream(in, 10);
return new String(buffer.array(), 0, buffer.limit(), "UTF-8");
}
Aggregations