1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/tests/background/junit3/src/sync/helpers/ExpectFetchSinceDelegate.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 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.assertFalse; 1.11 +import static junit.framework.Assert.assertTrue; 1.12 + 1.13 +import java.util.Arrays; 1.14 + 1.15 +import org.mozilla.gecko.sync.repositories.domain.Record; 1.16 + 1.17 +import junit.framework.AssertionFailedError; 1.18 + 1.19 +public class ExpectFetchSinceDelegate extends DefaultFetchDelegate { 1.20 + private String[] expected; 1.21 + private long earliest; 1.22 + 1.23 + public ExpectFetchSinceDelegate(long timestamp, String[] guids) { 1.24 + expected = guids; 1.25 + earliest = timestamp; 1.26 + Arrays.sort(expected); 1.27 + } 1.28 + 1.29 + @Override 1.30 + public void onFetchCompleted(final long fetchEnd) { 1.31 + AssertionFailedError err = null; 1.32 + try { 1.33 + int countSpecials = 0; 1.34 + for (Record record : records) { 1.35 + // Check if record should be ignored. 1.36 + if (!ignore.contains(record.guid)) { 1.37 + assertFalse(-1 == Arrays.binarySearch(this.expected, record.guid)); 1.38 + } else { 1.39 + countSpecials++; 1.40 + } 1.41 + // Check that record is later than timestamp-earliest. 1.42 + assertTrue(record.lastModified >= this.earliest); 1.43 + } 1.44 + assertEquals(this.expected.length, records.size() - countSpecials); 1.45 + } catch (AssertionFailedError e) { 1.46 + err = e; 1.47 + } 1.48 + performNotify(err); 1.49 + } 1.50 +}