TestWorkerBuilder


public class TestWorkerBuilder<W extends Worker> extends TestListenableWorkerBuilder


Builds instances of Worker which can be used for testing.

Parameters
<W extends Worker>

The actual subtype of Worker

Summary

Public methods

static @NonNull TestWorkerBuilder<Worker>
from(
    @NonNull Context context,
    @NonNull WorkRequest workRequest,
    @NonNull Executor executor
)

Creates a new instance of a TestWorkerBuilder from a WorkRequest that runs on the given Executor.

static @NonNull TestWorkerBuilder<W>
<W extends Worker> from(
    @NonNull Context context,
    @NonNull Class<W> workerClass,
    @NonNull Executor executor
)

Creates a new instance of a TestWorkerBuilder with the worker Class that runs on the given Executor.

Inherited methods

From androidx.work.testing.TestListenableWorkerBuilder
@NonNull W

Builds the ListenableWorker.

static @NonNull TestListenableWorkerBuilder<ListenableWorker>
from(@NonNull Context context, @NonNull WorkRequest workRequest)

Creates a new instance of a TestListenableWorkerBuilder from a WorkRequest.

static @NonNull TestListenableWorkerBuilder<W>
<W extends ListenableWorker> from(
    @NonNull Context context,
    @NonNull Class<W> workerClass
)

Creates a new instance of a TestListenableWorkerBuilder the worker Class.

@NonNull TestListenableWorkerBuilder<W>

Sets the ForegroundUpdater to be used to construct the androidx.work.ListenableWorker.

@NonNull TestListenableWorkerBuilder<W>

Sets the id for this unit of work.

@NonNull TestListenableWorkerBuilder<W>

Adds input Data to the work.

@NonNull TestListenableWorkerBuilder<W>
@RequiresApi(value = 28)
setNetwork(@NonNull Network network)

Sets the network associated with this unit of work.

@NonNull TestListenableWorkerBuilder<W>

Sets the ProgressUpdater to be used to construct the androidx.work.ListenableWorker.

@NonNull TestListenableWorkerBuilder<W>
setRunAttemptCount(int runAttemptCount)

Sets the initial run attempt count for this work.

@NonNull TestListenableWorkerBuilder<W>

Sets the tags associated with this unit of work.

@NonNull TestListenableWorkerBuilder<W>

Sets the authorities for content Uri's associated with this unit of work.

@NonNull TestListenableWorkerBuilder<W>
@RequiresApi(value = 24)
setTriggeredContentUris(@NonNull List<Uri> contentUris)

Sets the list of Content Uris associated with this unit of work.

@NonNull TestListenableWorkerBuilder<W>

Sets the WorkerFactory to be used to construct the androidx.work.ListenableWorker.

Public methods

from

Added in 2.1.0
public static @NonNull TestWorkerBuilder<Workerfrom(
    @NonNull Context context,
    @NonNull WorkRequest workRequest,
    @NonNull Executor executor
)

Creates a new instance of a TestWorkerBuilder from a WorkRequest that runs on the given Executor.

Parameters
@NonNull Context context

The Context

@NonNull WorkRequest workRequest

The WorkRequest

@NonNull Executor executor

The Executor

Returns
@NonNull TestWorkerBuilder<Worker>

The new instance of a TestWorkerBuilder

from

Added in 2.1.0
public static @NonNull TestWorkerBuilder<W> <W extends Worker> from(
    @NonNull Context context,
    @NonNull Class<W> workerClass,
    @NonNull Executor executor
)

Creates a new instance of a TestWorkerBuilder with the worker Class that runs on the given Executor.

Parameters
@NonNull Context context

The Context

@NonNull Class<W> workerClass

The subtype of Worker being built

@NonNull Executor executor

The Executor

Returns
@NonNull TestWorkerBuilder<W>

The new instance of a TestWorkerBuilder