### Question:
RequestIdentifier { public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } }  static boolean isConfigRequest(@NonNull Request esRequest); static boolean isConfigUpdateRequest(@NonNull Request esRequest); static boolean isMutationRequest(@NonNull Request esRequest); static boolean isIndexRequest(@NonNull Request esRequest); static boolean isBulkRequest(@NonNull Request esRequest); static String getIndexName(@NonNull Request esRequest); static Optional<String> getBulkIndexName(@NonNull String payloadLine);  }### Answer:
@Test public void succeedGetBulkIndexNameWithIndexBulkPattern() { Optional<String> result = RequestIdentifier.getBulkIndexName(TestConstants.BULK_INDEX_PAYLOAD); assertTrue(result.isPresent()); assertEquals(TestConstants.INDEX_NAME, result.get()); }
@Test public void succeedGetBulkIndexNameWithCreateBulkPattern() { Optional<String> result = RequestIdentifier.getBulkIndexName(TestConstants.BULK_CREATE_PAYLOAD); assertTrue(result.isPresent()); assertEquals(TestConstants.INDEX_NAME, result.get()); }
@Test public void failedGetBulkIndexNameWithWrongPattern() { Optional<String> result = RequestIdentifier.getBulkIndexName(TestConstants.WRONG_BULK_INDEX_PAYLOAD); assertFalse(result.isPresent()); }
@Test public void failedGetBulkIndexNameWithNoIndexKey() { Optional<String> result = RequestIdentifier.getBulkIndexName(TestConstants.BULK_PAYLOAD_NO_INDEX_KEY); assertFalse(result.isPresent()); }