class SharedPreferencesHelper {

    public boolean saveSortBy(int sortBy) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putInt(STATE_CURRENT_SORT, sortBy);
        return editor.commit();
    }

}

class SharedPreferencesHelperTest {

    private SharedPreferencesHelper mMockSharedPreferencesHelper;
    private SharedPreferencesHelper mMockBrokenSharedPreferencesHelper;
    @Mock SharedPreferences mMockSharedPreferences;
    @Mock SharedPreferences mMockBrokenSharedPreferences;
    @Mock SharedPreferences.Editor mMockEditor;
    @Mock SharedPreferences.Editor mMockBrokenEditor;

    @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));
    }

}