This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit a196c9394b1299b49cb2b635a1a7eb9f0d6f3bd3 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Mon Aug 26 11:58:13 2024 +0200 (chores) camel-ftp simplify type checks - to use pattern matching for instanceof - use simpler assertion checks --- .../org/apache/camel/component/file/remote/CamelFTPParserFactory.java | 4 ++-- .../java/org/apache/camel/component/file/remote/FtpOperations.java | 4 ++-- .../org/apache/camel/component/file/remote/RemoteFileConsumer.java | 4 ++-- .../component/file/remote/RemoteFilePollingConsumerPollStrategy.java | 3 +-- .../RemoteEndPointRemoteFilePollingConsumerPollStrategyTest.java | 4 ++-- .../camel/component/file/remote/RemoteFileIgnoreDoPollErrorTest.java | 3 ++- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java index 06d8509b321..2d4b474becc 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java @@ -124,8 +124,8 @@ public class CamelFTPParserFactory extends DefaultFTPFileEntryParserFactory { } } - if (parser instanceof Configurable) { - ((Configurable) parser).configure(config); + if (parser instanceof Configurable configurable) { + configurable.configure(config); } return parser; diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java index 8a34515511d..43a29d10e43 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java @@ -146,8 +146,8 @@ public class FtpOperations implements RemoteFileOperations<FTPFile> { } if (payload.exception != null) { - if (payload.exception instanceof GenericFileOperationFailedException) { - throw (GenericFileOperationFailedException) payload.exception; + if (payload.exception instanceof GenericFileOperationFailedException genericFileOperationFailedException) { + throw genericFileOperationFailedException; } else { throw new GenericFileOperationFailedException( client.getReplyCode(), client.getReplyString(), payload.exception.getMessage(), payload.exception); diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java index bc50429d546..62dc1726b21 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java @@ -269,8 +269,8 @@ public abstract class RemoteFileConsumer<T> extends GenericFileConsumer<T> { return true; } else { LOG.trace("Not ignoring file error {} for {}", e.getMessage(), absolutePath); - if (e instanceof GenericFileOperationFailedException) { - throw (GenericFileOperationFailedException) e; + if (e instanceof GenericFileOperationFailedException genericFileOperationFailedException) { + throw genericFileOperationFailedException; } else { throw new GenericFileOperationFailedException( "Cannot poll sub-directory: " + absolutePath + " from: " + endpoint, e); diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java index 222b806637b..f517e1903f7 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java @@ -31,8 +31,7 @@ public class RemoteFilePollingConsumerPollStrategy extends DefaultPollingConsume @Override public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception { - if (consumer instanceof RemoteFileConsumer) { - RemoteFileConsumer<?> rfc = (RemoteFileConsumer<?>) consumer; + if (consumer instanceof RemoteFileConsumer<?> rfc) { // only try to recover if we are allowed to run if (rfc.isRunAllowed()) { diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteEndPointRemoteFilePollingConsumerPollStrategyTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteEndPointRemoteFilePollingConsumerPollStrategyTest.java index 68ded0df7b6..dd3be1d6c4a 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteEndPointRemoteFilePollingConsumerPollStrategyTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteEndPointRemoteFilePollingConsumerPollStrategyTest.java @@ -19,14 +19,14 @@ package org.apache.camel.component.file.remote; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; public class RemoteEndPointRemoteFilePollingConsumerPollStrategyTest extends CamelTestSupport { @Test public void testPollStrategy() { RemoteFileEndpoint<?> endpoint = context.getEndpoint("ftp://hostname", RemoteFileEndpoint.class); - assertTrue(endpoint.getPollStrategy() instanceof RemoteFilePollingConsumerPollStrategy); + assertInstanceOf(RemoteFilePollingConsumerPollStrategy.class, endpoint.getPollStrategy()); } } diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileIgnoreDoPollErrorTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileIgnoreDoPollErrorTest.java index 822800ba93f..13afb717835 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileIgnoreDoPollErrorTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileIgnoreDoPollErrorTest.java @@ -32,6 +32,7 @@ import org.apache.camel.impl.DefaultCamelContext; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -89,7 +90,7 @@ public class RemoteFileIgnoreDoPollErrorTest { Exception ex = assertThrows(GenericFileOperationFailedException.class, () -> consumer.doSafePollSubDirectory("anyPath", "adir", list, 0)); - assertTrue(ex.getCause() instanceof IllegalStateException); + assertInstanceOf(IllegalStateException.class, ex.getCause()); } @Test
