This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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?
 
 
subject: autowired inherited dependency not getting mocked while executing test case with junit and mockito
 
Similar Threads
Spring Junit test issue
how to read config file from other mahine using java
instance variable
Spring-Test-MVC & Mockito
constructor with private access modifier