File tree Expand file tree Collapse file tree
main/java/org/schabi/newpipe/settings/tabs
test/java/org/schabi/newpipe/settings/tabs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .schabi .newpipe .settings .tabs ;
22
3+ import androidx .annotation .NonNull ;
34import androidx .annotation .Nullable ;
45
56import com .grack .nanojson .JsonArray ;
@@ -39,9 +40,9 @@ private TabsJsonHelper() { }
3940 * @return a list of {@link Tab tabs}.
4041 * @throws InvalidJsonException if the JSON string is not valid
4142 */
42- public static List <Tab > getTabsFromJson (@ Nullable final String tabsJson )
43+ public static List <Tab > getTabsFromJson (@ NonNull final String tabsJson )
4344 throws InvalidJsonException {
44- if (tabsJson == null || tabsJson .isEmpty ()) {
45+ if (tabsJson .isEmpty ()) {
4546 return getDefaultTabs ();
4647 }
4748
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public static TabsManager getManager(final Context context) {
2828 }
2929
3030 public List <Tab > getTabs () {
31- final String savedJson = sharedPreferences .getString (savedTabsKey , null );
31+ final String savedJson = sharedPreferences .getString (savedTabsKey , "" );
3232 try {
3333 return TabsJsonHelper .getTabsFromJson (savedJson );
3434 } catch (final TabsJsonHelper .InvalidJsonException e ) {
Original file line number Diff line number Diff line change @@ -21,15 +21,11 @@ public class TabsJsonHelperTest {
2121 private static final String JSON_TAB_ID_KEY = "tab_id" ;
2222
2323 @ Test
24- public void testEmptyAndNullRead () throws TabsJsonHelper .InvalidJsonException {
24+ public void testEmptyRead () throws TabsJsonHelper .InvalidJsonException {
2525 final List <Tab > defaultTabs = TabsJsonHelper .getDefaultTabs ();
2626
2727 final String emptyTabsJson = "{\" " + JSON_TABS_ARRAY_KEY + "\" :[]}" ;
28- List <Tab > items = TabsJsonHelper .getTabsFromJson (emptyTabsJson );
29- assertEquals (items , defaultTabs );
30-
31- final String nullSource = null ;
32- items = TabsJsonHelper .getTabsFromJson (nullSource );
28+ final List <Tab > items = TabsJsonHelper .getTabsFromJson (emptyTabsJson );
3329 assertEquals (items , defaultTabs );
3430 }
3531
You can’t perform that action at this time.
0 commit comments