BulkUpdateUtil { @SuppressWarnings("unchecked") public static JSONObject mergeMetadataFields(final JSONObject first, final JSONObject second) { if (first == null) { return second; } if (second == null) { return first; } final JSONObject result = deepCopy(first); final Collection fields = (Collection) result.get("fields"); fields.addAll((Collection) second.get("fields")); return result; } private  BulkUpdateUtil(); static Optional<Event> getEvent(
    final IndexService indexSvc,
    final AdminUISearchIndex index,
    final String id); @SuppressWarnings("unchecked") static JSONObject addSchedulingDates(final Event event, final JSONObject scheduling); @SuppressWarnings("unchecked") static JSONObject toNonTechnicalMetadataJson(final JSONObject scheduling); @SuppressWarnings("unchecked") static JSONObject mergeMetadataFields(final JSONObject first, final JSONObject second);  }
@Test public void testMergeMetadataFields() { final JSONObject metadata1 = loadJsonObject("merge1.json"); final JSONObject metadata2 = loadJsonObject("merge2.json"); final JSONObject expected = loadJsonObject("metadata-expected.json"); final JSONObject actual = BulkUpdateUtil.mergeMetadataFields(metadata1, metadata2); assertThat(actual.toJSONString(), SameJSONAs.sameJSONAs(expected.toJSONString())); }
@Test public void testMergeMetadataFieldsFirstNull() { final JSONObject metadata1 = null; final JSONObject metadata2 = loadJsonObject("merge2.json"); final JSONObject expected = loadJsonObject("merge2.json"); final JSONObject actual = BulkUpdateUtil.mergeMetadataFields(metadata1, metadata2); assertThat(actual.toJSONString(), SameJSONAs.sameJSONAs(expected.toJSONString())); }
@Test public void testMergeMetadataFieldsSecondNull() { final JSONObject metadata1 = loadJsonObject("merge1.json"); final JSONObject metadata2 = null; final JSONObject expected = loadJsonObject("merge1.json"); final JSONObject actual = BulkUpdateUtil.mergeMetadataFields(metadata1, metadata2); assertThat(actual.toJSONString(), SameJSONAs.sameJSONAs(expected.toJSONString())); }