You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "LostArtist (via GitHub)" <gi...@apache.org> on 2023/07/24 12:09:00 UTC

[GitHub] [camel] LostArtist opened a new pull request, #10804: Camel 19557

LostArtist opened a new pull request, #10804:
URL: https://github.com/apache/camel/pull/10804

   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally and I have committed all auto-generated changes
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #10804: Camel 19557

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272188032


##########
core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java:
##########
@@ -39,19 +40,19 @@
 public class FluentProducerTemplateTest extends ContextTestSupport {
 
     @Test
-    public void testNoEndpoint() throws Exception {
+    public void testNoEndpoint() {
         FluentProducerTemplate fluent = context.createFluentProducerTemplate();
 
         try {
             fluent.withBody("Hello World").send();
-            fail("Should have thrown exception");
+            Assertions.assertDoesNotThrow(() -> fail("Should have thrown exception"));

Review Comment:
   This code is wrong as the code was expected to throw an exception, and hence it will execute the .. catch block.



##########
core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java:
##########
@@ -239,12 +240,12 @@ public void testExceptionUsingExchange() throws Exception {
     }
 
     @Test
-    public void testExceptionUsingProcessorAndBody() throws Exception {
+    public void testExceptionUsingProcessorAndBody() {
         try {
             DefaultFluentProducerTemplate.on(context)
                     .withBody("World")
                     .withProcessor(exchange -> exchange.getIn().setHeader("foo", 123)).to("direct:async").send();
-            fail();
+            Assertions.assertDoesNotThrow(() -> fail());

Review Comment:
   Same as before



##########
core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java:
##########
@@ -33,7 +34,7 @@ public void testDefaultPropertyPlaceholderLocationDisabled() {
             main.setDefaultPropertyPlaceholderLocation("false");
             main.start();
             main.getCamelContext().resolvePropertyPlaceholders("{{hello}}");
-            fail("Expected IllegalArgumentException");
+            Assertions.assertDoesNotThrow( () -> fail("Expected IllegalArgumentException"));

Review Comment:
   Same as before



##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   Sorry this code is harder to understand and maintain.
   
   Its perfect OK for a test method to have throws exception.
   As. the old code is 100% how an end user will write the code.
   



##########
core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java:
##########
@@ -48,7 +48,7 @@ public void testMainAws() throws Exception {
         Assertions.assertEquals("myKey", cfg.getAccessKey());
         Assertions.assertEquals("mySecret", cfg.getSecretKey());
         Assertions.assertEquals("myRegion", cfg.getRegion());
-        Assertions.assertEquals(false, cfg.isDefaultCredentialsProvider());
+        Assertions.assertFalse(cfg.isDefaultCredentialsProvider());

Review Comment:
   These changes are ok (and the following)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272362916


##########
core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java:
##########
@@ -47,26 +48,13 @@ public void testRenameSuccess() throws Exception {
     }
 
     @Test
-    public void testIllegalOptions() throws Exception {
-        try {
-            context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(new Processor() {
-                public void process(Exchange exchange) throws Exception {
-                }
-            });
-            fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
+    public void testIllegalOptions() {
 
-        try {
-            context.getEndpoint(fileUri("?move=${file:name.noext}.bak&delete=true")).createConsumer(new Processor() {
-                public void process(Exchange exchange) throws Exception {
-                }
-            });
-            fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
+        Assertions.assertThrows(IllegalArgumentException.class, () -> context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(exchange -> {
+        }), "Should have thrown an exception");

Review Comment:
   More likely you mean: 
   
   ```
          Endpoint ep = context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true");
           Assertions.assertThrows(IllegalArgumentException.class, () -> ep.createConsumer(exchange -> {
           }), "Should have thrown an exception");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272226759


##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   To be even more correct, with regards to the `run` especification, the test code should do something like this:
   
   ```
   final int ret = Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-h" }));
   Assertions.assertEquals(0, ret, "The code should return 0 when -h is requested");
   ```
   
   That ensures that: 
   1. Proper distinction between errors and failures
   2. That the correct return code (0 - or something else, if that's the expectation) is returned when a valid options is passed.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272219145


##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   Actually, the proposed change is right.
   
   In the case `my.run` throws an exception, that gets recorded as a test error not as a test failure. A test without assertions is not really testing anything (or, just, doing half of the job). 



##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   Actually, the proposed change is correct.
   
   In the case `my.run` throws an exception, that gets recorded as a test error not as a test failure. A test without assertions is not really testing anything (or, just, doing half of the job). 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272362916


##########
core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java:
##########
@@ -47,26 +48,13 @@ public void testRenameSuccess() throws Exception {
     }
 
     @Test
-    public void testIllegalOptions() throws Exception {
-        try {
-            context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(new Processor() {
-                public void process(Exchange exchange) throws Exception {
-                }
-            });
-            fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
+    public void testIllegalOptions() {
 
-        try {
-            context.getEndpoint(fileUri("?move=${file:name.noext}.bak&delete=true")).createConsumer(new Processor() {
-                public void process(Exchange exchange) throws Exception {
-                }
-            });
-            fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
+        Assertions.assertThrows(IllegalArgumentException.class, () -> context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(exchange -> {
+        }), "Should have thrown an exception");

Review Comment:
   More likely you mean: 
   
   ```
          Endpoint ep = context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true"));
           Assertions.assertThrows(IllegalArgumentException.class, () -> ep.createConsumer(exchange -> {
           }), "Should have thrown an exception");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] LostArtist commented on a diff in pull request #10804: Camel 19557

Posted by "LostArtist (via GitHub)" <gi...@apache.org>.
LostArtist commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272216604


##########
core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java:
##########
@@ -39,19 +40,19 @@
 public class FluentProducerTemplateTest extends ContextTestSupport {
 
     @Test
-    public void testNoEndpoint() throws Exception {
+    public void testNoEndpoint() {
         FluentProducerTemplate fluent = context.createFluentProducerTemplate();
 
         try {
             fluent.withBody("Hello World").send();
-            fail("Should have thrown exception");
+            Assertions.assertDoesNotThrow(() -> fail("Should have thrown exception"));

Review Comment:
   Yeah, now I see. Thanks, I'll fix it 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] LostArtist commented on a diff in pull request #10804: Camel 19557

Posted by "LostArtist (via GitHub)" <gi...@apache.org>.
LostArtist commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272217580


##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   Yes, I didn't mean to touch it. Will rollback it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] LostArtist commented on pull request #10804: Camel 19557

Posted by "LostArtist (via GitHub)" <gi...@apache.org>.
LostArtist commented on PR #10804:
URL: https://github.com/apache/camel/pull/10804#issuecomment-1657888440

   Hi, @davsclaus. I fixed all the problems you mentioned. Could you please accept them, if it's ok for you? Thanks 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272226759


##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   To be even more correct, with regards to the `run` especification, the test code should do something like this:
   
   ```
   final int ret = Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-h" }));
   Assertions.assertEquals(0, ret, "The code should return 0 when -h is requested");
   ```
   
   That ensures: 
   1. Proper distinction between errors and failures
   2. That the correct return code (0 - or something else, if that's the expectation) is returned when a valid option is passed.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10804: Camel 19557

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10804:
URL: https://github.com/apache/camel/pull/10804#issuecomment-1647785936

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :camel: Maintainers, please note that first-time contributors *require manual approval* for the GitHub Actions to run.
   
   :warning: Please note that the changes on this PR may be **tested automatically** if they change components.
   
   :robot: Use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #10804:
URL: https://github.com/apache/camel/pull/10804#discussion_r1272219145


##########
core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java:
##########
@@ -44,20 +45,20 @@ public CamelContext getCamelContext() {
     }
 
     @Test
-    public void testMainSupport() throws Exception {
+    public void testMainSupport() {
         MyMainSupport my = new MyMainSupport();
-        my.run(new String[] { "-d", "1" });
+        Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));

Review Comment:
   Actually, the proposed change is correct.
   
   In the case `my.run` throws an exception, that gets recorded as a test error not as a test failure. A test without assertions is not really testing anything (or, instead, doing half of the job). 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske merged pull request #10804: Camel 19557

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske merged PR #10804:
URL: https://github.com/apache/camel/pull/10804


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org