File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
seenu java
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic