-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Switch to PrivateConstructorChecker for "testNotInstantiable" tests #3130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to PrivateConstructorChecker for "testNotInstantiable" tests #3130
Conversation
@@ -11,6 +11,7 @@ apply plugin: 'java' | |||
dependencies { | |||
testCompile 'junit:junit-dep:4.10' | |||
testCompile 'org.mockito:mockito-core:1.8.5' | |||
testCompile 'com.pushtorefresh.java-private-constructor-checker:checker:1.0.0' |
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'm not sure about this; it is unusual to add dependencies to RxJava.
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's a small (only one class), test dependency that won't affect project.
@benjchristensen what is your opinion?
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 question the need of this assertion, thus it doesn't seem a strong enough value to warrant a dependency.
Instead of another library, you could create a utility method on a test class that does this check and call it from all places. |
I can just copy Okay? |
Sounds good. |
af51773
to
61a8cbe
Compare
Added @akarnokd I'll add missing tests for other non-instantiable classes in a separate PR to make it easier for review. |
I don't understand why we need this assertion, or the ability to assert this via tests. |
@benjchristensen because we are humans and we make mistakes, somebody may delete private constructor in some huge PR and it can be merged and API will become public. Quote from https://github.com/pushtorefresh/java-private-constructor-checker
|
👍 |
Without having an external dependency, that removes my strong opinion. Now I don't have strong opinions one way or another on this. I can't think of a single time when a private constructor becoming public has been an issue, nor do I think people will ever remember to write unit tests asserting this behavior, but if it is deemed worthwhile by others, it is fine by me. @ReactiveX/rxjava-committers what do you think? |
I loved to see the coverage max out with this kind of test in my related PRs and I planned to factor out the common check in the next improvement run. I'm in favor, but the checker's package should be rx.internal.util instead. |
@akarnokd I hope you mean |
Keep it among the tests of course. |
498164c
to
0c26c9c
Compare
@akarnokd done! |
Is the motivation here to get a higher score on code coverage reports? Why is it necessary to create private constructors? 100% is not achievable nor is it an effective measure of good tests. |
@stealthcode not only higher score on code coverage, but also verification of the class contract. Would you test |
Okay. I can't see any harm (or benefit) from asserting that the |
Fair enough :) I'm going to add such tests for all other classes ( |
I don't want to discourage writing good tests. Submitting PRs to improve the quality of tests is certainly welcome and that's what I see that this PR is doing. That said, the tests that you are modifying are making assertions and establishing certain contracts that are not necessarily essential or permanent. We are making a conscious decision not to require code coverage (or other such tools) in the release process, nor are we taking a stance on which tools we want people to use. However we encourage and hope to provide a mechanism by which contributors can standardize tools configuration if you the individual developer choose to use these tools (see #3089). A larger decision should be made as to how we will address the use of build or bug finding tools in RxJava. I'm going to open an issue so that people can comment with suggestions or requests. |
I'd support merging the helper utility if we can use it to assert that public constructors don't exist for the classes where we have static method helpers to build them. I think this list includes:
and (unless someone objects) I think we could delete the tests to assert non-public constructors for
I think these are valid contract assertions (but anyone feel free to correct me). Also I opened the issue to discuss tools (as mentioned in my previous comment). Please see #3164. |
@artem-zinnatullin can this be closed or is there still work to be done in this pull request? |
Let's close this, looks like not a lot of people see sense in this (it's ok, no problem). |
@akarnokd as I promised in #3112 I am adding nice class that allows to assert that:
Here is the repository: https://github.com/pushtorefresh/java-private-constructor-checker
Hope you'll find it nice & useful!
Previous solution didn't check that constructor is private, that class has only one constructor and it required a lot of boilerplate code!