wx930910 opened a new issue #11528: URL: https://github.com/apache/druid/issues/11528
### Description I noticed that a test class [TestInputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java#L160) implements a production interface [InputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/main/java/org/apache/druid/data/input/HandlingInputRowIterator.java#L34) to assist testing production function [HandlingInputRowIterator::next()](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/main/java/org/apache/druid/data/input/HandlingInputRowIterator.java#L71). This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks. ### Current Implementation - [TestInputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java#L160) use boolean variables to control and keep tracking invocation status of function `handle(InputRow)`. - Use assertion statements in unit tests to verify the behavior of the `TestInputRowHandler`. ### Proposed Implementation - Replace `TestInputRowHandler` with a mocking object created by Mockito. - Use method stub to control the behavior of the mocking object. - Use `Mockito.verify()` to check the method excution status. ### Motivation - Decoupling test class [TestInputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java#L160) from production class [InputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/main/java/org/apache/druid/data/input/HandlingInputRowIterator.java#L34). - Making test condition more clear by directly verify invocation status of function `handle(InputRow)` in [InputRowHandler](https://github.com/apache/druid/blob/0de1837ff7e8bffbd74524be824b1dc08b2f661d/core/src/main/java/org/apache/druid/data/input/HandlingInputRowIterator.java#L34) - Making test logic more clear by using method stub instead of method overriding. -- 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]
