### Question:
TabsJsonHelper { public static String getJsonToSave(@Nullable final List<Tab> tabList) { final JsonStringWriter jsonWriter = JsonWriter.string(); jsonWriter.object(); jsonWriter.array(JSON_TABS_ARRAY_KEY); if (tabList != null) { for (Tab tab : tabList) { tab.writeJsonOn(jsonWriter); } } jsonWriter.end(); jsonWriter.end(); return jsonWriter.done(); } private  TabsJsonHelper(); static List<Tab> getTabsFromJson(@Nullable final String tabsJson); static String getJsonToSave(@Nullable final List<Tab> tabList); static List<Tab> getDefaultTabs();  }### Answer:
@Test public void testEmptyAndNullSave() throws JsonParserException { final List<Tab> emptyList = Collections.emptyList(); String returnedJson = TabsJsonHelper.getJsonToSave(emptyList); assertTrue(isTabsArrayEmpty(returnedJson)); final List<Tab> nullList = null; returnedJson = TabsJsonHelper.getJsonToSave(nullList); assertTrue(isTabsArrayEmpty(returnedJson)); }
@Test public void testSaveAndReading() throws JsonParserException { final Tab.BlankTab blankTab = new Tab.BlankTab(); final Tab.DefaultKioskTab defaultKioskTab = new Tab.DefaultKioskTab(); final Tab.SubscriptionsTab subscriptionsTab = new Tab.SubscriptionsTab(); final Tab.ChannelTab channelTab = new Tab.ChannelTab( 666, "https: final Tab.KioskTab kioskTab = new Tab.KioskTab(123, "trending_key"); final List<Tab> tabs = Arrays.asList( blankTab, defaultKioskTab, subscriptionsTab, channelTab, kioskTab); final String returnedJson = TabsJsonHelper.getJsonToSave(tabs); final JsonObject jsonObject = JsonParser.object().from(returnedJson); assertTrue(jsonObject.containsKey(JSON_TABS_ARRAY_KEY)); final JsonArray tabsFromArray = jsonObject.getArray(JSON_TABS_ARRAY_KEY); assertEquals(tabs.size(), tabsFromArray.size()); final Tab.BlankTab blankTabFromReturnedJson = requireNonNull((Tab.BlankTab) Tab.from( (JsonObject) tabsFromArray.get(0))); assertEquals(blankTab.getTabId(), blankTabFromReturnedJson.getTabId()); final Tab.DefaultKioskTab defaultKioskTabFromReturnedJson = requireNonNull( (Tab.DefaultKioskTab) Tab.from((JsonObject) tabsFromArray.get(1))); assertEquals(defaultKioskTab.getTabId(), defaultKioskTabFromReturnedJson.getTabId()); final Tab.SubscriptionsTab subscriptionsTabFromReturnedJson = requireNonNull( (Tab.SubscriptionsTab) Tab.from((JsonObject) tabsFromArray.get(2))); assertEquals(subscriptionsTab.getTabId(), subscriptionsTabFromReturnedJson.getTabId()); final Tab.ChannelTab channelTabFromReturnedJson = requireNonNull((Tab.ChannelTab) Tab.from( (JsonObject) tabsFromArray.get(3))); assertEquals(channelTab.getTabId(), channelTabFromReturnedJson.getTabId()); assertEquals(channelTab.getChannelServiceId(), channelTabFromReturnedJson.getChannelServiceId()); assertEquals(channelTab.getChannelUrl(), channelTabFromReturnedJson.getChannelUrl()); assertEquals(channelTab.getChannelName(), channelTabFromReturnedJson.getChannelName()); final Tab.KioskTab kioskTabFromReturnedJson = requireNonNull((Tab.KioskTab) Tab.from( (JsonObject) tabsFromArray.get(4))); assertEquals(kioskTab.getTabId(), kioskTabFromReturnedJson.getTabId()); assertEquals(kioskTab.getKioskServiceId(), kioskTabFromReturnedJson.getKioskServiceId()); assertEquals(kioskTab.getKioskId(), kioskTabFromReturnedJson.getKioskId()); }