Following is the working code i used while testing similar method
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.jdbc.core.JdbcTemplate;
@RunWith(MockitoJUnitRunner.class)
public class DecompileTest {
@Mock/* works fine with autowired dependency too */
JdbcTemplate jdbcTemplate;
@InjectMocks/* for the claa that we are mocking */
Decompile testclass;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testgetRunner() {
Mockito.lenient().when(jdbcTemplate.queryForObject("select * from .. ",String.class, new Object[] { 1001 } )).thenReturn("resultval");
testclass.getRunner();
}
}
mvn package used as following ( compatible with spring version > 2 /* tested */ )
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>