Stay organized with collections
Save and categorize content based on your preferences.
added in
version 1.1.0
belongs to Maven artifact android.arch.core:core-testing:1.1.1
CountingTaskExecutorRule
public
class
CountingTaskExecutorRule
extends TestWatcher
java.lang.Object
|
↳ |
org.junit.rules.TestWatcher
|
|
↳ |
android.arch.core.executor.testing.CountingTaskExecutorRule
|
A JUnit Test Rule that swaps the background executor used by the Architecture Components with a
different one which counts the tasks as they are start and finish.
You can use this rule for your host side tests that use Architecture Components.
Summary
Public methods |
void
|
drainTasks(int time, TimeUnit timeUnit)
Waits until all active tasks are finished.
|
boolean
|
isIdle()
Returns false if there are tasks waiting to be executed, true otherwise.
|
Protected methods |
void
|
finished(Description description)
|
void
|
onIdle()
Called when the number of awaiting tasks reaches to 0.
|
void
|
starting(Description description)
|
Inherited methods |
From class
org.junit.rules.TestWatcher
Statement
|
apply(Statement arg0, Description arg1)
|
void
|
failed(Throwable arg0, Description arg1)
|
void
|
finished(Description arg0)
|
void
|
skipped(AssumptionViolatedException arg0, Description arg1)
|
void
|
skipped(AssumptionViolatedException arg0, Description arg1)
|
void
|
starting(Description arg0)
|
void
|
succeeded(Description arg0)
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
From interface
org.junit.rules.TestRule
abstract
Statement
|
apply(Statement arg0, Description arg1)
|
|
Public constructors
CountingTaskExecutorRule
CountingTaskExecutorRule ()
Public methods
drainTasks
void drainTasks (int time,
TimeUnit timeUnit)
Waits until all active tasks are finished.
Parameters |
time |
int : The duration to wait |
timeUnit |
TimeUnit : The time unit for the time parameter |
Throws |
InterruptedException |
If thread is interrupted while waiting |
TimeoutException |
If tasks cannot be drained at the given time
|
isIdle
boolean isIdle ()
Returns false if there are tasks waiting to be executed, true otherwise.
Returns |
boolean |
False if there are tasks waiting to be executed, true otherwise. |
Protected methods
finished
void finished (Description description)
Parameters |
description |
Description |
onIdle
void onIdle ()
Called when the number of awaiting tasks reaches to 0.
starting
void starting (Description description)
Parameters |
description |
Description |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# CountingTaskExecutorRule\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \nbelongs to Maven artifact android.arch.core:core-testing:1.1.1 \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Protected Methods](#promethods) \\| [Inherited Methods](#inhmethods) \n\nCountingTaskExecutorRule\n========================\n\n| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\\*](/jetpack/androidx/migrate) packages. See [androidx.arch.core.executor.testing.CountingTaskExecutorRule](/reference/androidx/arch/core/executor/testing/CountingTaskExecutorRule) instead.\n\n\n`\npublic\n\n\nclass\nCountingTaskExecutorRule\n`\n\n\n`\n\n\n`\n\n`\n\nextends TestWatcher\n\n\n`\n\n`\n\n\n`\n\n|---|---|-------------------------------------------------------------|\n| java.lang.Object |||\n| ↳ | org.junit.rules.TestWatcher ||\n| | ↳ | android.arch.core.executor.testing.CountingTaskExecutorRule |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA JUnit Test Rule that swaps the background executor used by the Architecture Components with a\ndifferent one which counts the tasks as they are start and finish.\n\n\nYou can use this rule for your host side tests that use Architecture Components.\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[CountingTaskExecutorRule](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#CountingTaskExecutorRule())`() ` |\n\n| ### Public methods ||\n|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[drainTasks](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#drainTasks(int, java.util.concurrent.TimeUnit))`(int time, TimeUnit timeUnit) ` Waits until all active tasks are finished. |\n| ` boolean` | ` `[isIdle](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#isIdle())`() ` Returns false if there are tasks waiting to be executed, true otherwise. |\n\n| ### Protected methods ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[finished](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#finished(org.junit.runner.Description))`(Description description) ` |\n| ` void` | ` `[onIdle](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#onIdle())`() ` Called when the number of awaiting tasks reaches to 0. |\n| ` void` | ` `[starting](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#starting(org.junit.runner.Description))`(Description description) ` |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` org.junit.rules.TestWatcher ` |--------------|-----------------------------------------------------------------| | ` Statement` | ` apply(Statement arg0, Description arg1) ` | | ` void` | ` failed(Throwable arg0, Description arg1) ` | | ` void` | ` finished(Description arg0) ` | | ` void` | ` skipped(AssumptionViolatedException arg0, Description arg1) ` | | ` void` | ` skipped(AssumptionViolatedException arg0, Description arg1) ` | | ` void` | ` starting(Description arg0) ` | | ` void` | ` succeeded(Description arg0) ` | ||\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n| From interface ` org.junit.rules.TestRule ` |-----------------------|---------------------------------------------| | ` abstract Statement` | ` apply(Statement arg0, Description arg1) ` | ||\n\nPublic constructors\n-------------------\n\n### CountingTaskExecutorRule\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nCountingTaskExecutorRule ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### drainTasks\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nvoid drainTasks (int time, \n TimeUnit timeUnit)\n```\n\nWaits until all active tasks are finished.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------------------------------------------------|\n| `time` | `int`: The duration to wait \u003cbr /\u003e |\n| `timeUnit` | `TimeUnit`: The time unit for the `time` parameter \u003cbr /\u003e |\n\n| Throws ||\n|------------------------|----------------------------------------------|\n| `InterruptedException` | If thread is interrupted while waiting |\n| `TimeoutException` | If tasks cannot be drained at the given time |\n\n### isIdle\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nboolean isIdle ()\n```\n\nReturns false if there are tasks waiting to be executed, true otherwise.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|-------------------------------------------------------------------------|\n| `boolean` | False if there are tasks waiting to be executed, true otherwise. \u003cbr /\u003e |\n\n**See also:**\n\n- [onIdle()](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#onIdle())\n\nProtected methods\n-----------------\n\n### finished\n\n```\nvoid finished (Description description)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------|\n| `description` | `Description` \u003cbr /\u003e |\n\n### onIdle\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nvoid onIdle ()\n```\n\nCalled when the number of awaiting tasks reaches to 0.\n\n\u003cbr /\u003e\n\n**See also:**\n\n- [isIdle()](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule#isIdle()) \n\n### starting\n\n```\nvoid starting (Description description)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------|\n| `description` | `Description` \u003cbr /\u003e |\n\n-\n\n Classes\n -------\n\n - [CountingTaskExecutorRule](/reference/android/arch/core/executor/testing/CountingTaskExecutorRule)\n - [InstantTaskExecutorRule](/reference/android/arch/core/executor/testing/InstantTaskExecutorRule)"]]