All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowBroadcastPendingResult Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package org.robolectric.shadows;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;

@Implements(BroadcastReceiver.PendingResult.class)
public final class ShadowBroadcastPendingResult {
    @RealObject BroadcastReceiver.PendingResult pendingResult;

    static BroadcastReceiver.PendingResult create(int resultCode, String resultData, Bundle resultExtras, boolean ordered) {
      return new BroadcastReceiver.PendingResult(
              resultCode,
              resultData,
              resultExtras,
              0 /* type */,
              ordered,
              false /*sticky*/,
              null /* ibinder token */,
              0 /* userid */);

    }

    private final SettableFuture finished = SettableFuture.create();

    @Implementation
    public final void finish() {
      Preconditions.checkState(finished.set(pendingResult), "Broadcast already finished");
    }

    public ListenableFuture getFuture() {
      return finished;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy