### Question:
TabsJsonHelper { public static List<Tab> getTabsFromJson(@Nullable final String tabsJson) throws InvalidJsonException { if (tabsJson == null || tabsJson.isEmpty()) { return getDefaultTabs(); } final List<Tab> returnTabs = new ArrayList<>(); final JsonObject outerJsonObject; try { outerJsonObject = JsonParser.object().from(tabsJson); if (!outerJsonObject.has(JSON_TABS_ARRAY_KEY)) { throw new InvalidJsonException("JSON doesn't contain \"" + JSON_TABS_ARRAY_KEY + "\" array"); } final JsonArray tabsArray = outerJsonObject.getArray(JSON_TABS_ARRAY_KEY); for (Object o : tabsArray) { if (!(o instanceof JsonObject)) { continue; } final Tab tab = Tab.from((JsonObject) o); if (tab != null) { returnTabs.add(tab); } } } catch (JsonParserException e) { throw new InvalidJsonException(e); } if (returnTabs.isEmpty()) { return getDefaultTabs(); } return returnTabs; } 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 testInvalidIdRead() throws TabsJsonHelper.InvalidJsonException { final int blankTabId = Tab.Type.BLANK.getTabId(); final String emptyTabsJson = "{\"" + JSON_TABS_ARRAY_KEY + "\":[" + "{\"" + JSON_TAB_ID_KEY + "\":" + blankTabId + "}," + "{\"" + JSON_TAB_ID_KEY + "\":" + 12345678 + "}" + "]}"; final List<Tab> items = TabsJsonHelper.getTabsFromJson(emptyTabsJson); assertEquals("Should ignore the tab with invalid id", 1, items.size()); assertEquals(blankTabId, items.get(0).getTabId()); }
@Test public void testInvalidRead() { final List<String> invalidList = Arrays.asList( "{\"notTabsArray\":[]}", "{invalidJSON]}", "{}" ); for (String invalidContent : invalidList) { try { TabsJsonHelper.getTabsFromJson(invalidContent); fail("didn't throw exception"); } catch (Exception e) { boolean isExpectedException = e instanceof TabsJsonHelper.InvalidJsonException; assertTrue("\"" + e.getClass().getSimpleName() + "\" is not the expected exception", isExpectedException); } } }