package com.ushahidi.android.data.repository;

import com.ushahidi.android.BaseTestCase;
import com.ushahidi.android.data.entity.DeploymentEntity;
import com.ushahidi.android.data.entity.mapper.DeploymentEntityDataMapper;
import com.ushahidi.android.data.repository.datasource.deployment.DeploymentDataSource;
import com.ushahidi.android.data.repository.datasource.deployment.DeploymentDataSourceFactory;
import com.ushahidi.android.domain.entity.Deployment;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import rx.Observable;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;

/**
 * Test suite for {@link DeploymentDataRepository}
 *
 * @author Ushahidi Team <team@ushahidi.com>
 */
public class DeploymentDataRepositoryTest extends BaseTestCase {

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    private DeploymentDataRepository mDeploymentDataRepository;

    @Mock
    private DeploymentDataSourceFactory mMockDeploymentDataSourceFactory;

    @Mock
    private DeploymentEntityDataMapper mMockDeploymentEntityMapper;

    @Mock
    private DeploymentDataSource mMockDataSource;

    @Mock
    private Deployment mMockDeployment;

    @Mock
    private DeploymentEntity mMockDeploymentEntity;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        clearSingleton(DeploymentDataRepository.class);
        mDeploymentDataRepository = new DeploymentDataRepository(mMockDeploymentDataSourceFactory,
                mMockDeploymentEntityMapper);
        given(mMockDeploymentDataSourceFactory.createDatabaseDataSource())
                .willReturn(mMockDataSource);
    }

    @Test
    public void shouldSuccessfullyAddADeployment() {
        given(mMockDataSource.addDeploymentEntity(mMockDeploymentEntity)).willReturn(
                Observable.just(1l));
        given(mMockDeploymentEntityMapper.map(mMockDeployment)).willReturn(mMockDeploymentEntity);
        mDeploymentDataRepository.addEntity(mMockDeployment);

        verify(mMockDeploymentDataSourceFactory).createDatabaseDataSource();
        verify(mMockDataSource).addDeploymentEntity(mMockDeploymentEntity);
    }

    @Test
    public void shouldSuccessfullyUpdateADeployment() {
        given(mMockDataSource.updateDeploymentEntity(mMockDeploymentEntity)).willReturn(
                Observable.just(1l));
        given(mMockDeploymentEntityMapper.map(mMockDeployment)).willReturn(mMockDeploymentEntity);
        mDeploymentDataRepository.updateEntity(mMockDeployment);

        verify(mMockDeploymentDataSourceFactory).createDatabaseDataSource();
        verify(mMockDataSource).updateDeploymentEntity(mMockDeploymentEntity);
    }

    @Test
    public void shouldSuccessfullyDeleteADeployment() {
        given(mMockDataSource.deleteDeploymentEntity(1l)).willReturn(
                Observable.just(1l));
        mDeploymentDataRepository.deleteEntity(1l);

        verify(mMockDeploymentDataSourceFactory).createDatabaseDataSource();
        verify(mMockDataSource).deleteDeploymentEntity(1l);
    }
}

@@ -3231,11 +3231,488 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void shouldSuccessfullyGetADeployment() %7B%0A        given(mMockDataSource.getDeploymentEntity(1l)).willReturn(%0A                Observable.just(mMockDeploymentEntity));%0A        given(mMockDeploymentEntityMapper.map(mMockDeployment)).willReturn(mMockDeploymentEntity);%0A        mDeploymentDataRepository.getEntity(1l);%0A%0A        verify(mMockDeploymentDataSourceFactory).createDatabaseDataSource();%0A        verify(mMockDataSource).getDeploymentEntity(1l);%0A    %7D
 %0A%7D%0A

Implement test for deployment repo get a deployment