-
Notifications
You must be signed in to change notification settings - Fork 0
[TG-5859] Always use Objenesis to instantiate objects #59
Conversation
It looks like the Travis command to install openjdk6 is failing. This also happens on develop. |
c8d49d0
to
ce16df8
Compare
Based on #60, which has to be merged first as Travis no longer supports openjdk6. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems sensible
50ae2cd
to
5b822ae
Compare
6d2a9e7
to
7d2ba28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs need updating but thanks for adding a test!
@@ -0,0 +1,12 @@ | |||
package com.diffblue.deeptestutils.regression; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 It would be super awesome if you were you to add tests for what happens when creating abstract classes and interfaces since that code is a complicated under tested mess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do this in the follow-up PR for https://diffblue.atlassian.net/browse/TG-5895, as that will fix the exception wrapping for interfaces and abstract classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling real constructors is problematic as they might have side effects that are not considered by Diffblue Cover. For example, a field could be set by calling a method on a static field, and Diffblue Cover would not know that this field should be set to something non-null. See the following commit for an example.
This test would fail without the changes from the previous commit.
7d2ba28
to
0987f74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got to love it when you start picking at a bit of code a find a nest of bugs...
We previously used real constructors if a constructor with no arguments was defined in the class to instantiate. Such a constructor could have code with side effects that Diffblue Cover is not analysing, which could lead to failing tests, see the regression test in this PR (added to a new folder
regression
to distinguish it from the unit tests generated by Diffblue Cover).It makes sense to always use Objenesis to create objects so we don't have to worry about accidentally causing side effects anywhere when we use reflection.