teragrep / pth_10

Data Processing Language (DPL) translator for Apache Spark
GNU Affero General Public License v3.0
0 stars 5 forks source link

Translation tests without getters #202

Open 51-code opened 7 months ago

51-code commented 7 months ago

Description Translation tests are for checking that the parse tree is translated correctly, namely, that the Step objects are initialized correctly. Currently the tests are done by creating a parse tree, visiting it, and then asserting that the resulting Step object has correctly initialized variables. This is done by having getters in the Step-classes, which is against Elegant Object principles.

Example of a Teragrep translation test utilizing getters: final TeragrepStep cs = ct.teragrepStep; assertEquals(AbstractTeragrepStep.TeragrepCommandMode.EXEC_HDFS_SAVE, cs.getCmdMode()); assertEquals("/tmp/path", cs.getPath()); assertNull(cs.getRetentionSpan());

The translation should probably be tested in a different way, if this is an issue at all. At least returning the correct Step can be easily tested by returning a StepNode in the visit function that gets called in tests and then checking the class of the Step object inside of the Node. However, the initialization of the Step might be more difficult to test.

kortemik commented 7 months ago

is commandMode final in TeragrepStep? if yes then it could be public final?

51-code commented 7 months ago

It isn't final but it certainly should be. However, commandMode is going to vanish in my refactoring of #28. Perhaps using public final variables and getters for non-final variables is the answer. I think that maybe getters are okay here as the reason is to just use them in unit testing. Unit testing shouldn't necessary test values of private variables, but here they happen to be the result of the parser translation which should be tested. So this is kind of an exception of an exception type situation.