urbanairship-core/src/test/java/com/urbanairship/remotedata/RemoteDataTest.java
@Test
    public void testPayloadsForTypeWithMissingTypeInResponse() throws Exception {
        remoteData.init();
        remoteData.dataStore.savePayload(payload);

        Assert.assertEquals(remoteData.dataStore.getPayloads().size(), 1);

        runLooperTasks();

        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();

        // The first callback should be the cached payload
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), payload);

        subscribedPayloads.clear();

        remoteData.handleRefreshResponse(asSet(otherPayload));

        runLooperTasks();

        // The second callback should be an empty placeholder
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), emptyPayload);
    }
/**
     * Test that a type missing in the response will result in an empty model object in the callback.
     */
Test that a type missing in the response will result in an empty model object in the callback.
Test that a type missing in the response will result in an empty model object in the callback .
@Test
    public void testPayloadsForTypeWithMissingTypeInResponse() throws Exception {
        remoteData.init();
        remoteData.dataStore.savePayload(payload);
        Assert.assertEquals(remoteData.dataStore.getPayloads().size(), 1);
        runLooperTasks();
        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();
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), payload);
        subscribedPayloads.clear();
        remoteData.handleRefreshResponse(asSet(otherPayload));
        runLooperTasks();
        Assert.assertEquals(subscribedPayloads.size(), 1);
        Assert.assertEquals(subscribedPayloads.get(0), emptyPayload);
    }
@ Test public void testPayloadsForTypeWithMissingTypeInResponse ( ) throws Exception { remoteData . init ( ) ; remoteData . dataStore . savePayload ( payload ) ; Assert . assertEquals ( remoteData . dataStore . getPayloads ( ) . size ( ) , 1 ) ; runLooperTasks ( ) ; 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 ( ) ; Assert . assertEquals ( subscribedPayloads . size ( ) , 1 ) ; Assert . assertEquals ( subscribedPayloads . get ( 0 ) , payload ) ; subscribedPayloads . clear ( ) ; remoteData . handleRefreshResponse ( asSet ( otherPayload ) ) ; runLooperTasks ( ) ; Assert . assertEquals ( subscribedPayloads . size ( ) , 1 ) ; Assert . assertEquals ( subscribedPayloads . get ( 0 ) , emptyPayload ) ; }
Test that a type missing in the response will result in an empty model object in the callback.
Test that a type missing in the response will result in an empty model object in the callback .
// The first callback should be the cached payload // The second callback should be an empty placeholder