|
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.assertTrue; |
|
8 |
|
9 import java.util.HashSet; |
|
10 import java.util.concurrent.atomic.AtomicLong; |
|
11 |
|
12 import junit.framework.AssertionFailedError; |
|
13 |
|
14 import org.mozilla.gecko.sync.repositories.domain.Record; |
|
15 |
|
16 public class ExpectManyStoredDelegate extends DefaultStoreDelegate { |
|
17 HashSet<String> expectedGUIDs; |
|
18 AtomicLong stored; |
|
19 |
|
20 public ExpectManyStoredDelegate(Record[] records) { |
|
21 HashSet<String> s = new HashSet<String>(); |
|
22 for (Record record : records) { |
|
23 s.add(record.guid); |
|
24 } |
|
25 expectedGUIDs = s; |
|
26 stored = new AtomicLong(0); |
|
27 } |
|
28 |
|
29 @Override |
|
30 public void onStoreCompleted(long storeEnd) { |
|
31 try { |
|
32 assertEquals(expectedGUIDs.size(), stored.get()); |
|
33 performNotify(); |
|
34 } catch (AssertionFailedError e) { |
|
35 performNotify(e); |
|
36 } |
|
37 } |
|
38 |
|
39 @Override |
|
40 public void onRecordStoreSucceeded(String guid) { |
|
41 try { |
|
42 assertTrue(expectedGUIDs.contains(guid)); |
|
43 } catch (AssertionFailedError e) { |
|
44 performNotify(e); |
|
45 } |
|
46 stored.incrementAndGet(); |
|
47 } |
|
48 } |