|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 package org.mozilla.gecko.background.sync.helpers; |
|
5 |
|
6 import static junit.framework.Assert.assertEquals; |
|
7 import static junit.framework.Assert.assertFalse; |
|
8 import static junit.framework.Assert.assertTrue; |
|
9 |
|
10 import java.util.Arrays; |
|
11 |
|
12 import org.mozilla.gecko.sync.repositories.domain.Record; |
|
13 |
|
14 import junit.framework.AssertionFailedError; |
|
15 |
|
16 public class ExpectFetchSinceDelegate extends DefaultFetchDelegate { |
|
17 private String[] expected; |
|
18 private long earliest; |
|
19 |
|
20 public ExpectFetchSinceDelegate(long timestamp, String[] guids) { |
|
21 expected = guids; |
|
22 earliest = timestamp; |
|
23 Arrays.sort(expected); |
|
24 } |
|
25 |
|
26 @Override |
|
27 public void onFetchCompleted(final long fetchEnd) { |
|
28 AssertionFailedError err = null; |
|
29 try { |
|
30 int countSpecials = 0; |
|
31 for (Record record : records) { |
|
32 // Check if record should be ignored. |
|
33 if (!ignore.contains(record.guid)) { |
|
34 assertFalse(-1 == Arrays.binarySearch(this.expected, record.guid)); |
|
35 } else { |
|
36 countSpecials++; |
|
37 } |
|
38 // Check that record is later than timestamp-earliest. |
|
39 assertTrue(record.lastModified >= this.earliest); |
|
40 } |
|
41 assertEquals(this.expected.length, records.size() - countSpecials); |
|
42 } catch (AssertionFailedError e) { |
|
43 err = e; |
|
44 } |
|
45 performNotify(err); |
|
46 } |
|
47 } |