### Question:
EntityService { public UpdateResult updateMessage(String entityId, String payload) throws ResponseException, Exception { logger.trace("updateMessage() :: started"); MessageChannel messageChannel = producerChannels.updateWriteChannel(); String entityBody = validateIdAndGetBody(entityId); JsonNode updateNode = objectMapper.readTree(payload); UpdateResult updateResult = this.updateFields(entityBody, updateNode, null); if (updateResult.getStatus()) { if (directDB) { String entityWithoutSysAttrs = new String(updateResult.getJsonWithoutSysAttrs()); String withSysAttrs = new String(updateResult.getJson()); try { pushToDB(entityId, withSysAttrs, entityWithoutSysAttrs, objectMapper.writeValueAsString(getKeyValueEntity(objectMapper.readTree(withSysAttrs)))); } catch (JsonProcessingException e) { e.printStackTrace(); } } new Thread() { public void run() { try { operations.pushToKafka(messageChannel, entityId.getBytes(NGSIConstants.ENCODE_FORMAT), updateResult.getAppendedJsonFields().toString().getBytes()); updateContext(entityId.getBytes(NGSIConstants.ENCODE_FORMAT), updateResult.getJson()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ResponseException e) { e.printStackTrace(); } }; }.start(); } logger.trace("updateMessage() :: completed"); return updateResult; } 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 updateMessageTest() throws Exception{ EntityDetails entityDetails=Mockito.mock(EntityDetails.class); byte[] messageByte=entityPayload.getBytes(); JsonNode resultJson = objectMapper.createObjectNode(); UpdateResult updateResult = new UpdateResult(updateJsonNode, resultJson); updateResult.setStatus(true); Mockito.doReturn(entityDetails).when(entityTopicMap).get(any()); Mockito.doReturn(messageByte).when(operations).getMessage(any(), any(), any(Integer.class), any(Long.class)); Mockito.doReturn(payloadNode).when(objectMapper).readTree(any(String.class)); Mockito.doReturn(blankNode).when(objectMapper).createObjectNode(); Mockito.doReturn(updateResult).when(entityService).updateMessage(any(), any()); entityService.updateMessage("urn:ngsi-ld:Vehicle:A103", updatePayload); verify(entityService, times(1)).updateMessage(any(),any()); }