@Test public void getAutoCompleteAsObservable_whenEmpty_default3A() throws Exception { TestObserver<List<String>> testObserver = mPreferencesHelper.getAutoCompleteAsObservable().test(); testObserver.assertValues(Collections.singletonList("3A")); }
public Observable<List<String>> getAutoCompleteAsObservable() { return mRxSharedPreferences.getString(PREF_KEY_AUTO_COMPLETE_LIST, getDefaultAutoCompleteString()).asObservable() .map(new Function<String, List<String>>() { @Override public List<String> apply(String json) throws Exception { List<String> items = new ArrayList<>(); if (!TextUtils.isEmpty(json)) { items = gson.fromJson(json, new TypeToken<List<String>>() { }.getType()); return items; } else { items.add("3A"); return items; } } }); }
PreferencesHelper { public Observable<List<String>> getAutoCompleteAsObservable() { return mRxSharedPreferences.getString(PREF_KEY_AUTO_COMPLETE_LIST, getDefaultAutoCompleteString()).asObservable() .map(new Function<String, List<String>>() { @Override public List<String> apply(String json) throws Exception { List<String> items = new ArrayList<>(); if (!TextUtils.isEmpty(json)) { items = gson.fromJson(json, new TypeToken<List<String>>() { }.getType()); return items; } else { items.add("3A"); return items; } } }); } }
PreferencesHelper { public Observable<List<String>> getAutoCompleteAsObservable() { return mRxSharedPreferences.getString(PREF_KEY_AUTO_COMPLETE_LIST, getDefaultAutoCompleteString()).asObservable() .map(new Function<String, List<String>>() { @Override public List<String> apply(String json) throws Exception { List<String> items = new ArrayList<>(); if (!TextUtils.isEmpty(json)) { items = gson.fromJson(json, new TypeToken<List<String>>() { }.getType()); return items; } else { items.add("3A"); return items; } } }); } @Inject  PreferencesHelper(Context context); }
PreferencesHelper { public Observable<List<String>> getAutoCompleteAsObservable() { return mRxSharedPreferences.getString(PREF_KEY_AUTO_COMPLETE_LIST, getDefaultAutoCompleteString()).asObservable() .map(new Function<String, List<String>>() { @Override public List<String> apply(String json) throws Exception { List<String> items = new ArrayList<>(); if (!TextUtils.isEmpty(json)) { items = gson.fromJson(json, new TypeToken<List<String>>() { }.getType()); return items; } else { items.add("3A"); return items; } } }); } @Inject  PreferencesHelper(Context context); void clear(); void saveStartFromFirst(boolean isStartFromFirst); boolean getIsStartFromFirst(); Observable<List<String>> getAutoCompleteAsObservable(); void saveAutoCompleteItem(String item); void saveLastQueryLine(String lastQueryStation); String getLastQueryLine(); boolean getShowNotification(); boolean getTrackBackground(); boolean getShowPopupNotification(); int getAutoRefreshInterval(); }
PreferencesHelper { public Observable<List<String>> getAutoCompleteAsObservable() { return mRxSharedPreferences.getString(PREF_KEY_AUTO_COMPLETE_LIST, getDefaultAutoCompleteString()).asObservable() .map(new Function<String, List<String>>() { @Override public List<String> apply(String json) throws Exception { List<String> items = new ArrayList<>(); if (!TextUtils.isEmpty(json)) { items = gson.fromJson(json, new TypeToken<List<String>>() { }.getType()); return items; } else { items.add("3A"); return items; } } }); } @Inject  PreferencesHelper(Context context); void clear(); void saveStartFromFirst(boolean isStartFromFirst); boolean getIsStartFromFirst(); Observable<List<String>> getAutoCompleteAsObservable(); void saveAutoCompleteItem(String item); void saveLastQueryLine(String lastQueryStation); String getLastQueryLine(); boolean getShowNotification(); boolean getTrackBackground(); boolean getShowPopupNotification(); int getAutoRefreshInterval(); static final String PREF_FILE_APP; }