3
@RunWith(MockitoJUnitRunner.class)
public class TestMail{    
    @Autowired(required = true)
    SomeFactory someFactory;
    private @Mock MailService mailService;
    private @Captor ArgumentCaptor<List<MailList>> mailListCaptor;
    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
    }  
    @PostConstruct
    public void init() throws Exception {
            logger.info("someFactory {}", someFactory);
    }
}

This is sample code. Before using mockito or the @Beofre annotation everything seems to be fine. Now its mocking the objects correctly but someFactory is not autowired correctly.

Before Mockito everything worked fine.

user1364861
  • 303
  • 1
  • 2
  • 15

1 Answers1

0

If you want dependencies of SomeFactory to be injected to it use the @InjectMocks annotation.

http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/InjectMocks.html

Refer Mockito: Inject real objects into private @Autowired fields as well

Dev Blanked
  • 8,075
  • 3
  • 25
  • 32