Skip to content

Jukito shouldn't inject optional injection points #61

@tbroyer

Description

@tbroyer

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions