Github user rafaelweingartner commented on the pull request:
https://github.com/apache/cloudstack/pull/1425#issuecomment-191455410
@nvazquez I have reviewed your code.
Class âVolumeJoinDaoImplâ at line 46, why did you change the get Logger
method to use âVolumeJoinDaoImplTestâ?
The method âupdateTemplateTagInformationâ is duplicated (I would say
triplicated) at âVolumeJoinDaoImplâ, âUserVmJoinDaoImplâ and
âTemplateJoinDaoImplâ. I know, you may argue that the method
âupdateTemplateTagInformationâ has a conditional in
âTemplateJoinDaoImplâ and âVolumeJoinDaoImplâ; still, that conditional
is executed with some additional checks in âUserVmJoinDaoImplâ. The point
here is that you should let that conditional out of the method scope, and then
extract the method to a place that can be reused in all of those classes. All
of them (VolumeJoinDaoImpl, UserVmJoinDaoImpl, and TemplateJoinDaoImpl) extend
âGenericDaoBaseâ class. You can easily create a new class that extend
âGenericDaoBaseâ, with that âupdateTemplateTagInformationâ and make all
of those classes extend this new one. Please, keep that in mind in your next
PRs.
That same is happening for VolumeJoinVO, UserVmJoinVO, and TemplateJoinVO
classes. All of them have attributes âtagAccountNameâ, âtagDomainUuidâ
and âtagDomainNameâ and their respective getters and setters. They all
extend âBaseViewVOâ, you can do that same trick I mentioned you above here.
Now about the tests. First, when writing tests, you should ask yourself,
âWhat am I going to test?â, âIf this method changes the behavior would I
like to catch it?â, âWhat is the behavior I want to monitor the behavior
of?â. Those are the basic questions.
I believe your tests, should test the method
âupdateTemplateTagInformationâ that you wrote. So, what do you want to
detect if that method stops setting a property? Do you want to detect if it
sets a property in a wrong place? If you want that, your tests now are not
adequate, if you do not want that, you should delete the tests classes.
I personally believe that the method deserves tests, to check if it is
working as expected. Meaning, that it sets the properties you want in the right
place.
Additionally, when writing tests try to code as little as possible.
Variables âaccountServiceâ and âconfigDaoâ are not needed to test the
âupdateTemplateTagInformationâ; keep in mind that is a unit test. To test
âupdateTemplateTagInformationâ you only need a simple instance of
âTemplateJoinDaoImplâ and a mock of
âApiDBUtils.newResourceTagResponse(vtag, false)â
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---