Skip to content
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

Improve the error message when @Tested can't find a suitable constructor #9

Closed
rliesenfeld opened this issue Jul 16, 2014 · 0 comments
Closed
Assignees
Labels

Comments

@rliesenfeld
Copy link
Member

@rliesenfeld rliesenfeld commented Jul 16, 2014

From issue 344 in the old issue tracker at Google Code:

Given a tested class with a single public constructor having several parameters of distinct types, and an @Injectable field in the test class for each parameter, the following exception was reported to occur:

java.lang.IllegalArgumentException: No constructor in class com.murex.processing.plugins.ppsconnector.utility.UtilityServiceImpl that can be satisfied by available injectables

I think it’s worth it for the code to take the time and include in the exception message at least:

  1. which constructors it found (if there are several) and which of these it chose to use for injection;
  2. which constructor arguments or injectable fields it could not satisfy;
  3. for each element of (2), if there are any fields or parameters in scope that have a type assignable to that element (annotated or not), the reason why it was not selected;
  4. ideally, it should also tell you why it matched the parts that it could match (mostly useful if there were several possibilities).

In other words, rather than:

java.lang.IllegalArgumentException: No constructor in class my.TestedClass that can be satisfied by available injectables

It should say something like this:

java.lang.IllegalArgumentException: No constructor in class my.TestedClass that can be satisfied by available injectables:

Candidate constructor my.TestedClass.TestedClass(A, B, C) cannot be satisfied:
Argument 1 cannot be satisfied:
) there are no fields of parameters of type A (or “assignable to A”, I’m not sure of the rules here)
Argument 2 cannot be satisfied:
*) candidate field my.TestedClassUnitTests.instanceA is not annotated with @Injectable
Argument 3 is satisfied by field my.TestedClassUnitTests.instanceC:
*) argument 2 of my.TestedClassUnitTests.testSomething(C, C) matches but /
reason this was not preferred /
*) field my.TestedClassUnitTests.instanceC2 /
idem */

Candidate constructor my.TestedClass.TestedClass(A, D) cannot be satisfied:
Argument 1 cannot be satisfied (see above)
Argument 2 cannot be satisfied /* whatever reason */

@rliesenfeld rliesenfeld self-assigned this Jul 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.