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.assertFalse; michael@0: import static junit.framework.Assert.assertTrue; michael@0: michael@0: import java.util.Arrays; michael@0: michael@0: import org.mozilla.gecko.sync.repositories.domain.Record; michael@0: michael@0: import junit.framework.AssertionFailedError; michael@0: michael@0: public class ExpectFetchSinceDelegate extends DefaultFetchDelegate { michael@0: private String[] expected; michael@0: private long earliest; michael@0: michael@0: public ExpectFetchSinceDelegate(long timestamp, String[] guids) { michael@0: expected = guids; michael@0: earliest = timestamp; michael@0: Arrays.sort(expected); michael@0: } michael@0: michael@0: @Override michael@0: public void onFetchCompleted(final long fetchEnd) { michael@0: AssertionFailedError err = null; michael@0: try { michael@0: int countSpecials = 0; michael@0: for (Record record : records) { michael@0: // Check if record should be ignored. michael@0: if (!ignore.contains(record.guid)) { michael@0: assertFalse(-1 == Arrays.binarySearch(this.expected, record.guid)); michael@0: } else { michael@0: countSpecials++; michael@0: } michael@0: // Check that record is later than timestamp-earliest. michael@0: assertTrue(record.lastModified >= this.earliest); michael@0: } michael@0: assertEquals(this.expected.length, records.size() - countSpecials); michael@0: } catch (AssertionFailedError e) { michael@0: err = e; michael@0: } michael@0: performNotify(err); michael@0: } michael@0: }