yesamer commented on code in PR #6085:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762809455


##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
 package org.kie.dmn.feel.runtime.functions;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
 
 class ReplaceFunctionTest {
 
     private static final ReplaceFunction replaceFunction = 
ReplaceFunction.INSTANCE;
 
-    @Test
-    void invokeNull() {
-        FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, 
null), InvalidParametersEvent.class);
-        
FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, 
null),
-                                           InvalidParametersEvent.class);
-        
FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", 
null),
-                                           InvalidParametersEvent.class);
-        FunctionTestUtil.assertResultError(replaceFunction.invoke(null, 
"test", null), InvalidParametersEvent.class);
-        FunctionTestUtil.assertResultError(replaceFunction.invoke(null, 
"test", "ttt"), InvalidParametersEvent.class);
-        FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, 
"ttt"), InvalidParametersEvent.class);
+    @ParameterizedTest
+    @MethodSource("invokeNullTestData")
+    void invokeNullTest(String input, String pattern, String replacement, 
Class<?> expectedErrorEventClass) {

Review Comment:
   Done



##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.util;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+    @ParameterizedTest
+    @MethodSource("executeMatchesFunctionTestData")
+    void executeMatchesFunctionTest(String input, String pattern, String 
flags, boolean expected) {
+        assertThat(XQueryImplUtil.executeMatchesFunction(input, pattern, 
flags)).isEqualTo(expected);
+    }
+
+    private static Object[][] executeMatchesFunctionTestData() {
+        return new Object[][] {
+                { "test", "^test", "i", true },
+                { "fo\nbar", "o.b", null, false },
+                { "TEST", "test", "i", true },
+        };
+    }
+
+    @ParameterizedTest
+    @MethodSource("executeMatchesFunctionInvokingExceptionTestData")
+    void executeMatchesFunctionInvokingExceptionTest(String input, String 
pattern, String flags,
+                                                     Class<?> 
expectedException, String exceptionMessage) {
+        assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction(input, 
pattern, flags))
+                
.isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+    }
+
+    private static Object[][] 
executeMatchesFunctionInvokingExceptionTestData() {
+        return new Object[][] {
+                { "test", "^test", "g", IllegalArgumentException.class, 
"Unrecognized flag" },
+                { "test", "(?=\\s)", null, IllegalArgumentException.class, "No 
expression before quantifier" },
+                { "test", "(.)\\2", "i", IllegalArgumentException.class, 
"invalid backreference \\2" },
+        };
+    }
+
+    @ParameterizedTest
+    @MethodSource("executeReplaceFunctionTestData")
+    void executeReplaceFunctionTest(String input, String pattern, String 
replacement, String flags, String expected) {
+        assertThat(XQueryImplUtil.executeReplaceFunction(input, pattern, 
replacement, flags)).isEqualTo(expected);
+    }
+
+    private static Object[][] executeReplaceFunctionTestData() {
+        return new Object[][] {
+                { "testString", "^test", "ttt", "", "tttString" },
+                { "fo\nbar", "o.b", "ttt", "s", "ftttar" },
+        };
+    }
+
+    @ParameterizedTest
+    @MethodSource("executeReplaceFunctionInvokingExceptionTestData")
+    void executeReplaceFunctionInvokingExceptionTest(String input, String 
pattern, String replacement, String flags,
+                                                     Class<?> 
expectedException, String exceptionMessage) {
+        assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction(input, 
pattern, replacement, flags))
+                
.isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+    }
+
+    private static Object[][] 
executeReplaceFunctionInvokingExceptionTestData() {
+        return new Object[][] {
+                { "fo\nbar", "o.b", "ttt", "g", 
IllegalArgumentException.class, "Unrecognized flag" },
+                { "test", "(?=\\s)", "ttt", null, 
IllegalArgumentException.class, "No expression before quantifier" },
+                { "test", "(.)\\2", "ttt", null, 
IllegalArgumentException.class, "invalid backreference \\2" },
+        };
+    }
+
+    @ParameterizedTest
+    @MethodSource("evaluateXQueryExpressionValidParametersTestData")
+    void evaluateXQueryExpressionValidParametersTest(String expression, 
Class<?> returnTypeClass, Object expectedResult) {
+        assertThat(XQueryImplUtil.evaluateXQueryExpression(expression, 
returnTypeClass)).isEqualTo(expectedResult);
+
+    }
+
+    private static Object[][] 
evaluateXQueryExpressionValidParametersTestData() {
+        return new Object[][] {
+                { "matches('test', '^test', 'i')", Boolean.class, true },
+                { "matches('fo\\nbar', 'o.b', '')", Boolean.class, false },
+                { "replace('testString', '^test', 'ttt', '')", String.class, 
"tttString" }
+        };
+    }
+
+    @ParameterizedTest
+    @MethodSource("evaluateXQueryExpressionInvalidParametersTestData")
+    void evaluateXQueryExpressionInvalidParametersTest(String expression, 
Class<?> returnTypeClass, Class<?> expectedException) {

Review Comment:
   Done



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to