This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new fe416d1  NIFI-6064 MockComponentLog misplaces reported exceptions
fe416d1 is described below

commit fe416d1ea0e1b7f15c1fdf8884d10f280d126f4e
Author: karthik-kadajji <[email protected]>
AuthorDate: Tue Feb 18 18:49:44 2020 +0100

    NIFI-6064 MockComponentLog misplaces reported exceptions
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #4061.
---
 .../java/org/apache/nifi/util/CapturingLogger.java    |  5 +++++
 .../nifi/util/TestStandardProcessorTestRunner.java    | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/CapturingLogger.java 
b/nifi-mock/src/main/java/org/apache/nifi/util/CapturingLogger.java
index 25b37a0..a289eaa 100644
--- a/nifi-mock/src/main/java/org/apache/nifi/util/CapturingLogger.java
+++ b/nifi-mock/src/main/java/org/apache/nifi/util/CapturingLogger.java
@@ -372,6 +372,11 @@ public class CapturingLogger implements Logger {
         logger.error(format, arg1, arg2);
     }
 
+    public void error(String format, Object arg1, Throwable t) {
+        errorMessages.add(new LogMessage(null, format, t, arg1));
+        logger.error(format, arg1, t);
+    }
+
     @Override
     public void error(String format, Object... arguments) {
         errorMessages.add(new LogMessage(null, format, null, arguments));
diff --git 
a/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
 
b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
index 134d2b8..f2febb4 100644
--- 
a/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
+++ 
b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
@@ -381,4 +381,23 @@ public class TestStandardProcessorTestRunner {
             return Arrays.asList(namePropertyDescriptor);
         }
     }
+
+    @Test
+    public void testErrorLogMessageArguments() {
+
+        String compName = "name of component";
+        final MockComponentLog logger = new MockComponentLog("first 
id",compName);
+
+        Throwable t = new ArithmeticException();
+        logger.error("expected test error",t);
+
+        String expected_throwable = "java.lang.ArithmeticException";
+
+        List<LogMessage>  log = logger.getErrorMessages();
+        LogMessage msg = log.get(0);
+        // checking if the error messages are recorded in the correct 
throwable argument.
+        assertEquals(expected_throwable,msg.getThrowable().toString());
+        assertEquals("{} expected test error",msg.getMsg());
+
+    }
 }

Reply via email to