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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 package org.mozilla.gecko.background.sync.helpers;
michael@0 5
michael@0 6 import static junit.framework.Assert.assertEquals;
michael@0 7 import static junit.framework.Assert.assertFalse;
michael@0 8 import static junit.framework.Assert.assertTrue;
michael@0 9
michael@0 10 import java.util.Arrays;
michael@0 11
michael@0 12 import org.mozilla.gecko.sync.repositories.domain.Record;
michael@0 13
michael@0 14 import junit.framework.AssertionFailedError;
michael@0 15
michael@0 16 public class ExpectFetchSinceDelegate extends DefaultFetchDelegate {
michael@0 17 private String[] expected;
michael@0 18 private long earliest;
michael@0 19
michael@0 20 public ExpectFetchSinceDelegate(long timestamp, String[] guids) {
michael@0 21 expected = guids;
michael@0 22 earliest = timestamp;
michael@0 23 Arrays.sort(expected);
michael@0 24 }
michael@0 25
michael@0 26 @Override
michael@0 27 public void onFetchCompleted(final long fetchEnd) {
michael@0 28 AssertionFailedError err = null;
michael@0 29 try {
michael@0 30 int countSpecials = 0;
michael@0 31 for (Record record : records) {
michael@0 32 // Check if record should be ignored.
michael@0 33 if (!ignore.contains(record.guid)) {
michael@0 34 assertFalse(-1 == Arrays.binarySearch(this.expected, record.guid));
michael@0 35 } else {
michael@0 36 countSpecials++;
michael@0 37 }
michael@0 38 // Check that record is later than timestamp-earliest.
michael@0 39 assertTrue(record.lastModified >= this.earliest);
michael@0 40 }
michael@0 41 assertEquals(this.expected.length, records.size() - countSpecials);
michael@0 42 } catch (AssertionFailedError e) {
michael@0 43 err = e;
michael@0 44 }
michael@0 45 performNotify(err);
michael@0 46 }
michael@0 47 }

mercurial