@@ -0,0 +1,3236 @@
+package com.jagsaund.rxuploader;%0A%0Aimport com.jagsaund.rxuploader.job.Job;%0Aimport com.jagsaund.rxuploader.job.Status;%0Aimport java.util.Collections;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport rx.Observable;%0Aimport rx.schedulers.TestScheduler;%0Aimport rx.subjects.TestSubject;%0A%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class UploadManagerTest %7B%0A    private static final Job TEST_JOB = Job.builder()%0A            .setId(%22job-id%22)%0A            .setFilepath(%22filepath%22)%0A            .setMetadata(Collections.emptyMap())%0A            .setStatus(Status.createQueued(%22job-id%22))%0A            .setMimeType(%22text/plain%22)%0A            .build();%0A%0A    @Mock private UploadInteractor uploadInteractor;%0A    @Mock private UploadErrorAdapter uploadErrorAdapter;%0A%0A    private TestScheduler testScheduler;%0A    private TestSubject%3CStatus%3E statusSubject;%0A    private TestSubject%3CJob%3E jobSubject;%0A    private UploadManager uploadManager;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        testScheduler = new TestScheduler();%0A        statusSubject = TestSubject.create(testScheduler);%0A        jobSubject = TestSubject.create(testScheduler);%0A%0A        uploadManager =%0A                new UploadManager(uploadInteractor, uploadErrorAdapter, jobSubject, statusSubject);%0A    %7D%0A%0A    @Test%0A    public void testEnqueue() throws Exception %7B%0A        when(uploadInteractor.save(TEST_JOB))%0A                .thenReturn(Observable.just(TEST_JOB));%0A%0A        when(uploadInteractor.update(TEST_JOB.status()))%0A                .thenReturn(Observable.just(TEST_JOB));%0A%0A        final Status completed = Status.createCompleted(TEST_JOB.id(), %22Finished%22);%0A        when(uploadInteractor.update(completed))%0A                .thenReturn(Observable.just(TEST_JOB.withStatus(completed)));%0A%0A        final Status%5B%5D statuses = new Status%5B%5D %7B%0A                Status.createSending(TEST_JOB.id(), 0),%0A                Status.createSending(TEST_JOB.id(), 50),%0A                Status.createSending(TEST_JOB.id(), 100),%0A                completed,%0A        %7D;%0A        when(uploadInteractor.upload(TEST_JOB.id()))%0A                .thenReturn(Observable.from(statuses));%0A%0A        when(uploadInteractor.delete(TEST_JOB.id()))%0A                .thenReturn(Observable.just(TEST_JOB.withStatus(completed)));%0A%0A        // when a new job is queued to be uploaded%0A        uploadManager.enqueue(TEST_JOB);%0A        testScheduler.triggerActions();%0A%0A        // it should first be saved to the job repository%0A        verify(uploadInteractor).save(TEST_JOB);%0A        // then the job should be passed to the status queue where the job status is updated%0A        verify(uploadInteractor).update(TEST_JOB.status());%0A        // then the status is filtered for queued items which should be sent to upload%0A        verify(uploadInteractor).upload(TEST_JOB.id());%0A        // then the status should be updated once upload completes%0A        verify(uploadInteractor).update(completed);%0A        // then the job should be deleted since it completed successfully%0A        verify(uploadInteractor).delete(TEST_JOB.id());%0A    %7D%0A%7D

Add Unit Tests for UploadManager