-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Labels
Description
I'm using a third-party library that uses Guice (Closure Templates) and makes use of optional injection:
@Inject(optional = true)
void setCheckConformance(CheckConformance checkConformance) {
this.checkConformance = checkConformance;
}Unfortunately, Jukito will inject a mock CheckConformance which will later cause issues because the contract for the interface is to never return a null, causing a NullPointerException when the mock breaks that contract:
if (checkConformance != null) {
ImmutableList<SoySyntaxException> violations = checkConformance.getViolations(soyTree);
if (!violations.isEmpty()) {Jukito shouldn't inject such injection points with mocks unless bind() or forceMock() has been called for the key.
The workaround in my case is to explicitly bind CheckConformance to a dummy instance (or configure the mock) to make sure it never return nulls.