### Question:
EntityService { public JsonNode deleteFields(String originalJsonObject, String attrId, String datasetId, String deleteAll) throws Exception, ResponseException { logger.trace("deleteFields() :: started"); JsonNode node = objectMapper.readTree(originalJsonObject); ObjectNode objectNode = (ObjectNode) node; JsonNode innerNode = ((ArrayNode) objectNode.get(attrId)); ArrayNode myArray = (ArrayNode) innerNode; String availableDatasetId = null; if (objectNode.has(attrId)) { if (datasetId != null && !datasetId.isEmpty()) { for (int i = 0; i < myArray.size(); i++) { if (myArray.get(i).has(NGSIConstants.NGSI_LD_DATA_SET_ID)) { String payloadDatasetId = myArray.get(i).get(NGSIConstants.NGSI_LD_DATA_SET_ID).get(0) .get(NGSIConstants.JSON_LD_ID).asText(); if (payloadDatasetId.equals(datasetId)) { availableDatasetId = "available"; myArray.remove(i); } } } if ((availableDatasetId == null) || (availableDatasetId.isEmpty())) { throw new ResponseException(ErrorType.NotFound, "Provided datasetId is not present"); } } else if (deleteAll != null && !deleteAll.isEmpty()) { if (deleteAll.equals("true")) { if (objectNode.has(attrId)) { objectNode.remove(attrId); } else { throw new ResponseException(ErrorType.NotFound); } } else { throw new ResponseException(ErrorType.InvalidRequest, "request is not valid"); } } else { for (int i = 0; i < myArray.size(); i++) { if (myArray.get(i).has(NGSIConstants.NGSI_LD_DATA_SET_ID)) { String payloadDatasetId = myArray.get(i).get(NGSIConstants.NGSI_LD_DATA_SET_ID).get(0) .get(NGSIConstants.JSON_LD_ID).asText(); if (payloadDatasetId.equals(NGSIConstants.DEFAULT_DATA_SET_ID)) { availableDatasetId = "available"; myArray.remove(i); } } else { availableDatasetId = "NotAvailable"; myArray.remove(i); } } if ((availableDatasetId == null) || (availableDatasetId.isEmpty())) { throw new ResponseException(ErrorType.NotFound, "Default attribute instance is not present"); } } } else { throw new ResponseException(ErrorType.NotFound, "Attribute is not present"); } logger.trace("deleteFields() :: completed"); return objectNode; } EntityService(EntityProducerChannel producerChannels, ObjectMapper objectMapper); void setOperations(KafkaOps operations); String createMessage(String payload); JsonNode getKeyValueEntity(JsonNode json); UpdateResult updateMessage(String entityId, String payload); AppendResult appendMessage(String entityId, String payload, String overwriteOption); boolean deleteEntity(String entityId); UpdateResult partialUpdateEntity(String entityId, String attrId, String payload); boolean deleteAttribute(String entityId, String attrId,String datasetId,String deleteAll); UpdateResult updateFields(String originalJsonObject, JsonNode jsonToUpdate, String attrId); AppendResult appendFields(String originalJsonObject, JsonNode jsonToAppend, String overwriteOption); JsonNode deleteFields(String originalJsonObject, String attrId, String datasetId, String deleteAll); boolean registerContext(byte[] id, byte[] payload); URI getResourceURL(String resource); void validateEntity(String payload, HttpServletRequest request); BatchResult createMultipleMessage(String payload); BatchResult deleteMultipleMessage(String payload); BatchResult updateMultipleMessage(String resolved); BatchResult upsertMultipleMessage(String resolved);  }### Answer:
@Test public void deleteAttributeInstanceIfDatasetIdExistTest() { try { Mockito.doReturn(payloadNode).when(objectMapper).readTree(any(String.class)); entityService.deleteFields(entityPayload, "http: } catch (Exception ex) { Assert.fail(); } }
@Test public void deleteAllAttributeInstanceTest() { try { Mockito.doReturn(payloadNode).when(objectMapper).readTree(any(String.class)); entityService.deleteFields(entityPayload, "http: } catch (Exception ex) { Assert.fail(); } }