aspose file tools*
The moose likes Testing and the fly likes autowired inherited dependency not getting mocked while executing test case with junit and mockito Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "autowired inherited dependency not getting mocked while executing test case with junit and mockito" Watch "autowired inherited dependency not getting mocked while executing test case with junit and mockito" New topic
Author

autowired inherited dependency not getting mocked while executing test case with junit and mockito

seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
public abstract class BaseClass {

@Autowired
protected DBproperties dbprop;

}

public class SampleClass extends BaseClass
{
@Autowired
private OrderService orderService ;

valdiateOrder(String input){
String config = dbprop.getProperty("config");


}


}


public class TestSampleClass{

@InjectMocks
SampleClass sampleClass ;
@Mock
private OrderService orderService ;

@Test
public void testValidateOrder(){
DBproperties dbprop = mock(DBproperties .class);
when(dbprop.getProperty("config")).thenReturn("xxxx");
assertNotNull(SampleClass.valdiateOrder("xxx"));
}
}

am using Junit4 and Mockito for test cases,in the above code dbprop.getProperty("config") throwing null pointer exception because of dbProp as null, please help me out why it was not mocked?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: autowired inherited dependency not getting mocked while executing test case with junit and mockito