spring – (mock / spy) cannot automatically connect a beanmapper used in a class by a junit test class that I am writing. Where should I look to solve this?


I am writing JUnit test classes for an inherited business application. Many classes use a Dozer BeanMapper.

import com.bpn.paylink.service.dozer.BeanMapper;  

@TransferService  
class TransferServiceImpl implements TransferService {  
  // ...  
  @Autowired  
  private BeanMapper beanMapper  

  // ...  
}  

Here is my exam class

import org.mockito.Mock;  
import org.mockito.Spy;  
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)  
public class TransferServiceImplTest {  
    @Mock // using @Spy does not work either  
    private BeanMapper beanMapper;  
    @InjectMocks  
    private TransferServiceImpl transServImpl = new transServImpl();   

    @Test
    public void someTransferTest(SomeEntity entity) {
        ....
    }
}

So, this code does not perform any logic. Simply configure my JUnit test environment. But the compiler gives this error:

Running com.rpp.TransferServiceImplTest
Tests performed: 1, Faults: 0, Errors: 1, Skipped: 0, Elapsed time: 0.085 seconds <<< FAIL!
com.bpn.paylink.payment.service.BridgeCOMMPaymentServiceImplTest Elapsed time: 0.085 seconds <<< ERROR!
org.mockito.exceptions.base.MockitoException:
Cannot make fun / spy class com.rpp.azabu.service.dozer.BeanMapper
Mockito cannot tease / spy on the following:
– final classes
– anonymous classes
– primitive types

in org.mockito.internal.runners.JUnit45AndHigherRunnerImpl $ 1.withBefores (JUnit45AndHigherRunnerImpl.java:27)
in org.junit.runners.BlockJUnit4ClassRunner.methodBlock (BlockJUnit4ClassRunner.java:276)
in org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:78)
in org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:57)
in org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:290)
in org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:71)
in org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)
in org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:58)
at org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java:268)
in org.junit.runners.ParentRunner.run (ParentRunner.java:363)
in org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run (JUnit45AndHigherRunnerImpl.java:37)
in org.mockito.runners.MockitoJUnitRunner.run (MockitoJUnitRunner.java:62)
in org.apache.maven.surefire.junit4.JUnit4Provider.execute (JUnit4Provider.java:252)
in org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet (JUnit4Provider.java:141)
in org.apache.maven.surefire.junit4.JUnit4Provider.invoke (JUnit4Provider.java:112)
in sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method)
in sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
in sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
in java.lang.reflect.Method.invoke (Method.java:498)
in org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:189)
in org.apache.maven.surefire.booter.ProviderFactory $ ProviderProxy.invoke (ProviderFactory.java:165)
in org.apache.maven.surefire.booter.ProviderFactory.invokeProvider (ProviderFactory.java:85)
in org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess (ForkedBooter.java:115)
in org.apache.maven.surefire.booter.ForkedBooter.main (ForkedBooter.java:75)

I am not using any final, anonymous or explicit internal class, nor am I using primitives that may affect the bean mapper. This will be a really challenging project. How can I get the BeanMapper instances created in the classes I need to test?
me can not Edit any source file in the business application. I can only edit my source files.

I mean, are "drills" and "spies" even the right techniques to use even in JUnit tests of classes that have Dozer BeanMappers in the first place? Am I going in the wrong direction?