|
| 1 | +package com.lasthopesoftware.bluewater.client.stored.library.items.files.job.GivenAFileThatDoesNotYetExist.AndTheFileCanBeDownloaded.AndNoBytesAreDownloaded |
| 2 | + |
| 3 | +import com.lasthopesoftware.bluewater.client.browsing.files.ServiceFile |
| 4 | +import com.lasthopesoftware.bluewater.client.browsing.library.repository.LibraryId |
| 5 | +import com.lasthopesoftware.bluewater.client.stored.library.items.files.job.StoredFileJob |
| 6 | +import com.lasthopesoftware.bluewater.client.stored.library.items.files.job.StoredFileJobProcessor |
| 7 | +import com.lasthopesoftware.bluewater.client.stored.library.items.files.job.StoredFileJobState |
| 8 | +import com.lasthopesoftware.bluewater.client.stored.library.items.files.repository.StoredFile |
| 9 | +import com.lasthopesoftware.promises.extensions.toPromise |
| 10 | +import com.lasthopesoftware.resources.emptyByteArray |
| 11 | +import com.namehillsoftware.handoff.promises.Promise |
| 12 | +import io.mockk.every |
| 13 | +import io.mockk.mockk |
| 14 | +import org.assertj.core.api.Assertions.assertThat |
| 15 | +import org.junit.jupiter.api.BeforeAll |
| 16 | +import org.junit.jupiter.api.Test |
| 17 | +import java.io.ByteArrayInputStream |
| 18 | +import java.io.OutputStream |
| 19 | +import java.net.URI |
| 20 | + |
| 21 | +class WhenProcessingTheJob { |
| 22 | + |
| 23 | + private val storedFile = StoredFile(LibraryId(5), ServiceFile("1"), URI("test-path"), true) |
| 24 | + private val states = ArrayList<StoredFileJobState>() |
| 25 | + |
| 26 | + @BeforeAll |
| 27 | + fun before() { |
| 28 | + val storedFileJobProcessor = StoredFileJobProcessor( |
| 29 | + mockk { |
| 30 | + every { promiseOutputStream(any()) } returns Promise(OutputStream.nullOutputStream()) |
| 31 | + }, |
| 32 | + mockk { |
| 33 | + every { promiseDownload(any(), any()) } returns Promise( |
| 34 | + ByteArrayInputStream(emptyByteArray) |
| 35 | + ) |
| 36 | + }, |
| 37 | + mockk { |
| 38 | + every { markStoredFileAsDownloaded(storedFile) } returns storedFile.toPromise() |
| 39 | + }, |
| 40 | + ) |
| 41 | + storedFileJobProcessor.observeStoredFileDownload( |
| 42 | + setOf( |
| 43 | + StoredFileJob( |
| 44 | + LibraryId(5), |
| 45 | + ServiceFile("1"), |
| 46 | + storedFile |
| 47 | + ) |
| 48 | + ) |
| 49 | + ) |
| 50 | + .map { f -> f.storedFileJobState } |
| 51 | + .blockingSubscribe( |
| 52 | + { storedFileJobState -> states.add(storedFileJobState) }, |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun thenTheStoredFileIsPutBackIntoQueuedState() { |
| 58 | + assertThat(states).containsExactly( |
| 59 | + StoredFileJobState.Queued, |
| 60 | + StoredFileJobState.Downloading, |
| 61 | + StoredFileJobState.Queued |
| 62 | + ) |
| 63 | + } |
| 64 | +} |
0 commit comments