### Question:
CSourceService { public URI registerCSource(CSourceRegistration csourceRegistration) throws ResponseException, Exception { MessageChannel messageChannel = producerChannels.csourceWriteChannel(); String id; URI idUri = csourceRegistration.getId(); if (idUri == null) { idUri = generateUniqueRegId(csourceRegistration); csourceRegistration.setId(idUri); } id = idUri.toString(); if (csourceRegistration.getType() == null) { logger.error("Invalid type!"); throw new ResponseException(ErrorType.BadRequestData); } if (!isValidURL(csourceRegistration.getEndpoint().toString())) { logger.error("Invalid endpoint URL!"); throw new ResponseException(ErrorType.BadRequestData); } if (csourceRegistration.getInformation() == null) { logger.error("Information is empty!"); throw new ResponseException(ErrorType.BadRequestData); } if (csourceRegistration.getExpires() != null && !isValidFutureDate(csourceRegistration.getExpires())) { logger.error("Invalid expire date!"); throw new ResponseException(ErrorType.BadRequestData); } if (this.operations.isMessageExists(id, this.CSOURCE_TOPIC)) { byte[] messageBytes = this.operations.getMessage(id, this.CSOURCE_TOPIC); JsonNode messgeJson = objectMapper.createObjectNode(); messgeJson = objectMapper.readTree(messageBytes); if (!messgeJson.isNull()) { throw new ResponseException(ErrorType.AlreadyExists); } } operations.pushToKafka(messageChannel, id.getBytes(), DataSerializer.toJson(csourceRegistration).getBytes()); this.csourceTimerTask(csourceRegistration); if (!csourceRegistration.isInternal()) { csourceSubService.checkSubscriptions(csourceRegistration, TriggerReason.newlyMatching); } handleFed(); return idUri; } 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 registerCSourceTest(){ try { csourceReg.setInternal(true); Mockito.doReturn(false).when(operations).isMessageExists(any(), any()); URI uri = csourceService.registerCSource(csourceReg); Assert.assertEquals(uri, new URI("urn:ngsi-ld:ContextSourceRegistration:csr1a3456")); }catch(Exception ex) { Assert.fail(); } }