jeudi 30 avril 2020

Mocked service not called

I have the following code.

SingleLoanDTO singleLoanDto;

@Mock
private SingleLoanService singleLoanService;

@Autowired
@InjectMocks
private LoanFacadeImpl loanFacadeImpl;

@Autowired
private MappingService mappingService;

setSingleLoanDto();
final long fake_id = 43252343;

Then I do some mock.

Mockito.when(
    singleLoanService.createSingleLoan(
        mappingService.mapTo(singleLoanDto, SingleLoan.class)
    )
).thenReturn(fake_id);

And assert, that it works.

Assert.assertEquals(fake_id,
    singleLoanService.createSingleLoan(
        mappingService.mapTo(singleLoanDto, SingleLoan.class)
));

However, instead of calling the mocked version, the code seems to call the real one.

java.lang.AssertionError: 
Expected :43252343
Actual   :0

The mapping by mappingService works. Why is the mocked version not called?

Aucun commentaire:

Enregistrer un commentaire