Mocking the Qualified beans using mockito for a spring-boot application -


consider scenario

public class someclass {   @autowired @qualifier("converter1") private iconverter converter1;   @autowired @qualifier("converter2") private iconverter converter2;    public void dosomeaction(string mimetype) {     converter1.execute();     converter2.execute();   } } 

this code.

in order test this

@runwith(mockitojunitrunner.class) public class someclasstest {   @mock(name="converter1") iconverter converter1;   @mock(name="converter2") iconverter converter2;   @injectmocks someclass class = new someclass();   @test   public void testgetlistofexcelconverters() throws exception {     class.dosomeaction("abcd");   } } 

here mocks not getting injected, please proper mechanism mocking qualified beans.

if not right way code using spring, please let me know correct method using this.

you can mock beans using test configuration:

@configuration public class testconfig {    @bean    public myservice myservice() {       return mockito.mock( myservice.class );    } }