org.robolectric.shadows.ShadowBroadcastPendingResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shadows-core-v19 Show documentation
Show all versions of shadows-core-v19 Show documentation
An alternative Android testing framework.
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;
}
}