@Test public void putStripeJsonModelListIfNotNull_forMapsWhenNull_doesNothing() { Map<String, Object> sampleMap = new HashMap<>(); StripeJsonModel.putStripeJsonModelListIfNotNull(sampleMap, "mapkey", null); assertTrue(sampleMap.isEmpty()); }
static void putStripeJsonModelListIfNotNull( @NonNull Map<String, Object> upperLevelMap, @NonNull @Size(min = 1) String key, @Nullable List<? extends StripeJsonModel> jsonModelList) { if (jsonModelList == null) { return; } List<Map<String, Object>> mapList = new ArrayList<>(); for (int i = 0; i < jsonModelList.size(); i++) { mapList.add(jsonModelList.get(i).toMap()); } upperLevelMap.put(key, mapList); }
StripeJsonModel { static void putStripeJsonModelListIfNotNull( @NonNull Map<String, Object> upperLevelMap, @NonNull @Size(min = 1) String key, @Nullable List<? extends StripeJsonModel> jsonModelList) { if (jsonModelList == null) { return; } List<Map<String, Object>> mapList = new ArrayList<>(); for (int i = 0; i < jsonModelList.size(); i++) { mapList.add(jsonModelList.get(i).toMap()); } upperLevelMap.put(key, mapList); } }
StripeJsonModel { static void putStripeJsonModelListIfNotNull( @NonNull Map<String, Object> upperLevelMap, @NonNull @Size(min = 1) String key, @Nullable List<? extends StripeJsonModel> jsonModelList) { if (jsonModelList == null) { return; } List<Map<String, Object>> mapList = new ArrayList<>(); for (int i = 0; i < jsonModelList.size(); i++) { mapList.add(jsonModelList.get(i).toMap()); } upperLevelMap.put(key, mapList); }  }
StripeJsonModel { static void putStripeJsonModelListIfNotNull( @NonNull Map<String, Object> upperLevelMap, @NonNull @Size(min = 1) String key, @Nullable List<? extends StripeJsonModel> jsonModelList) { if (jsonModelList == null) { return; } List<Map<String, Object>> mapList = new ArrayList<>(); for (int i = 0; i < jsonModelList.size(); i++) { mapList.add(jsonModelList.get(i).toMap()); } upperLevelMap.put(key, mapList); }  @NonNull abstract Map<String, Object> toMap(); @NonNull abstract JSONObject toJson(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); }
StripeJsonModel { static void putStripeJsonModelListIfNotNull( @NonNull Map<String, Object> upperLevelMap, @NonNull @Size(min = 1) String key, @Nullable List<? extends StripeJsonModel> jsonModelList) { if (jsonModelList == null) { return; } List<Map<String, Object>> mapList = new ArrayList<>(); for (int i = 0; i < jsonModelList.size(); i++) { mapList.add(jsonModelList.get(i).toMap()); } upperLevelMap.put(key, mapList); }  @NonNull abstract Map<String, Object> toMap(); @NonNull abstract JSONObject toJson(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }