From 40eb7fa64a254ab3ad1a6ea0ccaf73508c1d3078 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Mon, 25 Sep 2023 17:13:41 +0200 Subject: [PATCH] #997: Replace Optional.orElse() with Optional.orElseGet() to evaluate non-static values lazily --- .../docker/command/ContainerCreate.java | 2 +- .../actions/AbstractAsyncTestAction.java | 2 +- .../org/citrusframework/actions/InputAction.java | 2 +- .../actions/SendMessageAction.java | 2 +- .../condition/ActionCondition.java | 4 ++-- .../container/AbstractActionContainer.java | 2 +- .../org/citrusframework/container/Template.java | 2 +- .../org/citrusframework/message/ZipMessage.java | 2 +- .../selector/DelegatingMessageSelector.java | 2 +- .../org/citrusframework/report/HtmlReporter.java | 2 +- .../citrusframework/report/JUnitReporter.java | 4 ++-- .../java/org/citrusframework/util/FileUtils.java | 2 +- .../DefaultMessageHeaderValidator.java | 6 +++--- .../citrusframework/ftp/client/FtpClient.java | 4 ++-- .../citrusframework/ftp/client/SftpClient.java | 2 +- .../ftp/server/FtpServerFtpLet.java | 2 +- .../citrusframework/ftp/server/SftpServer.java | 2 +- .../http/message/HttpMessage.java | 2 +- .../message/HttpQueryParamHeaderValidator.java | 2 +- .../jms/endpoint/JmsTopicSubscriber.java | 6 +++--- .../kafka/embedded/EmbeddedKafkaServer.java | 2 +- .../kafka/endpoint/KafkaConsumer.java | 2 +- .../kafka/endpoint/KafkaProducer.java | 4 ++-- .../kafka/message/KafkaMessageConverter.java | 4 ++-- .../selector/DispatchingMessageSelector.java | 2 +- .../citrusframework/ssh/server/SshServer.java | 2 +- .../client/WebServiceEndpointConfiguration.java | 2 +- .../citrusframework/junit/JUnit4TestEngine.java | 2 +- .../citrusframework/main/CitrusAppOptions.java | 2 +- .../org/citrusframework/testng/TestNGEngine.java | 4 ++-- .../org/citrusframework/xml/XmlTestCase.java | 2 +- .../org/citrusframework/yaml/YamlTestCase.java | 2 +- .../mvn/plugin/CreateDocsMojo.java | 4 ++-- .../mvn/plugin/CreateTestMojo.java | 16 ++++++++-------- .../mvn/plugin/GenerateDocsMojo.java | 4 ++-- .../mvn/plugin/GenerateTestMojo.java | 16 ++++++++-------- .../generate/javadsl/JavaTestGenerator.java | 2 +- .../javadsl/MessagingJavaTestGenerator.java | 8 ++++---- .../generate/xml/MessagingXmlTestGenerator.java | 8 ++++---- 39 files changed, 71 insertions(+), 71 deletions(-) diff --git a/connectors/citrus-docker/src/main/java/org/citrusframework/docker/command/ContainerCreate.java b/connectors/citrus-docker/src/main/java/org/citrusframework/docker/command/ContainerCreate.java index 5c87d2e176..ba46196bc9 100644 --- a/connectors/citrus-docker/src/main/java/org/citrusframework/docker/command/ContainerCreate.java +++ b/connectors/citrus-docker/src/main/java/org/citrusframework/docker/command/ContainerCreate.java @@ -237,7 +237,7 @@ private Ports getPortBindings(String portSpecs, ExposedPort[] exposedPorts, Test Integer hostPort = Integer.valueOf(binding[0]); Integer port = Integer.valueOf(binding[1]); - portsBindings.bind(Stream.of(exposedPorts).filter(exposed -> port.equals(exposed.getPort())).findAny().orElse(ExposedPort.tcp(port)), Ports.Binding.bindPort(hostPort)); + portsBindings.bind(Stream.of(exposedPorts).filter(exposed -> port.equals(exposed.getPort())).findAny().orElseGet(() -> ExposedPort.tcp(port)), Ports.Binding.bindPort(hostPort)); } } diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java index 82f200a7d8..ede008d1e3 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java +++ b/core/citrus-base/src/main/java/org/citrusframework/actions/AbstractAsyncTestAction.java @@ -76,7 +76,7 @@ public final void doExecute(TestContext context) { public boolean isDone(TestContext context) { return Optional.ofNullable(finished) .map(future -> future.isDone() || isDisabled(context)) - .orElse(isDisabled(context)); + .orElseGet(() -> isDisabled(context)); } public abstract void doExecuteAsync(TestContext context); diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java index 4383100671..5a473382a0 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java +++ b/core/citrus-base/src/main/java/org/citrusframework/actions/InputAction.java @@ -69,7 +69,7 @@ public InputAction(Builder builder) { this.message = builder.message; this.variable = builder.variable; this.validAnswers = builder.validAnswers; - this.inputReader = Optional.ofNullable(builder.inputReader).orElse(new BufferedReader(new InputStreamReader(System.in))); + this.inputReader = Optional.ofNullable(builder.inputReader).orElseGet(() -> new BufferedReader(new InputStreamReader(System.in))); } @Override diff --git a/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java b/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java index 4476c8b56a..4e1cc35e07 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java +++ b/core/citrus-base/src/main/java/org/citrusframework/actions/SendMessageAction.java @@ -242,7 +242,7 @@ public boolean isDisabled(TestContext context) { public boolean isDone(TestContext context) { return Optional.ofNullable(finished) .map(future -> future.isDone() || isDisabled(context)) - .orElse(isDisabled(context)); + .orElseGet(() -> isDisabled(context)); } /** diff --git a/core/citrus-base/src/main/java/org/citrusframework/condition/ActionCondition.java b/core/citrus-base/src/main/java/org/citrusframework/condition/ActionCondition.java index 89d8cc2e8d..7fb143f847 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/condition/ActionCondition.java +++ b/core/citrus-base/src/main/java/org/citrusframework/condition/ActionCondition.java @@ -65,7 +65,7 @@ public boolean isSatisfied(TestContext context) { this.caughtException = e; logger.warn(String.format("Nested action did not perform as expected - %s", Optional.ofNullable(e.getMessage()) .map(msg -> e.getClass().getName() + ": " + msg) - .orElse(e.getClass().getName()))); + .orElseGet(() -> e.getClass().getName()))); return false; } @@ -82,7 +82,7 @@ public String getErrorMessage(TestContext context) { if (caughtException != null) { return String.format("Failed to check test action condition - action '%s' did not perform as expected: %s", getActionName(), Optional.ofNullable(caughtException.getMessage()) .map(msg -> caughtException.getClass().getName() + ": " + msg) - .orElse(caughtException.getClass().getName())); + .orElseGet(() -> caughtException.getClass().getName())); } else { return String.format("Failed to check test action condition - action '%s' did not perform as expected", getActionName()); } diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractActionContainer.java b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractActionContainer.java index 0028f8a764..e11737f966 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/container/AbstractActionContainer.java +++ b/core/citrus-base/src/main/java/org/citrusframework/container/AbstractActionContainer.java @@ -109,7 +109,7 @@ public boolean isDone(TestContext context) { if (action instanceof Completable && !((Completable) action).isDone(context)) { if (logger.isDebugEnabled()) { logger.debug(Optional.ofNullable(action.getName()).filter(name -> name.trim().length() > 0) - .orElse(action.getClass().getName()) + " not completed yet"); + .orElseGet(() -> action.getClass().getName()) + " not completed yet"); } return false; } diff --git a/core/citrus-base/src/main/java/org/citrusframework/container/Template.java b/core/citrus-base/src/main/java/org/citrusframework/container/Template.java index 7853c365b4..0a8059673c 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/container/Template.java +++ b/core/citrus-base/src/main/java/org/citrusframework/container/Template.java @@ -359,7 +359,7 @@ protected void onBuild() { if (referenceResolver != null && templateName != null) { Template rootTemplate = referenceResolver.resolve(templateName, Template.class); globalContext(rootTemplate.isGlobalContext() && globalContext); - actor(Optional.ofNullable(getActor()).orElse(rootTemplate.getActor())); + actor(Optional.ofNullable(getActor()).orElseGet(rootTemplate::getActor)); Map mergedParameters = new LinkedHashMap<>(); mergedParameters.putAll(rootTemplate.getParameter()); mergedParameters.putAll(parameter); diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java b/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java index d422bb768c..54c40a752a 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java +++ b/core/citrus-base/src/main/java/org/citrusframework/message/ZipMessage.java @@ -168,7 +168,7 @@ public Entry(String name, File file) throws IOException { this(name); if (file.isDirectory()) { - for (File child : Optional.ofNullable(file.listFiles()).orElse(new File[] {})) { + for (File child : Optional.ofNullable(file.listFiles()).orElseGet(() -> new File[] {})) { entries.add(new Entry(child)); } } else { diff --git a/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java b/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java index 4c35b3f98e..76ce0d3bb3 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java +++ b/core/citrus-base/src/main/java/org/citrusframework/message/selector/DelegatingMessageSelector.java @@ -69,7 +69,7 @@ public boolean accept(Message message) { .allMatch(entry -> factories.stream() .filter(factory -> factory.supports(entry.getKey())) .findAny() - .orElse(new HeaderMatchingMessageSelector.Factory()) + .orElseGet(HeaderMatchingMessageSelector.Factory::new) .create(entry.getKey(), entry.getValue(), context) .accept(message)); } diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java b/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java index 96765fcd9f..d3f3786c40 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java +++ b/core/citrus-base/src/main/java/org/citrusframework/report/HtmlReporter.java @@ -83,7 +83,7 @@ public String getReportContent(TestResults testResults) { final String emptyString = ""; testResults.doWithResults(result -> { - ResultDetail detail = Optional.ofNullable(details.get(result.getTestName())).orElse(new ResultDetail()); + ResultDetail detail = Optional.ofNullable(details.get(result.getTestName())).orElseGet(ResultDetail::new); Properties detailProps = new Properties(); detailProps.put("test.style.class", result.getResult().toLowerCase()); diff --git a/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java b/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java index ebe3b80481..a641bfdedd 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java +++ b/core/citrus-base/src/main/java/org/citrusframework/report/JUnitReporter.java @@ -116,13 +116,13 @@ private String createReportContent(String suiteName, List results, R detailProps.put("test.duration", "0.0"); if (result.isFailed()) { - detailProps.put("test.error.cause", Optional.ofNullable(result.getCause()).map(Object::getClass).map(Class::getName).orElse(Objects.toString(result.getFailureType(), ""))); + detailProps.put("test.error.cause", Optional.ofNullable(result.getCause()).map(Object::getClass).map(Class::getName).orElseGet(() -> Objects.toString(result.getFailureType(), ""))); detailProps.put("test.error.msg", StringEscapeUtils.escapeXml(result.getErrorMessage())); detailProps.put("test.error.stackTrace", Optional.ofNullable(result.getCause()).map(cause -> { StringWriter writer = new StringWriter(); cause.printStackTrace(new PrintWriter(writer)); return writer.toString(); - }).orElse(Objects.toString(result.getFailureType(), ""))); + }).orElseGet(() -> Objects.toString(result.getFailureType(), ""))); reportDetails.append(System.lineSeparator()) .append(" ") .append(PropertyUtils.replacePropertiesInString(templates.getFailedTemplate(), detailProps)); diff --git a/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java b/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java index b9048706d1..ae102d7337 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java +++ b/core/citrus-base/src/main/java/org/citrusframework/util/FileUtils.java @@ -237,7 +237,7 @@ public static List findFiles(final String startDir, final Set file return accepted && !name.startsWith("CVS") && !name.startsWith(".svn") && !name.startsWith(".git"); }); - for (File found : Optional.ofNullable(foundFiles).orElse(new File[] {})) { + for (File found : Optional.ofNullable(foundFiles).orElseGet(() -> new File[] {})) { /* Subfolder support */ if (found.isDirectory()) { dirs.push(found); diff --git a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java index 438e6cb758..5c93086d0d 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java +++ b/core/citrus-base/src/main/java/org/citrusframework/validation/DefaultMessageHeaderValidator.java @@ -83,7 +83,7 @@ public void validateMessage(Message receivedMessage, Message controlMessage, Tes .stream() .filter(validator -> validator.supports(headerName, Optional.ofNullable(controlValue).map(Object::getClass).orElse(null))) .findFirst() - .orElse( + .orElseGet(() -> validationContext.getValidatorNames() .stream() .map(beanName -> { @@ -97,11 +97,11 @@ public void validateMessage(Message receivedMessage, Message controlMessage, Tes .filter(Objects::nonNull) .filter(validator -> validator.supports(headerName, Optional.ofNullable(controlValue).map(Object::getClass).orElse(null))) .findFirst() - .orElse( + .orElseGet(() -> getHeaderValidators(context).stream() .filter(validator -> validator.supports(headerName, Optional.ofNullable(controlValue).map(Object::getClass).orElse(null))) .findFirst() - .orElse(new DefaultHeaderValidator()) + .orElseGet(DefaultHeaderValidator::new) ) ).validateHeader(headerName, receivedHeaders.get(headerName), controlValue, context, validationContext); } diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java index db79fef625..39776e3f83 100644 --- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java +++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/FtpClient.java @@ -282,7 +282,7 @@ protected FtpMessage storeFile(PutCommand command, TestContext context) { String localFilePath = context.replaceDynamicContentInString(command.getFile().getPath()); String remoteFilePath = addFileNameToTargetPath(localFilePath, context.replaceDynamicContentInString(command.getTarget().getPath())); - String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElse(DataType.BINARY.name())); + String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElseGet(() -> DataType.BINARY.name())); try (InputStream localFileInputStream = getLocalFileInputStream(command.getFile().getPath(), dataType, context)) { ftpClient.setFileType(getFileType(dataType)); @@ -330,7 +330,7 @@ protected FtpMessage retrieveFile(GetCommand command, TestContext context) { Files.createDirectories(Paths.get(localFilePath).getParent()); } - String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElse(DataType.BINARY.name())); + String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElseGet(() -> DataType.BINARY.name())); try (FileOutputStream localFileOutputStream = new FileOutputStream(localFilePath)) { ftpClient.setFileType(getFileType(dataType)); diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java index 0920c57161..dd405abe0c 100644 --- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java +++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/client/SftpClient.java @@ -202,7 +202,7 @@ protected FtpMessage storeFile(PutCommand command, TestContext context) { String localFilePath = context.replaceDynamicContentInString(command.getFile().getPath()); String remoteFilePath = addFileNameToTargetPath(localFilePath, context.replaceDynamicContentInString(command.getTarget().getPath())); - String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElse(DataType.BINARY.name())); + String dataType = context.replaceDynamicContentInString(Optional.ofNullable(command.getFile().getType()).orElseGet(() -> DataType.BINARY.name())); try (InputStream localFileInputStream = getLocalFileInputStream(command.getFile().getPath(), dataType, context)) { sftp.put(localFileInputStream, remoteFilePath); } diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java index ebe9c8a33e..2b01390365 100644 --- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java +++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/FtpServerFtpLet.java @@ -91,7 +91,7 @@ public FtpMessage handleMessage(FtpMessage request) { return new FtpMessage(response); } }) - .orElse(FtpMessage.success()); + .orElseGet(FtpMessage::success); } @Override diff --git a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/SftpServer.java b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/SftpServer.java index a24a1ebf94..37c50ab8e9 100644 --- a/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/SftpServer.java +++ b/endpoints/citrus-ftp/src/main/java/org/citrusframework/ftp/server/SftpServer.java @@ -88,7 +88,7 @@ public FtpMessage handleMessage(FtpMessage request) { return new FtpMessage(response); } }) - .orElse(FtpMessage.success()); + .orElseGet(FtpMessage::success); } @Override diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java index 03b144c2bb..df8b3eab77 100644 --- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java +++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpMessage.java @@ -209,7 +209,7 @@ public HttpMessage queryParams(final String queryParamString) { header(EndpointUriResolver.QUERY_PARAM_HEADER_NAME, queryParamString); Stream.of(queryParamString.split(",")) - .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[]{keyValue, ""})) + .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElseGet(() -> new String[]{keyValue, ""})) .filter(keyValue -> StringUtils.hasText(keyValue[0])) .forEach(keyValue -> this.addQueryParam(keyValue[0], keyValue[1])); diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java index 9a6a771bb6..2fdb222aa2 100644 --- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java +++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/message/HttpQueryParamHeaderValidator.java @@ -69,7 +69,7 @@ private Map convertToMap(Object expression) { .map(Object::toString) .orElse("") .split(",")) - .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[] {keyValue, ""})) + .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElseGet(() -> new String[] {keyValue, ""})) .collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1])); } diff --git a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java index c75b9e184c..32d393c264 100644 --- a/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java +++ b/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/endpoint/JmsTopicSubscriber.java @@ -89,7 +89,7 @@ public JmsTopicSubscriber(String name, JmsEndpointConfiguration endpointConfigur */ public void run() { ConnectionFactory connectionFactory = Optional.ofNullable(endpointConfiguration.getConnectionFactory()) - .orElse(endpointConfiguration.getJmsTemplate().getConnectionFactory()); + .orElseGet(() -> endpointConfiguration.getJmsTemplate().getConnectionFactory()); TopicConnection connection = null; try { @@ -118,8 +118,8 @@ public void run() { TopicSubscriber subscriber; if (endpointConfiguration.isDurableSubscription()) { - logger.debug(String.format("Create JMS topic durable subscription '%s'", Optional.ofNullable(endpointConfiguration.getDurableSubscriberName()).orElse(getName()))); - subscriber = session.createDurableSubscriber(topic, Optional.ofNullable(endpointConfiguration.getDurableSubscriberName()).orElse(getName())); + logger.debug(String.format("Create JMS topic durable subscription '%s'", Optional.ofNullable(endpointConfiguration.getDurableSubscriberName()).orElseGet(this::getName))); + subscriber = session.createDurableSubscriber(topic, Optional.ofNullable(endpointConfiguration.getDurableSubscriberName()).orElseGet(this::getName)); } else { logger.debug("Create JMS topic subscription"); subscriber = session.createSubscriber(topic); diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java index e9efe1a9bc..2744ba22be 100644 --- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java +++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/embedded/EmbeddedKafkaServer.java @@ -193,7 +193,7 @@ protected File createLogDir() { File logDir = Optional.ofNullable(logDirPath) .map(Paths::get) .map(Path::toFile) - .orElse(new File(System.getProperty("java.io.tmpdir"))); + .orElseGet(() -> new File(System.getProperty("java.io.tmpdir"))); if (!logDir.exists()) { if (!logDir.mkdirs()) { diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java index 0bd25288b2..93fdbce942 100644 --- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java +++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaConsumer.java @@ -114,7 +114,7 @@ public void stop() { */ private org.apache.kafka.clients.consumer.KafkaConsumer createConsumer() { Map consumerProps = new HashMap<>(); - consumerProps.put(ConsumerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElse(KafkaMessageHeaders.KAFKA_PREFIX + "consumer_" + UUID.randomUUID().toString())); + consumerProps.put(ConsumerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElseGet(() -> KafkaMessageHeaders.KAFKA_PREFIX + "consumer_" + UUID.randomUUID().toString())); consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, endpointConfiguration.getConsumerGroup()); consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, Optional.ofNullable(endpointConfiguration.getServer()).orElse("localhost:9092")); consumerProps.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1); diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java index b7c4be9711..bfff4e35c6 100644 --- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java +++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/endpoint/KafkaProducer.java @@ -72,7 +72,7 @@ public void send(final Message message, final TestContext context) { String topic = Optional.ofNullable(message.getHeader(KafkaMessageHeaders.TOPIC)) .map(Object::toString) .map(context::replaceDynamicContentInString) - .orElse(context.replaceDynamicContentInString(endpointConfiguration.getTopic())); + .orElseGet(() -> context.replaceDynamicContentInString(endpointConfiguration.getTopic())); if (!StringUtils.hasText(topic)) { throw new CitrusRuntimeException(String.format("Invalid Kafka stream topic header %s - must not be empty or null", KafkaMessageHeaders.TOPIC)); @@ -105,7 +105,7 @@ private org.apache.kafka.clients.producer.KafkaProducer createKa producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, endpointConfiguration.getKeySerializer()); producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, endpointConfiguration.getValueSerializer()); - producerProps.put(ProducerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElse(KafkaMessageHeaders.KAFKA_PREFIX + "producer_" + UUID.randomUUID().toString())); + producerProps.put(ProducerConfig.CLIENT_ID_CONFIG, Optional.ofNullable(endpointConfiguration.getClientId()).orElseGet(() -> KafkaMessageHeaders.KAFKA_PREFIX + "producer_" + UUID.randomUUID().toString())); producerProps.putAll(endpointConfiguration.getProducerProperties()); diff --git a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java index 378ba55640..05447e51d4 100644 --- a/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java +++ b/endpoints/citrus-kafka/src/main/java/org/citrusframework/kafka/message/KafkaMessageConverter.java @@ -62,8 +62,8 @@ public ProducerRecord convertOutbound(Message internalMessage, K kafkaMessage = new KafkaMessage(internalMessage.getPayload(), internalMessage.getHeaders()); } - return new ProducerRecord<>(Optional.ofNullable(kafkaMessage.getTopic()).map(context::replaceDynamicContentInString).orElse(context.replaceDynamicContentInString(endpointConfiguration.getTopic())), - Optional.ofNullable(kafkaMessage.getPartition()).orElse(endpointConfiguration.getPartition()), + return new ProducerRecord<>(Optional.ofNullable(kafkaMessage.getTopic()).map(context::replaceDynamicContentInString).orElseGet(() -> context.replaceDynamicContentInString(endpointConfiguration.getTopic())), + Optional.ofNullable(kafkaMessage.getPartition()).orElseGet(endpointConfiguration::getPartition), kafkaMessage.getMessageKey(), payload, endpointConfiguration.getHeaderMapper().toHeaders(kafkaMessage.getHeaders(), context)); diff --git a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/DispatchingMessageSelector.java b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/DispatchingMessageSelector.java index 9b088fee36..1238ab6494 100644 --- a/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/DispatchingMessageSelector.java +++ b/endpoints/citrus-spring-integration/src/main/java/org/citrusframework/channel/selector/DispatchingMessageSelector.java @@ -84,7 +84,7 @@ public boolean accept(Message message) { .allMatch(entry -> factories.stream() .filter(factory -> factory.supports(entry.getKey())) .findAny() - .orElse(new HeaderMatchingMessageSelector.Factory()) + .orElseGet(HeaderMatchingMessageSelector.Factory::new) .create(entry.getKey(), entry.getValue(), context) .accept(message)); } diff --git a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java index 4069d530d9..21782049ad 100644 --- a/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java +++ b/endpoints/citrus-ssh/src/main/java/org/citrusframework/ssh/server/SshServer.java @@ -129,7 +129,7 @@ protected void startup() { sshd.setPort(port); VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(); - Path userHomeDir = Optional.ofNullable(userHomePath).map(Paths::get).map(Path::toAbsolutePath).orElse(Paths.get(String.format("target/%s/home/%s", getName(), user)).toAbsolutePath()); + Path userHomeDir = Optional.ofNullable(userHomePath).map(Paths::get).map(Path::toAbsolutePath).orElseGet(() -> Paths.get(String.format("target/%s/home/%s", getName(), user)).toAbsolutePath()); if (!Files.exists(userHomeDir)) { try { diff --git a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceEndpointConfiguration.java b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceEndpointConfiguration.java index 53c0adb3d2..859578d288 100644 --- a/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceEndpointConfiguration.java +++ b/endpoints/citrus-ws/src/main/java/org/citrusframework/ws/client/WebServiceEndpointConfiguration.java @@ -172,7 +172,7 @@ public WebServiceTemplate getWebServiceTemplate() { * @param webServiceTemplate */ public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) { - interceptors.addAll(Optional.ofNullable(webServiceTemplate.getInterceptors()).map(Arrays::asList).orElse(Collections.emptyList())); + interceptors.addAll(Optional.ofNullable(webServiceTemplate.getInterceptors()).map(Arrays::asList).orElseGet(Collections::emptyList)); this.webServiceTemplate = webServiceTemplate; webServiceTemplate.setInterceptors(interceptors.toArray(new ClientInterceptor[0])); } diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java index 4a9042d664..c76881bafd 100644 --- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java +++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4TestEngine.java @@ -102,7 +102,7 @@ private void run(List classesToRun) { .stream() .peek(testClass -> logger.info(String.format("Running test %s", Optional.ofNullable(testClass.getMethod()).map(method -> testClass.getName() + "#" + method) - .orElse(testClass.getName())))) + .orElseGet(testClass::getName)))) .map(testClass -> { try { Class clazz; diff --git a/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java b/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java index ce64fbaa96..de225e9585 100644 --- a/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java +++ b/runtime/citrus-main/src/main/java/org/citrusframework/main/CitrusAppOptions.java @@ -112,7 +112,7 @@ protected void doProcess(T configuration, String arg, String value, LinkedList Optional.ofNullable(StringUtils.split(keyValue, "=")).orElse(new String[] {keyValue, ""})) + .map(keyValue -> Optional.ofNullable(StringUtils.split(keyValue, "=")).orElseGet(() -> new String[] {keyValue, ""})) .collect(Collectors.toMap(keyValue -> keyValue[0], keyValue -> keyValue[1]))); } else { throw new CitrusRuntimeException("Missing parameter value for -D/--properties option"); diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java index e2dc058349..3fbb684e3f 100644 --- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java +++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java @@ -74,7 +74,7 @@ public void run() { for (TestClass testClass : getConfiguration().getTestClasses()) { logger.info(String.format("Running test %s", Optional.ofNullable(testClass.getMethod()).map(method -> testClass.getName() + "#" + method) - .orElse(testClass.getName()))); + .orElseGet(testClass::getName))); XmlTest test = new XmlTest(suite); test.setClasses(new ArrayList<>()); @@ -124,7 +124,7 @@ public void run() { classesToRun.stream() .peek(testClass -> logger.info(String.format("Running test %s", Optional.ofNullable(testClass.getMethod()).map(method -> testClass.getName() + "#" + method) - .orElse(testClass.getName())))) + .orElseGet(testClass::getName)))) .map(testClass -> { try { Class clazz; diff --git a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestCase.java b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestCase.java index d6164c0f8c..bd18a46043 100644 --- a/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestCase.java +++ b/runtime/citrus-xml/src/main/java/org/citrusframework/xml/XmlTestCase.java @@ -79,7 +79,7 @@ public void setVariables(Variables variables) { try { delegate.getVariableDefinitions().put(variable.name, VariableUtils.getValueFromScript(variable.multilineValue.script.getType(), FileUtils.readToString(FileUtils.getFileResource(variable.multilineValue.script.getFile()), - Optional.ofNullable(variable.multilineValue.script.getCharset()).map(Charset::forName).orElse(FileUtils.getDefaultCharset())))); + Optional.ofNullable(variable.multilineValue.script.getCharset()).map(Charset::forName).orElseGet(FileUtils::getDefaultCharset)))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read script file resource", e); } diff --git a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestCase.java b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestCase.java index 6502ced460..76f166eafd 100644 --- a/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestCase.java +++ b/runtime/citrus-yaml/src/main/java/org/citrusframework/yaml/YamlTestCase.java @@ -70,7 +70,7 @@ public void setVariables(List variables) { try { delegate.getVariableDefinitions().put(variable.name, VariableUtils.getValueFromScript(variable.script.getType(), FileUtils.readToString(FileUtils.getFileResource(variable.script.getFile()), - Optional.ofNullable(variable.script.getCharset()).map(Charset::forName).orElse(FileUtils.getDefaultCharset())))); + Optional.ofNullable(variable.script.getCharset()).map(Charset::forName).orElseGet(FileUtils::getDefaultCharset)))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read script file resource", e); } diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateDocsMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateDocsMojo.java index 295ce3d84f..6f081f9f9a 100644 --- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateDocsMojo.java +++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateDocsMojo.java @@ -156,7 +156,7 @@ private void createExcelDoc() throws PrompterException { * @return */ public HtmlTestDocsGenerator getHtmlTestDocsGenerator() { - return Optional.ofNullable(htmlTestDocsGenerator).orElse(HtmlTestDocsGenerator.build()); + return Optional.ofNullable(htmlTestDocsGenerator).orElseGet(HtmlTestDocsGenerator::build); } /** @@ -165,7 +165,7 @@ public HtmlTestDocsGenerator getHtmlTestDocsGenerator() { * @return */ public ExcelTestDocsGenerator getExcelTestDocsGenerator() { - return Optional.ofNullable(excelTestDocsGenerator).orElse(ExcelTestDocsGenerator.build()); + return Optional.ofNullable(excelTestDocsGenerator).orElseGet(ExcelTestDocsGenerator::build); } /** diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java index dbcdcc59a8..57397a23e1 100644 --- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java +++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/CreateTestMojo.java @@ -396,7 +396,7 @@ public void createWithSwagger(SwaggerTestGenerator generator) throws MojoExecuti * @return test generator. */ public XmlTestGenerator getXmlTestGenerator() { - return Optional.ofNullable(xmlTestGenerator).orElse(new XmlTestGenerator()); + return Optional.ofNullable(xmlTestGenerator).orElseGet(XmlTestGenerator::new); } /** @@ -406,7 +406,7 @@ public XmlTestGenerator getXmlTestGenerator() { * @return test generator. */ public JavaDslTestGenerator getJavaTestGenerator() { - return Optional.ofNullable(javaTestGenerator).orElse(new JavaDslTestGenerator()); + return Optional.ofNullable(javaTestGenerator).orElseGet(JavaDslTestGenerator::new); } /** @@ -417,9 +417,9 @@ public JavaDslTestGenerator getJavaTestGenerator() { */ public SwaggerTestGenerator getSwaggerTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(swaggerJavaTestGenerator).orElse(new SwaggerJavaTestGenerator()); + return Optional.ofNullable(swaggerJavaTestGenerator).orElseGet(SwaggerJavaTestGenerator::new); } else { - return Optional.ofNullable(swaggerXmlTestGenerator).orElse(new SwaggerXmlTestGenerator()); + return Optional.ofNullable(swaggerXmlTestGenerator).orElseGet(SwaggerXmlTestGenerator::new); } } @@ -431,9 +431,9 @@ public SwaggerTestGenerator getSwaggerTestGenerator() { */ public WsdlTestGenerator getWsdlTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(wsdlJavaTestGenerator).orElse(new WsdlJavaTestGenerator()); + return Optional.ofNullable(wsdlJavaTestGenerator).orElseGet(WsdlJavaTestGenerator::new); } else { - return Optional.ofNullable(wsdlXmlTestGenerator).orElse(new WsdlXmlTestGenerator()); + return Optional.ofNullable(wsdlXmlTestGenerator).orElseGet(WsdlXmlTestGenerator::new); } } @@ -445,9 +445,9 @@ public WsdlTestGenerator getWsdlTestGenerator() { */ public XsdTestGenerator getXsdTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(xsdJavaTestGenerator).orElse(new XsdJavaTestGenerator()); + return Optional.ofNullable(xsdJavaTestGenerator).orElseGet(XsdJavaTestGenerator::new); } else { - return Optional.ofNullable(xsdXmlTestGenerator).orElse(new XsdXmlTestGenerator()); + return Optional.ofNullable(xsdXmlTestGenerator).orElseGet(XsdXmlTestGenerator::new); } } diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateDocsMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateDocsMojo.java index 46fc138f13..c300e507d1 100644 --- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateDocsMojo.java +++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateDocsMojo.java @@ -100,7 +100,7 @@ public void doExecute() throws MojoExecutionException { * @return */ public HtmlTestDocsGenerator getHtmlTestDocGenerator() { - return Optional.ofNullable(htmlTestDocGenerator).orElse(HtmlTestDocsGenerator.build()); + return Optional.ofNullable(htmlTestDocGenerator).orElseGet(HtmlTestDocsGenerator::build); } /** @@ -109,6 +109,6 @@ public HtmlTestDocsGenerator getHtmlTestDocGenerator() { * @return */ public ExcelTestDocsGenerator getExcelTestDocGenerator() { - return Optional.ofNullable(excelTestDocGenerator).orElse(ExcelTestDocsGenerator.build()); + return Optional.ofNullable(excelTestDocGenerator).orElseGet(ExcelTestDocsGenerator::build); } } diff --git a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java index 7fc98960ce..f197857e37 100644 --- a/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java +++ b/tools/maven/citrus-maven-plugin/src/main/java/org/citrusframework/mvn/plugin/GenerateTestMojo.java @@ -224,7 +224,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { * @return test generator. */ public XmlTestGenerator getXmlTestGenerator() { - return Optional.ofNullable(xmlTestGenerator).orElse(new XmlTestGenerator()); + return Optional.ofNullable(xmlTestGenerator).orElseGet(XmlTestGenerator::new); } /** @@ -234,7 +234,7 @@ public XmlTestGenerator getXmlTestGenerator() { * @return test generator. */ public JavaDslTestGenerator getJavaTestGenerator() { - return Optional.ofNullable(javaTestGenerator).orElse(new JavaDslTestGenerator()); + return Optional.ofNullable(javaTestGenerator).orElseGet(JavaDslTestGenerator::new); } /** @@ -245,9 +245,9 @@ public JavaDslTestGenerator getJavaTestGenerator() { */ public SwaggerTestGenerator getSwaggerTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(swaggerJavaTestGenerator).orElse(new SwaggerJavaTestGenerator()); + return Optional.ofNullable(swaggerJavaTestGenerator).orElseGet(SwaggerJavaTestGenerator::new); } else { - return Optional.ofNullable(swaggerXmlTestGenerator).orElse(new SwaggerXmlTestGenerator()); + return Optional.ofNullable(swaggerXmlTestGenerator).orElseGet(SwaggerXmlTestGenerator::new); } } @@ -259,9 +259,9 @@ public SwaggerTestGenerator getSwaggerTestGenerator() { */ public WsdlTestGenerator getWsdlTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(wsdlJavaTestGenerator).orElse(new WsdlJavaTestGenerator()); + return Optional.ofNullable(wsdlJavaTestGenerator).orElseGet(WsdlJavaTestGenerator::new); } else { - return Optional.ofNullable(wsdlXmlTestGenerator).orElse(new WsdlXmlTestGenerator()); + return Optional.ofNullable(wsdlXmlTestGenerator).orElseGet(WsdlXmlTestGenerator::new); } } @@ -273,9 +273,9 @@ public WsdlTestGenerator getWsdlTestGenerator() { */ public XsdTestGenerator getXsdTestGenerator() { if (getType().equals("java")) { - return Optional.ofNullable(xsdJavaTestGenerator).orElse(new XsdJavaTestGenerator()); + return Optional.ofNullable(xsdJavaTestGenerator).orElseGet(XsdJavaTestGenerator::new); } else { - return Optional.ofNullable(xsdXmlTestGenerator).orElse(new XsdXmlTestGenerator()); + return Optional.ofNullable(xsdXmlTestGenerator).orElseGet(XsdXmlTestGenerator::new); } } } diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/JavaTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/JavaTestGenerator.java index 0f843cd815..f6f40b5876 100644 --- a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/JavaTestGenerator.java +++ b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/JavaTestGenerator.java @@ -96,7 +96,7 @@ protected JavaFile.Builder createJavaFileBuilder(TypeSpec.Builder testTypeBuilde */ private CodeBlock getJavaDoc() { return CodeBlock.builder() - .add("$L\n\n", Optional.ofNullable(getDescription()).orElse(getName())) + .add("$L\n\n", Optional.ofNullable(getDescription()).orElseGet(this::getName)) .add("@author $L\n", getAuthor()) .add("@since $L\n", getCreationDate()) .build(); diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/MessagingJavaTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/MessagingJavaTestGenerator.java index 18541d025b..5f2036e150 100644 --- a/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/MessagingJavaTestGenerator.java +++ b/tools/test-generator/src/main/java/org/citrusframework/generate/javadsl/MessagingJavaTestGenerator.java @@ -62,16 +62,16 @@ protected List getActions() { List codeBlocks = super.getActions(); if (getMode().equals(GeneratorMode.CLIENT)) { - codeBlocks.add(getSendRequestCodeProvider(request).getCode(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateOutboundMessage(request))); + codeBlocks.add(getSendRequestCodeProvider(request).getCode(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateOutboundMessage(request))); if (response != null) { - codeBlocks.add(getReceiveResponseCodeProvider(response).getCode(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateInboundMessage(response))); + codeBlocks.add(getReceiveResponseCodeProvider(response).getCode(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateInboundMessage(response))); } } else if (getMode().equals(GeneratorMode.SERVER)) { - codeBlocks.add(getReceiveRequestCodeProvider(request).getCode(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateInboundMessage(request))); + codeBlocks.add(getReceiveRequestCodeProvider(request).getCode(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateInboundMessage(request))); if (response != null) { - codeBlocks.add(getSendResponseCodeProvider(response).getCode(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateOutboundMessage(response))); + codeBlocks.add(getSendResponseCodeProvider(response).getCode(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateOutboundMessage(response))); } } diff --git a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/MessagingXmlTestGenerator.java b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/MessagingXmlTestGenerator.java index 50926269b0..3c2265a4aa 100644 --- a/tools/test-generator/src/main/java/org/citrusframework/generate/xml/MessagingXmlTestGenerator.java +++ b/tools/test-generator/src/main/java/org/citrusframework/generate/xml/MessagingXmlTestGenerator.java @@ -46,16 +46,16 @@ protected List getActions() { List actions = super.getActions(); if (getMode().equals(GeneratorMode.CLIENT)) { - actions.add(getSendRequestActionProvider(request).getAction(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateOutboundMessage(request))); + actions.add(getSendRequestActionProvider(request).getAction(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateOutboundMessage(request))); if (response != null) { - actions.add(getReceiveResponseActionProvider(response).getAction(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateInboundMessage(response))); + actions.add(getReceiveResponseActionProvider(response).getAction(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateInboundMessage(response))); } } else if (getMode().equals(GeneratorMode.SERVER)) { - actions.add(getReceiveRequestActionProvider(request).getAction(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateInboundMessage(request))); + actions.add(getReceiveRequestActionProvider(request).getAction(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateInboundMessage(request))); if (response != null) { - actions.add(getSendResponseActionProvider(response).getAction(Optional.ofNullable(endpoint).orElse(getMode().name().toLowerCase()), generateOutboundMessage(response))); + actions.add(getSendResponseActionProvider(response).getAction(Optional.ofNullable(endpoint).orElseGet(() -> getMode().name().toLowerCase()), generateOutboundMessage(response))); } }