title: How to write Junit test for mapstruct abstract mapper injected via Spring
body: <p>I'm using MapStruct, mapstruct-jdk8 version 1.1.0.Final and defining abstract class that I inject via Spring.</p>
  
  <p>I'm looking at how to be able to test them via Junit Test ?
  I've basicaly a main mapper that will use 2 sub mappers</p>
  
  <pre><code>@Mapper(componentModel = "spring", uses = {SubMapper1.class, SubMapper2.class})
  public abstract class MainMapper {
  
    @Mapping(target = "field1", qualifiedByName = {"MyMapper2Name", "toEntity"})
    public abstract MyEntity toEntity(MyDto pDto);
  
    public MyDto fromEntity(MyEntity pEntity) {
       // Specific code, hence why I use Abstract class instead of interface. 
    }
  }
  </code></pre>
  
  <p>I've tried several things but can't get the mapper to be instancied correctly to test it.</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  public class MainMapperTest {
  
      private MainMapper service = Mappers.getMapper(MainMapper.class);
  
      @Test
      public void testToEntity() throws Exception {
  .....
  </code></pre>
  
  <blockquote>
    <p>java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation for com.mappers.MainMapper</p>
  </blockquote>
  
  <p>I've also tried via @InjectMock but no dice either.</p>
  
  <blockquote>
    <p>Cannot instantiate @InjectMocks field named 'service'. You haven't
    provided the instance at field declaration so I tried to construct the
    instance. However, I failed because: the type 'MainMapper is
    an abstract class.</p>
  </blockquote>
  
  <p>And via Spring @Autowired </p>
  
  <blockquote>
    <p>Caused by:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type 'com.mappers.MainMapper' available: expected
    at least 1 bean which qualifies as autowire candidate. Dependency
    annotations:
    {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  
  <p>I'm guessing this might have to do with annotation processor, and mapper not being generated when I launch test.
  I found <a href="https://github.com/mapstruct/mapstruct/blob/master/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/SpringDecoratorTest.java" rel="noreferrer">this class as example</a>.</p>
  
  <p>However the class AnnotationProcessorTestRunner doesn't seems to be available before 1.2 which has no final release yet.</p>
  
  <p>So my question is how do I write Junit tests to test my mapstruct abstract class mapper that I use via Spring injection in my code.</p>