Skip to content

1.x: Test all private Constructors #4125

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

Merged
merged 2 commits into from
Jun 27, 2016
Merged

1.x: Test all private Constructors #4125

merged 2 commits into from
Jun 27, 2016

Conversation

vanniktech
Copy link
Collaborator

@vanniktech vanniktech commented Jun 25, 2016

No description provided.

@codecov-io
Copy link

codecov-io commented Jun 25, 2016

Current coverage is 81.33%

Merging #4125 into 1.x will increase coverage by 0.28%

@@                1.x      #4125   diff @@
==========================================
  Files           257        257          
  Lines         16811      16811          
  Methods           0          0          
  Messages          0          0          
  Branches       2547       2547          
==========================================
+ Hits          13626      13674    +48   
+ Misses         2277       2239    -38   
+ Partials        908        898    -10   

Powered by Codecov. Last updated by ed92ba8...ae01993

@akarnokd akarnokd added the Test label Jun 25, 2016
@@ -31,7 +31,7 @@

/** Utility class, no instances. */
private Exceptions() {
throw new IllegalStateException("No instances!");
throw new AssertionError("No instances.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to AssertionError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it that this exception matches the use case a bit better since we're asserting that this constructor shall never be called.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these as unnecessary changes. The methods throw to those who instantiate the class via reflection and are not test methods themselves to fail with AssertionError like TestSubscriber.assertX.

@akarnokd
Copy link
Member

👍 Great!

/cc @artem-zinnatullin

@artem-zinnatullin
Copy link
Contributor

👍

Now I'm not that fanatic regarding testing private constructors, but since test coverage causes addiction and constant desire to increase it — let's merge it!

@davidmoten
Copy link
Collaborator

Can I suggest in the spirit of DRY that you make a static method available somewhere (a new class TestingUtil, say) like this:

public static void checkConstructorPrivate(Class<?> cls)  {
    PrivateConstructorChecker
         .forClass(cls)
        .expectedTypeOfException(IllegalStateException.class)
        .expectedExceptionMessage("No instances!").check();
}

and call that instead?

@akarnokd
Copy link
Member

Thanks!

@davidmoten I'll refactor those checks into a simple call as you and I suggested.

@akarnokd akarnokd merged commit 5c74757 into ReactiveX:1.x Jun 27, 2016
@vanniktech vanniktech deleted the 1.x_test_private_constructors branch June 27, 2016 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants