### Question:
CSourceService { public boolean updateCSourceRegistration(String registrationId, String payload) throws ResponseException, Exception { MessageChannel messageChannel = producerChannels.csourceWriteChannel(); if (registrationId == null) { throw new ResponseException(ErrorType.BadRequestData); } byte[] csourceBytes = operations.getMessage(registrationId, this.CSOURCE_TOPIC); if (csourceBytes == null) { throw new ResponseException(ErrorType.NotFound); } JsonNode entityJsonBody = objectMapper.createObjectNode(); entityJsonBody = objectMapper.readTree(csourceBytes); CSourceRegistration prevCSourceRegistration = DataSerializer.getCSourceRegistration(entityJsonBody.toString()); logger.debug("Previous CSource Registration:: " + prevCSourceRegistration); CSourceRegistration updateCS = DataSerializer.getCSourceRegistration(payload); CSourceRegistration newCSourceRegistration = prevCSourceRegistration.update(updateCS); synchronized (this) { TimerTask task = regId2TimerTask.get(registrationId.toString()); if (task != null) { task.cancel(); } this.csourceTimerTask(newCSourceRegistration); } csourceSubService.checkSubscriptions(prevCSourceRegistration, newCSourceRegistration); this.operations.pushToKafka(messageChannel, registrationId.getBytes(), DataSerializer.toJson(newCSourceRegistration).getBytes()); handleFed(); return true; } CSourceService(CSourceProducerChannel producerChannels); List<JsonNode> getCSourceRegistrations(); CSourceRegistration getCSourceRegistrationById(String registrationId); boolean updateCSourceRegistration(String registrationId, String payload); URI registerCSource(CSourceRegistration csourceRegistration); void csourceTimerTask(CSourceRegistration csourceReg); boolean deleteCSourceRegistration(String registrationId); @KafkaListener(topics = "${csource.registry.topic}", groupId = "regmanger") // (CSourceConsumerChannel.contextRegistryReadChannel) void handleEntityRegistration(Message<?> message); @KafkaListener(topics = "${csource.query.topic}", groupId = "csourceQueryHandler") @SendTo // @SendTo("QUERY_RESULT") // for tests without QueryManager byte[] handleContextQuery(@Payload byte[] message);  }### Answer:
@Test public void updateCSourceTest() { try { byte[] payloadBytes = payload.getBytes(); updateCSourceReg.setInternal(false); Mockito.doReturn(payloadBytes).when(operations).getMessage(any(), any()); Mockito.doReturn(blankNode).when(objectMapper).createObjectNode(); Mockito.doReturn(payloadNode).when(objectMapper).readTree(any(byte[].class)); Mockito.doReturn(true).when(csourceSubService).checkSubscriptions(any(CSourceRegistration.class), any(CSourceRegistration.class)); boolean result = csourceService.updateCSourceRegistration("urn:ngsi-ld:ContextSourceRegistration:csr1a3456", updatePayload); Assert.assertTrue(result); }catch(Exception ex) { Assert.fail(); } }