title: MapStruct Converter with Autowired Dependency Does Not Work With Mockito
body: <p>Given the following mapper...</p>
  <pre><code>@Mapper(componentModel = &quot;spring&quot;)
  public abstract class MyConverter {
  
      @Autowired protected TimeUtils timeUtils;
  
      @Mapping(
          target = &quot;expiryDate&quot;,
            expression =
                &quot;java(timeUtils.toDate(&quot;subscription.getDuration()))&quot;)
      public abstract SubscriptionPo convert @NonNull final Subscription subscription);
  }
  </code></pre>
  <p>... I've defined a mapping that gets the ISO 8601 duration (i.e. &quot;P2Y&quot;) from the input <code>subscription</code> and calculates the end date by calling <code>timeUtils.toDate</code>:</p>
  <pre><code>public class TimeUtils {
  
      private final Clock clock = Clock.systemDefaultZone();
  
      public LocalDate toDate(@NonNull final String iso8601) {
          final Period period = Period.parse(iso8601);
          return (LocalDate) period.addTo(LocalDate.now(clock));
      }
  }
  </code></pre>
  <p>Then, here is my unit test class:</p>
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class MyConverteTest {
  
      @InjectMocks
      private MyConverter myConverter = Mappers.getMapper(MyConverte.class);
  
      @Mock private final TimeUtils timeUtils;
  
      @Test
      void convertPeriodToDate_ok() {
          // setup data
          final Subscription subscription = Subscription.Builder
              .id(1)
              .period(&quot;P2Y&quot;)
              .build;
    
           final LocalDate expiryDate = new TimeUtils.toDate(subscription.getDuration());
  
           // commenting out the following line has no effect
           when(timeUtils.toDate(anyString()).thenReturn(expiryDate);
  
           // run unit test
           final SubscriptionPo subscriptionPo = myConverter.convert(subscription);
  
           // check result
           assertNotNull(subscriptionPo);
           assertEquals(subscription.getId(), subscriptionPo.getId());             
           assertEquals(expiryDate, subscriptionPo.getExpiryDate());
      }
  }
  </code></pre>
  <p>When I run the unit test above, it seems that <code>TimeUtils.toDate</code>has no effects, i.e. <code>subscriptionPo.getExpiryDate()</code> returns <code>null</code>. Note that if I use <code>MyConverter</code> in the actual code, it works as expected.</p>
  <p>Am I missing something? Any help would be really appreciated.</p>