# FakeDownloader

Artifact: [androidx.media3:media3-test-utils-robolectric](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/robolectric/FakeDownloader.java+class:androidx.media3.test.utils.robolectric.FakeDownloader)

*** ** * ** ***


```
@UnstableApi
public class FakeDownloader implements Downloader
```

<br />

*** ** * ** ***

A fake `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#FakeDownloader(androidx.media3.exoplayer.offline.DownloadRequest)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request)` Creates a `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader`. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#assertCanceled(boolean)(boolean canceled)` Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` has been canceled or not canceled. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#assertDownloadStarted()()` Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` has started. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#assertId(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Asserts that the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader` instance was created with the given `id`. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#assertRemoveStarted(boolean)(boolean started)` Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` has started or not started. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#assertStreamKeys(androidx.media3.common.StreamKey...)(StreamKey[] streamKeys)` Asserts that the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader` instance was created with the given `streamKeys`. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#cancel()()` Permanently cancels the downloading by this downloader. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader.ProgressListener progressListener)` Downloads the content. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#fail()()` Fails `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` with an error. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#finish()()` Finishes the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` without an error. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#incrementBytesDownloaded()()` Increments the number of bytes that the fake downloader has downloaded. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()()` Removes the content. |

## Public constructors

### FakeDownloader

```
public FakeDownloader(DownloadRequest request)
```

Creates a `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request` | The `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest`. |

## Public methods

### assertCanceled

```
public void assertCanceled(boolean canceled)
```

Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` has been canceled or not canceled.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |

### assertDownloadStarted

```
public void assertDownloadStarted()
```

Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` has started.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |

### assertId

```
public void assertId(String id)
```

Asserts that the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader` instance was created with the given `id`.

### assertRemoveStarted

```
public void assertRemoveStarted(boolean started)
```

Asserts that `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` has started or not started.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |

### assertStreamKeys

```
public void assertStreamKeys(StreamKey[] streamKeys)
```

Asserts that the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader` instance was created with the given `streamKeys`.

### cancel

```
public void cancel()
```

Permanently cancels the downloading by this downloader. The caller should also interrupt the downloading thread immediately after calling this method.

Once canceled, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` cannot be called again.

### download

```
public void download(@Nullable Downloader.ProgressListener progressListener)
```

Downloads the content.

If downloading fails, this method can be called again to resume the download. It cannot be called again after the download has been `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader#cancel()`.

If downloading is canceled whilst this method is executing, then it is expected that it will return reasonably quickly. However, there are no guarantees about how the method will return, meaning that it can return without throwing, or by throwing any of its documented exceptions. The caller must use its own knowledge about whether downloading has been canceled to determine whether this is why the method has returned, rather than relying on the method returning in a particular way.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader.ProgressListener progressListener` | A listener to receive progress updates, or `null`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If the download failed to complete successfully. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` | If the download was interrupted. |
| `https://developer.android.com/reference/java/util/concurrent/CancellationException.html` | If the download was canceled. |

### fail

```
public void fail()
```

Fails `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` with an error.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |

### finish

```
public void finish()
```

Finishes the `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)` or `https://developer.android.com/reference/androidx/media3/test/utils/robolectric/FakeDownloader#remove()` without an error.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |

### incrementBytesDownloaded

```
public void incrementBytesDownloaded()
```

Increments the number of bytes that the fake downloader has downloaded.

### remove

```
public void remove()
```

Removes the content.