@Test public void testWhatsNewJsonParsing() throws IOException, ParseException { final Context context = RuntimeEnvironment.application; final String whatsNewJson = FileUtil.loadTextFileFromResources(context, R.raw.whats_new); final Type type = new TypeToken<List<WhatsNewModel>>() { }.getType(); final List<WhatsNewModel> whatsNewModels = new Gson().fromJson(whatsNewJson, type); assertThat(whatsNewModels).isNotEmpty(); List<WhatsNewItemModel> whatsNewItems; for (WhatsNewModel whatsNewModel : whatsNewModels) { assertThat(new Version(whatsNewModel.getVersion())).isNotNull(); whatsNewItems = whatsNewModel.getWhatsNewItems(); assertThat(whatsNewItems).isNotEmpty(); validateWhatsNewItems(whatsNewItems); whatsNewItems = WhatsNewUtil.getWhatsNewItems(whatsNewModel.getVersion(), whatsNewModels); assertThat(whatsNewItems).isNotEmpty(); } whatsNewItems = WhatsNewUtil.getWhatsNewItems("0.0.00", whatsNewModels); assertThat(whatsNewItems).isNull(); }
@Nullable public static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion, @NonNull List<WhatsNewModel> whatsNewModelsList) { final Version version; Version whatsNewVersion; try { version = new Version(buildVersion); } catch (ParseException e) { logger.error(e, true); return null; } for (WhatsNewModel whatsNewModel : whatsNewModelsList) { try { whatsNewVersion = new Version(whatsNewModel.getVersion()); } catch (ParseException e) { logger.error(e, true); continue; } if (version.hasSameMajorMinorVersion(whatsNewVersion)) { return filterAndroidItems(whatsNewModel.getWhatsNewItems()); } } return null; }
WhatsNewUtil { @Nullable public static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion, @NonNull List<WhatsNewModel> whatsNewModelsList) { final Version version; Version whatsNewVersion; try { version = new Version(buildVersion); } catch (ParseException e) { logger.error(e, true); return null; } for (WhatsNewModel whatsNewModel : whatsNewModelsList) { try { whatsNewVersion = new Version(whatsNewModel.getVersion()); } catch (ParseException e) { logger.error(e, true); continue; } if (version.hasSameMajorMinorVersion(whatsNewVersion)) { return filterAndroidItems(whatsNewModel.getWhatsNewItems()); } } return null; } }
WhatsNewUtil { @Nullable public static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion, @NonNull List<WhatsNewModel> whatsNewModelsList) { final Version version; Version whatsNewVersion; try { version = new Version(buildVersion); } catch (ParseException e) { logger.error(e, true); return null; } for (WhatsNewModel whatsNewModel : whatsNewModelsList) { try { whatsNewVersion = new Version(whatsNewModel.getVersion()); } catch (ParseException e) { logger.error(e, true); continue; } if (version.hasSameMajorMinorVersion(whatsNewVersion)) { return filterAndroidItems(whatsNewModel.getWhatsNewItems()); } } return null; }  }
WhatsNewUtil { @Nullable public static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion, @NonNull List<WhatsNewModel> whatsNewModelsList) { final Version version; Version whatsNewVersion; try { version = new Version(buildVersion); } catch (ParseException e) { logger.error(e, true); return null; } for (WhatsNewModel whatsNewModel : whatsNewModelsList) { try { whatsNewVersion = new Version(whatsNewModel.getVersion()); } catch (ParseException e) { logger.error(e, true); continue; } if (version.hasSameMajorMinorVersion(whatsNewVersion)) { return filterAndroidItems(whatsNewModel.getWhatsNewItems()); } } return null; }  @Nullable static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion,
                                                           @NonNull List<WhatsNewModel> whatsNewModelsList); @Nullable static List<WhatsNewItemModel> filterAndroidItems(@NonNull List<WhatsNewItemModel> whatsNewItems); }
WhatsNewUtil { @Nullable public static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion, @NonNull List<WhatsNewModel> whatsNewModelsList) { final Version version; Version whatsNewVersion; try { version = new Version(buildVersion); } catch (ParseException e) { logger.error(e, true); return null; } for (WhatsNewModel whatsNewModel : whatsNewModelsList) { try { whatsNewVersion = new Version(whatsNewModel.getVersion()); } catch (ParseException e) { logger.error(e, true); continue; } if (version.hasSameMajorMinorVersion(whatsNewVersion)) { return filterAndroidItems(whatsNewModel.getWhatsNewItems()); } } return null; }  @Nullable static List<WhatsNewItemModel> getWhatsNewItems(@NonNull String buildVersion,
                                                           @NonNull List<WhatsNewModel> whatsNewModelsList); @Nullable static List<WhatsNewItemModel> filterAndroidItems(@NonNull List<WhatsNewItemModel> whatsNewItems);  }