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
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?
 
jQuery in Action, 2nd edition
 
subject: autowired inherited dependency not getting mocked while executing test case with junit and mockito
 
Similar Threads
instance variable
constructor with private access modifier
Spring Junit test issue
how to read config file from other mahine using java
Spring-Test-MVC & Mockito