Skip to content

Commit aabcc25

Browse files
committed
Replace EasyMock with Mockito
Change-Id: I6d903849de08e995b6d23b4e6eb7bd28eee8eea7 Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
1 parent 4c4cb4b commit aabcc25

3 files changed

Lines changed: 98 additions & 118 deletions

File tree

org.eclipse.egit.core.test/META-INF/MANIFEST.MF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
1111
org.eclipse.team.core;bundle-version="[3.4.0,4.0.0)",
1212
org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
1313
org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
14-
org.junit4;bundle-version="[4.3.0,5.0.0)"
14+
org.junit4;bundle-version="[4.3.0,5.0.0)",
15+
org.mockito;bundle-version="[1.8.0,1.9.0)"
1516
Bundle-ActivationPolicy: lazy
16-
Import-Package: org.easymock;version="[2.4.0,3.0.0)",
17+
Import-Package: org.mockito;version="[1.8.0,1.9.0)",
18+
org.mockito.stubbing;version="[1.8.0,1.9.0)",
1719
org.eclipse.egit.core;version="[0.12.0,0.13.0)",
1820
org.eclipse.egit.core.op;version="[0.12.0,0.13.0)",
1921
org.eclipse.egit.core.project;version="[0.12.0,0.13.0)",

org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java

Lines changed: 78 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
import static junit.framework.Assert.assertFalse;
1212
import static junit.framework.Assert.assertTrue;
13-
import static org.easymock.EasyMock.anyObject;
14-
import static org.easymock.EasyMock.createMock;
15-
import static org.easymock.EasyMock.expect;
16-
import static org.easymock.EasyMock.replay;
17-
import static org.easymock.EasyMock.verify;
1813
import static org.eclipse.jgit.lib.Constants.HEAD;
14+
import static org.mockito.Matchers.any;
15+
import static org.mockito.Mockito.mock;
16+
import static org.mockito.Mockito.when;
1917

2018
import java.io.ByteArrayInputStream;
2119
import java.io.File;
@@ -91,13 +89,11 @@ public void shouldReturnFalseWhenRemoteDoesNotExist() {
9189
null);
9290

9391
// given
94-
IResource local = createMock(IResource.class);
95-
expect(local.exists()).andReturn(false);
96-
replay(local);
92+
IResource local = mock(IResource.class);
93+
when(local.exists()).thenReturn(false);
9794

9895
// then
9996
assertFalse(grvc.compare(local, null));
100-
verify(local);
10197
}
10298

10399
@Test
@@ -108,15 +104,13 @@ public void shouldReturnFalseWhenRemoteDoesNotExist2() throws Exception{
108104
null);
109105

110106
// given
111-
IResource local = createMock(IResource.class);
112-
expect(local.exists()).andReturn(false);
113-
replay(local);
107+
IResource local = mock(IResource.class);
108+
when(local.exists()).thenReturn(false);
114109
IResourceVariant remote = new GitFolderResourceVariant(repo, null,
115110
ObjectId.zeroId(), "./");
116111

117112
// then
118113
assertFalse(grvc.compare(local, remote));
119-
verify(local);
120114
}
121115

122116
/**
@@ -132,17 +126,14 @@ public void shouldReturnFalseWhenComparingFileAndContainer() {
132126
null);
133127

134128
// given
135-
IFile local = createMock(IFile.class);
136-
expect(local.exists()).andReturn(true);
137-
replay(local);
129+
IFile local = mock(IFile.class);
130+
when(local.exists()).thenReturn(true);
138131

139-
IResourceVariant remote = createMock(IResourceVariant.class);
140-
expect(remote.isContainer()).andReturn(true);
141-
replay(remote);
132+
IResourceVariant remote = mock(IResourceVariant.class);
133+
when(remote.isContainer()).thenReturn(true);
142134

143135
// then
144136
assertFalse(grvc.compare(local, remote));
145-
verify(local, remote);
146137
}
147138

148139
/**
@@ -159,12 +150,10 @@ public void shouldReturnFalseWhenComparingContainerAndContainer()
159150
null);
160151

161152
// given
162-
IPath localPath = createMock(IPath.class);
163-
replay(localPath);
164-
IContainer local = createMock(IContainer.class);
165-
expect(local.exists()).andReturn(true).times(2);
166-
expect(local.getFullPath()).andReturn(localPath);
167-
replay(local);
153+
IPath localPath = mock(IPath.class);
154+
IContainer local = mock(IContainer.class);
155+
when(local.exists()).thenReturn(true);
156+
when(local.getFullPath()).thenReturn(localPath);
168157

169158
File file = testRepo.createFile(iProject, "test" + File.separator
170159
+ "keep");
@@ -177,7 +166,6 @@ public void shouldReturnFalseWhenComparingContainerAndContainer()
177166

178167
// then
179168
assertFalse(grvc.compare(local, remote));
180-
verify(local, localPath);
181169
}
182170

183171
/**
@@ -202,17 +190,15 @@ public void shouldReturnTrueWhenComparingContainerAndContainer()
202190
String path = Repository.stripWorkDir(repo.getWorkTree(), file);
203191
IPath iPath = new Path(File.separator + path);
204192

205-
IContainer local = createMock(IContainer.class);
206-
expect(local.exists()).andReturn(true).times(2);
207-
expect(local.getFullPath()).andReturn(iPath).anyTimes();
208-
replay(local);
193+
IContainer local = mock(IContainer.class);
194+
when(local.exists()).thenReturn(true);
195+
when(local.getFullPath()).thenReturn(iPath);
209196

210197
GitFolderResourceVariant remote = new GitFolderResourceVariant(repo, null,
211198
commit.getTree(), path);
212199

213200
// then
214201
assertTrue(grvc.compare(local, remote));
215-
verify(local);
216202
}
217203

218204
/**
@@ -234,27 +220,23 @@ public void shouldReturnFalseWhenContentLengthIsDifferent()
234220
dataSet);
235221

236222
// given
237-
IFile local = createMock(IFile.class);
238-
expect(local.exists()).andReturn(true);
239-
expect(local.getProject()).andReturn(project.getProject()).anyTimes();
240-
expect(local.getContents()).andReturn(
223+
IFile local = mock(IFile.class);
224+
when(local.exists()).thenReturn(true);
225+
when(local.getProject()).thenReturn(project.getProject());
226+
when(local.getContents()).thenReturn(
241227
new ByteArrayInputStream(longContent));
242-
replay(local);
243228

244-
IStorage storage = createMock(IStorage.class);
245-
expect(storage.getContents()).andReturn(
229+
IStorage storage = mock(IStorage.class);
230+
when(storage.getContents()).thenReturn(
246231
new ByteArrayInputStream(shortContent));
247-
replay(storage);
248232

249-
IResourceVariant remote = createMock(IResourceVariant.class);
250-
expect(remote.isContainer()).andReturn(false);
251-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
252-
storage).anyTimes();
253-
replay(remote);
233+
IResourceVariant remote = mock(IResourceVariant.class);
234+
when(remote.isContainer()).thenReturn(false);
235+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
236+
storage);
254237

255238
// then
256239
assertFalse(grvc.compare(local, remote));
257-
verify(local, remote, storage);
258240
}
259241

260242
/**
@@ -276,27 +258,23 @@ public void shouldReturnFalseWhenShortContentIsDifferent() throws Exception {
276258
dataSet);
277259

278260
// given
279-
IFile local = createMock(IFile.class);
280-
expect(local.exists()).andReturn(true);
281-
expect(local.getProject()).andReturn(project.getProject());
282-
expect(local.getContents()).andReturn(
261+
IFile local = mock(IFile.class);
262+
when(local.exists()).thenReturn(true);
263+
when(local.getProject()).thenReturn(project.getProject());
264+
when(local.getContents()).thenReturn(
283265
new ByteArrayInputStream(localContent));
284-
replay(local);
285266

286-
IStorage storage = createMock(IStorage.class);
287-
expect(storage.getContents()).andReturn(
267+
IStorage storage = mock(IStorage.class);
268+
when(storage.getContents()).thenReturn(
288269
new ByteArrayInputStream(remoteContent));
289-
replay(storage);
290270

291-
IResourceVariant remote = createMock(IResourceVariant.class);
292-
expect(remote.isContainer()).andReturn(false);
293-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
294-
storage).anyTimes();
295-
replay(remote);
271+
IResourceVariant remote = mock(IResourceVariant.class);
272+
when(remote.isContainer()).thenReturn(false);
273+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
274+
storage);
296275

297276
// then
298277
assertFalse(grvc.compare(local, remote));
299-
verify(local, remote);
300278
}
301279

302280
/**
@@ -320,27 +298,23 @@ public void shouldReturnFalseWhenLongContentIsDifferent() throws Exception {
320298
dataSet);
321299

322300
// given
323-
IFile local = createMock(IFile.class);
324-
expect(local.exists()).andReturn(true);
325-
expect(local.getProject()).andReturn(project.getProject());
326-
expect(local.getContents()).andReturn(
301+
IFile local = mock(IFile.class);
302+
when(local.exists()).thenReturn(true);
303+
when(local.getProject()).thenReturn(project.getProject());
304+
when(local.getContents()).thenReturn(
327305
new ByteArrayInputStream(localContent));
328-
replay(local);
329306

330-
IStorage storage = createMock(IStorage.class);
331-
expect(storage.getContents()).andReturn(
307+
IStorage storage = mock(IStorage.class);
308+
when(storage.getContents()).thenReturn(
332309
new ByteArrayInputStream(remoteContent));
333-
replay(storage);
334310

335-
IResourceVariant remote = createMock(IResourceVariant.class);
336-
expect(remote.isContainer()).andReturn(false);
337-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
338-
storage).anyTimes();
339-
replay(remote);
311+
IResourceVariant remote = mock(IResourceVariant.class);
312+
when(remote.isContainer()).thenReturn(false);
313+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
314+
storage);
340315

341316
// then
342317
assertFalse(grvc.compare(local, remote));
343-
verify(local, remote);
344318
}
345319

346320
/**
@@ -368,27 +342,23 @@ public void shouldReturnFalseWhenLongContentLengthIsDifferent()
368342
dataSet);
369343

370344
// given
371-
IFile local = createMock(IFile.class);
372-
expect(local.exists()).andReturn(true);
373-
expect(local.getProject()).andReturn(project.getProject());
374-
expect(local.getContents()).andReturn(
345+
IFile local = mock(IFile.class);
346+
when(local.exists()).thenReturn(true);
347+
when(local.getProject()).thenReturn(project.getProject());
348+
when(local.getContents()).thenReturn(
375349
new ByteArrayInputStream(localContent));
376-
replay(local);
377350

378-
IStorage storage = createMock(IStorage.class);
379-
expect(storage.getContents()).andReturn(
351+
IStorage storage = mock(IStorage.class);
352+
when(storage.getContents()).thenReturn(
380353
new ByteArrayInputStream(remoteContent));
381-
replay(storage);
382354

383-
IResourceVariant remote = createMock(IResourceVariant.class);
384-
expect(remote.isContainer()).andReturn(false);
385-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
386-
storage).anyTimes();
387-
replay(remote);
355+
IResourceVariant remote = mock(IResourceVariant.class);
356+
when(remote.isContainer()).thenReturn(false);
357+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
358+
storage);
388359

389360
// then
390361
assertFalse(grvc.compare(local, remote));
391-
verify(local, remote, storage);
392362
}
393363

394364
/**
@@ -409,27 +379,23 @@ public void shouldReturnTrueWhenShortContentIsDifferent() throws Exception {
409379
dataSet);
410380

411381
// given
412-
IFile local = createMock(IFile.class);
413-
expect(local.exists()).andReturn(true);
414-
expect(local.getProject()).andReturn(project.getProject());
415-
expect(local.getContents()).andReturn(
382+
IFile local = mock(IFile.class);
383+
when(local.exists()).thenReturn(true);
384+
when(local.getProject()).thenReturn(project.getProject());
385+
when(local.getContents()).thenReturn(
416386
new ByteArrayInputStream(localContent));
417-
replay(local);
418387

419-
IStorage storage = createMock(IStorage.class);
420-
expect(storage.getContents()).andReturn(
388+
IStorage storage = mock(IStorage.class);
389+
when(storage.getContents()).thenReturn(
421390
new ByteArrayInputStream(remoteContent));
422-
replay(storage);
423391

424-
IResourceVariant remote = createMock(IResourceVariant.class);
425-
expect(remote.isContainer()).andReturn(false);
426-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
427-
storage).anyTimes();
428-
replay(remote);
392+
IResourceVariant remote = mock(IResourceVariant.class);
393+
when(remote.isContainer()).thenReturn(false);
394+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
395+
storage);
429396

430397
// then
431398
assertTrue(grvc.compare(local, remote));
432-
verify(local, remote);
433399
}
434400

435401
/**
@@ -453,27 +419,23 @@ public void shouldReturnTrueWhenLongContentLengthIsDifferent()
453419
dataSet);
454420

455421
// given
456-
IFile local = createMock(IFile.class);
457-
expect(local.exists()).andReturn(true);
458-
expect(local.getProject()).andReturn(project.getProject());
459-
expect(local.getContents()).andReturn(
422+
IFile local = mock(IFile.class);
423+
when(local.exists()).thenReturn(true);
424+
when(local.getProject()).thenReturn(project.getProject());
425+
when(local.getContents()).thenReturn(
460426
new ByteArrayInputStream(localContent));
461-
replay(local);
462427

463-
IStorage storage = createMock(IStorage.class);
464-
expect(storage.getContents()).andReturn(
428+
IStorage storage = mock(IStorage.class);
429+
when(storage.getContents()).thenReturn(
465430
new ByteArrayInputStream(remoteContent));
466-
replay(storage);
467431

468-
IResourceVariant remote = createMock(IResourceVariant.class);
469-
expect(remote.isContainer()).andReturn(false);
470-
expect(remote.getStorage((IProgressMonitor) anyObject())).andReturn(
471-
storage).anyTimes();
472-
replay(remote);
432+
IResourceVariant remote = mock(IResourceVariant.class);
433+
when(remote.isContainer()).thenReturn(false);
434+
when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(
435+
storage);
473436

474437
// then
475438
assertTrue(grvc.compare(local, remote));
476-
verify(local, remote, storage);
477439
}
478440

479441
/* ==================================================

0 commit comments

Comments
 (0)