You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/09/22 04:59:00 UTC

[jira] [Created] (JXPATH-198) Refactor Context to improve test logic

Xiao Wang created JXPATH-198:
--------------------------------

             Summary: Refactor Context to improve test logic
                 Key: JXPATH-198
                 URL: https://issues.apache.org/jira/browse/JXPATH-198
             Project: Commons JXPath
          Issue Type: Improvement
            Reporter: Xiao Wang


h3. Description

I noticed that there is a test class [Context|https://github.com/apache/commons-jxpath/blob/192f4c92727cf5387a8043525a1e1e1533c9ac69/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java#L388] implements production interface [ExpressionContext|https://github.com/apache/commons-jxpath/blob/192f4c92727cf5387a8043525a1e1e1533c9ac69/src/main/java/org/apache/commons/jxpath/ExpressionContext.java#L45] to assist testing  [ClassFunctions.getFunction(String, String, Object)|https://github.com/apache/commons-jxpath/blob/192f4c92727cf5387a8043525a1e1e1533c9ac69/src/main/java/org/apache/commons/jxpath/ClassFunctions.java#L91], [ConstructorFunction.invoke(ExpressionContext, Object[])](https://github.com/apache/commons-jxpath/blob/192f4c92727cf5387a8043525a1e1e1533c9ac69/src/main/java/org/apache/commons/jxpath/functions/ConstructorFunction.java#L52) and [MethodFunction.invoke(ExpressionContext, Object[])](https://github.com/apache/commons-jxpath/blob/192f4c92727cf5387a8043525a1e1e1533c9ac69/src/main/java/org/apache/commons/jxpath/functions/MethodFunction.java#L48). This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

h3. Current Implementation
 * {{Context}} overrides {{getContextNodePointer()}} to control the behavior.
 * {{Context}} implements {{ExpressionContext}} and implement methods to return the default values.
 * In test case, the child test class is used to assit testing by passing as a parameter to {{Function.invoke(ExpressionContext, Object[])}}.

h3. Proposed Implementation
 * Replace {{Context}} with a mocking object created by Mockito.
 * Use method stub to control the behavior of {{getContextNodePointer()}}.
 * Create a method to return the mocking object for reusing.

h3. Motivation
 * Decouple test class {{Context}} from production interface {{ExpressionContext}}.
 * Remove the redundant test child class {{Context}}
 * Remove the redundant overridden methods that return default values.
 * Make testing logic more explict.




--
This message was sent by Atlassian Jira
(v8.3.4#803005)