// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/ItemsFragment.java
// public static String STATE_CURRENT_SORT = "current_sort";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/SortItemsDialogFragment.java
// public static final int SORT_BY_EXPIRY = 0;


import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import android.content.SharedPreferences;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static com.michaelvescovo.android.itemreaper.items.ItemsFragment.STATE_CURRENT_SORT;
import static com.michaelvescovo.android.itemreaper.items.SortItemsDialogFragment.SORT_BY_EXPIRY;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
    @Mock
    SharedPreferences.Editor mMockEditor;

    @Mock
    SharedPreferences.Editor mMockBrokenEditor;

    @Before
    public void initMocks() {
        mMockSharedPreferencesHelper = createMockSharedPreference();
        mMockBrokenSharedPreferencesHelper = createBrokenMockSharedPreference();
    }

    @Test
    public void saveAndReadSortBy() {
        boolean success = mMockSharedPreferencesHelper.saveSortBy(SORT_BY_EXPIRY);
        assertThat("Checking that SharedPreferenceEntry.save... returns true", success, is(true));

        int sortBy = mMockSharedPreferencesHelper.getSortBy();
        assertThat("Checking that SharedPreferenceEntry.name has been persisted and read correctly",
                SORT_BY_EXPIRY, is(equalTo(sortBy)));
    }

    @Test
    public void saveSortByFailed_ReturnsFalse() {
        boolean success = mMockBrokenSharedPreferencesHelper.saveSortBy(SORT_BY_EXPIRY);
        assertThat("Makes sure writing to a broken SharedPreferencesHelper returns false", success,
                is(false));
    }

    private SharedPreferencesHelper createMockSharedPreference() {
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/ItemsFragment.java
// public static String STATE_CURRENT_SORT = "current_sort";
// 
// Path: app/src/main/java/com/michaelvescovo/android/itemreaper/items/SortItemsDialogFragment.java
// public static final int SORT_BY_EXPIRY = 0;


// Path: app/src/test/java/com/michaelvescovo/android/itemreaper/SharedPreferencesHelperTest.java
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import android.content.SharedPreferences;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static com.michaelvescovo.android.itemreaper.items.ItemsFragment.STATE_CURRENT_SORT;
import static com.michaelvescovo.android.itemreaper.items.SortItemsDialogFragment.SORT_BY_EXPIRY;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;

    @Mock
    SharedPreferences.Editor mMockEditor;

    @Mock
    SharedPreferences.Editor mMockBrokenEditor;

    @Before
    public void initMocks() {
        mMockSharedPreferencesHelper = createMockSharedPreference();
        mMockBrokenSharedPreferencesHelper = createBrokenMockSharedPreference();
    }

    @Test
    public void saveAndReadSortBy() {
        boolean success = mMockSharedPreferencesHelper.saveSortBy(SORT_BY_EXPIRY);
        assertThat("Checking that SharedPreferenceEntry.save... returns true", success, is(true));

        int sortBy = mMockSharedPreferencesHelper.getSortBy();
        assertThat("Checking that SharedPreferenceEntry.name has been persisted and read correctly",
                SORT_BY_EXPIRY, is(equalTo(sortBy)));
    }

    @Test
    public void saveSortByFailed_ReturnsFalse() {
        boolean success = mMockBrokenSharedPreferencesHelper.saveSortBy(SORT_BY_EXPIRY);
        assertThat("Makes sure writing to a broken SharedPreferencesHelper returns false", success,
                is(false));
    }

    private SharedPreferencesHelper createMockSharedPreference() {
        when(mMockSharedPreferences.getInt(eq(STATE_CURRENT_SORT), anyInt()))