michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.sync.helpers; michael@0: michael@0: import static junit.framework.Assert.assertEquals; michael@0: import static junit.framework.Assert.assertTrue; michael@0: michael@0: import java.util.HashSet; michael@0: import java.util.concurrent.atomic.AtomicLong; michael@0: michael@0: import junit.framework.AssertionFailedError; michael@0: michael@0: import org.mozilla.gecko.sync.repositories.domain.Record; michael@0: michael@0: public class ExpectManyStoredDelegate extends DefaultStoreDelegate { michael@0: HashSet expectedGUIDs; michael@0: AtomicLong stored; michael@0: michael@0: public ExpectManyStoredDelegate(Record[] records) { michael@0: HashSet s = new HashSet(); michael@0: for (Record record : records) { michael@0: s.add(record.guid); michael@0: } michael@0: expectedGUIDs = s; michael@0: stored = new AtomicLong(0); michael@0: } michael@0: michael@0: @Override michael@0: public void onStoreCompleted(long storeEnd) { michael@0: try { michael@0: assertEquals(expectedGUIDs.size(), stored.get()); michael@0: performNotify(); michael@0: } catch (AssertionFailedError e) { michael@0: performNotify(e); michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void onRecordStoreSucceeded(String guid) { michael@0: try { michael@0: assertTrue(expectedGUIDs.contains(guid)); michael@0: } catch (AssertionFailedError e) { michael@0: performNotify(e); michael@0: } michael@0: stored.incrementAndGet(); michael@0: } michael@0: }