mobile/android/tests/background/junit3/src/sync/helpers/ExpectManyStoredDelegate.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/tests/background/junit3/src/sync/helpers/ExpectManyStoredDelegate.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +package org.mozilla.gecko.background.sync.helpers;
     1.8 +
     1.9 +import static junit.framework.Assert.assertEquals;
    1.10 +import static junit.framework.Assert.assertTrue;
    1.11 +
    1.12 +import java.util.HashSet;
    1.13 +import java.util.concurrent.atomic.AtomicLong;
    1.14 +
    1.15 +import junit.framework.AssertionFailedError;
    1.16 +
    1.17 +import org.mozilla.gecko.sync.repositories.domain.Record;
    1.18 +
    1.19 +public class ExpectManyStoredDelegate extends DefaultStoreDelegate {
    1.20 +  HashSet<String> expectedGUIDs;
    1.21 +  AtomicLong stored;
    1.22 +
    1.23 +  public ExpectManyStoredDelegate(Record[] records) {
    1.24 +    HashSet<String> s = new HashSet<String>();
    1.25 +    for (Record record : records) {
    1.26 +      s.add(record.guid);
    1.27 +    }
    1.28 +    expectedGUIDs = s;
    1.29 +    stored = new AtomicLong(0);
    1.30 +  }
    1.31 +
    1.32 +  @Override
    1.33 +  public void onStoreCompleted(long storeEnd) {
    1.34 +    try {
    1.35 +      assertEquals(expectedGUIDs.size(), stored.get());
    1.36 +      performNotify();
    1.37 +    } catch (AssertionFailedError e) {
    1.38 +      performNotify(e);
    1.39 +    }
    1.40 +  }
    1.41 +
    1.42 +  @Override
    1.43 +  public void onRecordStoreSucceeded(String guid) {
    1.44 +    try {
    1.45 +      assertTrue(expectedGUIDs.contains(guid));
    1.46 +    } catch (AssertionFailedError e) {
    1.47 +      performNotify(e);
    1.48 +    }
    1.49 +    stored.incrementAndGet();
    1.50 +  }
    1.51 +}

mercurial