File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: autowired inherited dependency not getting mocked while executing test case with junit and mockito