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

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

        Observable<Collection<RemoteDataPayload>> payloadsObservable = remoteData.payloadsForTypes(Arrays.asList("type", "otherType"));
        payloadsObservable.subscribe(new Subscriber<Collection<RemoteDataPayload>>(){
            @Override
            public void onNext(Collection<RemoteDataPayload> value) {
                subscribedPayloads.add(value);
            }
        });

        runLooperTasks();

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

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

        Assert.assertEquals(subscribedPayloads, Arrays.asList(asSet(payload, otherPayload)));

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

        subscribedPayloads.clear();

        // 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, Arrays.asList(asSet(freshPayload, otherPayload)));
    }
/**
     * Test that a multiple types will only produce a callback if at least one of the payloads has changed
     */
Test that a multiple types will only produce a callback if at least one of the payloads has changed
Test that a multiple types will only produce a callback if at least one of the payloads has changed
@Test
    public void testPayloadsForTypesDistinctness() {
        remoteData.init();
        final List<Collection<RemoteDataPayload>> subscribedPayloads = new ArrayList<>();
        Observable<Collection<RemoteDataPayload>> payloadsObservable = remoteData.payloadsForTypes(Arrays.asList("type", "otherType"));
        payloadsObservable.subscribe(new Subscriber<Collection<RemoteDataPayload>>(){
            @Override
            public void onNext(Collection<RemoteDataPayload> value) {
                subscribedPayloads.add(value);
            }
        });
        runLooperTasks();
        subscribedPayloads.clear();
        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads, Arrays.asList(asSet(payload, otherPayload)));
        remoteData.handleRefreshResponse(asSet(payload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads, Arrays.asList(asSet(payload, otherPayload)));
        subscribedPayloads.clear();
        RemoteDataPayload freshPayload = new RemoteDataPayload(payload.getType(), payload.getTimestamp() + 100000, payload.getData());
        remoteData.handleRefreshResponse(asSet(freshPayload, otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads, Arrays.asList(asSet(freshPayload, otherPayload)));
    }
@ Test public void testPayloadsForTypesDistinctness ( ) { remoteData . init ( ) ; final List < Collection < RemoteDataPayload > > subscribedPayloads = new ArrayList < > ( ) ; Observable < Collection < RemoteDataPayload > > payloadsObservable = remoteData . payloadsForTypes ( Arrays . asList ( "type" , "otherType" ) ) ; payloadsObservable . subscribe ( new Subscriber < Collection < RemoteDataPayload > > ( ) { @ Override public void onNext ( Collection < RemoteDataPayload > value ) { subscribedPayloads . add ( value ) ; } } ) ; runLooperTasks ( ) ; subscribedPayloads . clear ( ) ; remoteData . handleRefreshResponse ( asSet ( payload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads , Arrays . asList ( asSet ( payload , otherPayload ) ) ) ; remoteData . handleRefreshResponse ( asSet ( payload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads , Arrays . asList ( asSet ( payload , otherPayload ) ) ) ; subscribedPayloads . clear ( ) ; RemoteDataPayload freshPayload = new RemoteDataPayload ( payload . getType ( ) , payload . getTimestamp ( ) + 100000 , payload . getData ( ) ) ; remoteData . handleRefreshResponse ( asSet ( freshPayload , otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads , Arrays . asList ( asSet ( freshPayload , otherPayload ) ) ) ; }
Test that a multiple types will only produce a callback if at least one of the payloads has changed
Test that a multiple types will only produce a callback if at least one of the payloads has changed
// Clear the first callback // Replaying the response should not result in another callback because the timestamp hasn't changed // Sending a fresh payload with an updated timestamp should result in a new callback