urbanairship-core/src/test/java/com/urbanairship/remotedata/RemoteDataTest.java
@Test
    public void testPayloadsForTypeDistinctness() {
        remoteData.init();

        final List<RemoteDataPayload> subscribedPayloads = new ArrayList<>();

        Observable<RemoteDataPayload> payloadsObservable = remoteData.payloadsForType("type");

        payloadsObservable.subscribe(new Subscriber<RemoteDataPayload>() {
            @Override
            public void onNext(RemoteDataPayload value) {
                subscribedPayloads.add(value);
            }
        });

        runLooperTasks();

        // Clear the first callback
        subscribedPayloads.clear();

        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();

        // We should get a second callback with the refreshed data
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), payload);

        subscribedPayloads.clear();

        // Replaying the response should not result in another callback because the data hasn't changed
        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads.size(), 0);

        // Sending a fresh payload with an updated timestamp should result in a new callback
        RemoteDataPayload freshPayload = new RemoteDataPayload(payload.getType(), payload.getTimestamp() + 100000, payload.getData());
        remoteData.handleRefreshResponse(asSet(freshPayload, otherPayload));
        runLooperTasks();

        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), freshPayload);
    }
/**
     * Test that a single type will only produce a callback if the payload has changed
     */
Test that a single type will only produce a callback if the payload has changed
Test that a single type will only produce a callback if the payload has changed
@Test
    public void testPayloadsForTypeDistinctness() {
        remoteData.init();
        final List<RemoteDataPayload> subscribedPayloads = new ArrayList<>();
        Observable<RemoteDataPayload> payloadsObservable = remoteData.payloadsForType("type");
        payloadsObservable.subscribe(new Subscriber<RemoteDataPayload>() {
            @Override
            public void onNext(RemoteDataPayload value) {
                subscribedPayloads.add(value);
            }
        });
        runLooperTasks();
        subscribedPayloads.clear();
        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), payload);
        subscribedPayloads.clear();
        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads.size(), 0);
        RemoteDataPayload freshPayload = new RemoteDataPayload(payload.getType(), payload.getTimestamp() + 100000, payload.getData());
        remoteData.handleRefreshResponse(asSet(freshPayload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), freshPayload);
    }
@ Test public void testPayloadsForTypeDistinctness ( ) { remoteData . init ( ) ; final List < RemoteDataPayload > subscribedPayloads = new ArrayList < > ( ) ; Observable < RemoteDataPayload > payloadsObservable = remoteData . payloadsForType ( "type" ) ; payloadsObservable . subscribe ( new Subscriber < RemoteDataPayload > ( ) { @ Override public void onNext ( RemoteDataPayload value ) { subscribedPayloads . add ( value ) ; } } ) ; runLooperTasks ( ) ; subscribedPayloads . clear ( ) ; remoteData . handleRefreshResponse ( asSet ( payload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads . size ( ) , 1 ) ; Assert . assertEquals ( subscribedPayloads . get ( 0 ) , payload ) ; subscribedPayloads . clear ( ) ; remoteData . handleRefreshResponse ( asSet ( payload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads . size ( ) , 0 ) ; RemoteDataPayload freshPayload = new RemoteDataPayload ( payload . getType ( ) , payload . getTimestamp ( ) + 100000 , payload . getData ( ) ) ; remoteData . handleRefreshResponse ( asSet ( freshPayload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads . size ( ) , 1 ) ; Assert . assertEquals ( subscribedPayloads . get ( 0 ) , freshPayload ) ; }
Test that a single type will only produce a callback if the payload has changed
Test that a single type will only produce a callback if the payload has changed
// Clear the first callback // We should get a second callback with the refreshed data // Replaying the response should not result in another callback because the data hasn't changed // Sending a fresh payload with an updated timestamp should result in a new callback