// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// final static List<Item> ITEMS = Lists.newArrayList();
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static Item ITEM_1 = new Item("1",
//         1453554000000L, // purchase: 24/01/2016
//         2000,
//         0,
//         1485176400000L, // expiry: 24/01/2017
//         "Clothing", "Casual", "T-shirt",
//         "Short sleeve", "V-neck", "Plain", "Black", "Dark", "Some secondary colour",
//         "Some Size", "Some Brand", "Some Shop", "Standard plain T-shirt", "Some note",
//         "file:///android_asset/black-t-shirt.jpg", false);
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static Item ITEM_2 = new Item("2",
//         -1, // purchase: unknown
//         3000,
//         -1,
//         1514206800000L, // expiry: 26/12/2017
//         "Bathroom", null,
//         "Towel", null, null, null, "White", null, null, null, null, null, null, null, null,
//         false);
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static String USER_ID = "testUID";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/item_details/ItemDetailsPresenter.java
// public final static String ITEM_DETAILS_CALLER = "item_details";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/ItemsPresenter.java
// @SuppressWarnings("WeakerAccess")
// @VisibleForTesting
// public final static String ITEMS_CALLER = "items";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/util/Constants.java
// public static final String SORT_BY_EXPIRY_STRING = "expiry";


import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEMS;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEM_1;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEM_2;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.USER_ID;
import static com.michaelvescovo.android.itemreaper.item_details.ItemDetailsPresenter.ITEM_DETAILS_CALLER;
import static com.michaelvescovo.android.itemreaper.items.ItemsPresenter.ITEMS_CALLER;
import static com.michaelvescovo.android.itemreaper.util.Constants.SORT_BY_EXPIRY_STRING;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.michaelvescovo.android.itemreaper.data;





/**
 * @author Michael Vescovo
 */

public class RepositoryTest {

    private Repository mRepository;
    @Mock
    private DataSource mRemoteDataSource;
    @Mock
    private DataSource.GetItemsCallback mGetItemsCallback;
    @Captor
    private ArgumentCaptor<DataSource.GetItemsCallback> mItemsCallbackCaptor;
    @Mock
    private DataSource.GetNewItemIdCallback mGetNewItemIdCallback;
    @Captor
    private ArgumentCaptor<DataSource.GetItemCallback> mItemCallbackCaptor;
    @Mock
    private DataSource.GetItemCallback mGetItemCallback;

    @Before
    public void setupRepository() {
        MockitoAnnotations.initMocks(this);
        mRepository = new Repository(mRemoteDataSource);
    }

    @Test
    public void getItems_CacheAfterFirstCall() {
        // First call.
        mRepository.getItems(USER_ID, SORT_BY_EXPIRY_STRING, ITEMS_CALLER, mGetItemsCallback);
        // Trigger callback.
        verify(mRemoteDataSource).getItems(anyString(), anyString(), anyString(),
                mItemsCallbackCaptor.capture());
        // Set the callback data.
        mItemsCallbackCaptor.getValue().onItemsLoaded(ITEMS);
        // Second call.
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// final static List<Item> ITEMS = Lists.newArrayList();
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static Item ITEM_1 = new Item("1",
//         1453554000000L, // purchase: 24/01/2016
//         2000,
//         0,
//         1485176400000L, // expiry: 24/01/2017
//         "Clothing", "Casual", "T-shirt",
//         "Short sleeve", "V-neck", "Plain", "Black", "Dark", "Some secondary colour",
//         "Some Size", "Some Brand", "Some Shop", "Standard plain T-shirt", "Some note",
//         "file:///android_asset/black-t-shirt.jpg", false);
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static Item ITEM_2 = new Item("2",
//         -1, // purchase: unknown
//         3000,
//         -1,
//         1514206800000L, // expiry: 26/12/2017
//         "Bathroom", null,
//         "Towel", null, null, null, "White", null, null, null, null, null, null, null, null,
//         false);
// 
// Path: app/src/mock/java/com/michaelvescovo/android/itemreaper/data/FakeDataSource.java
// public final static String USER_ID = "testUID";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/item_details/ItemDetailsPresenter.java
// public final static String ITEM_DETAILS_CALLER = "item_details";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/ItemsPresenter.java
// @SuppressWarnings("WeakerAccess")
// @VisibleForTesting
// public final static String ITEMS_CALLER = "items";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/util/Constants.java
// public static final String SORT_BY_EXPIRY_STRING = "expiry";


// Path: app/src/testMock/java/com/michaelvescovo/android/itemreaper/data/RepositoryTest.java
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEMS;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEM_1;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.ITEM_2;
import static com.michaelvescovo.android.itemreaper.data.FakeDataSource.USER_ID;
import static com.michaelvescovo.android.itemreaper.item_details.ItemDetailsPresenter.ITEM_DETAILS_CALLER;
import static com.michaelvescovo.android.itemreaper.items.ItemsPresenter.ITEMS_CALLER;
import static com.michaelvescovo.android.itemreaper.util.Constants.SORT_BY_EXPIRY_STRING;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

package com.michaelvescovo.android.itemreaper.data;





/**
 * @author Michael Vescovo
 */

public class RepositoryTest {

    private Repository mRepository;
    @Mock
    private DataSource mRemoteDataSource;
    @Mock
    private DataSource.GetItemsCallback mGetItemsCallback;
    @Captor
    private ArgumentCaptor<DataSource.GetItemsCallback> mItemsCallbackCaptor;
    @Mock
    private DataSource.GetNewItemIdCallback mGetNewItemIdCallback;
    @Captor
    private ArgumentCaptor<DataSource.GetItemCallback> mItemCallbackCaptor;
    @Mock
    private DataSource.GetItemCallback mGetItemCallback;

    @Before
    public void setupRepository() {
        MockitoAnnotations.initMocks(this);
        mRepository = new Repository(mRemoteDataSource);
    }

    @Test
    public void getItems_CacheAfterFirstCall() {
        // First call.
        mRepository.getItems(USER_ID, SORT_BY_EXPIRY_STRING, ITEMS_CALLER, mGetItemsCallback);
        // Trigger callback.
        verify(mRemoteDataSource).getItems(anyString(), anyString(), anyString(),
                mItemsCallbackCaptor.capture());
        // Set the callback data.
        mItemsCallbackCaptor.getValue().onItemsLoaded(ITEMS);
        // Second call.
        mRepository.getItems(USER_ID, SORT_BY_EXPIRY_STRING, ITEMS_CALLER, mGetItemsCallback);