I have one service class and one dao class. where service class getting some input from dao class.
public SomeDao{
public String getValue(String urlType){
String value = "";
//do something here
return value
}
}
public class SomeClass {
@Autowired
SomeDao dao;
public String checkurl(String str1, String str2) throws IOException
{
Value= dao.getValue("urlType");
//Do something with URLResultAsString
}
}
writing some test for checkurl method.
@RunWith(PowerMockRunner.class)
@PrepareForTest({SomeClass.class, SomeDao.class})
public Class TestSomeClass {
private SomeClass someClass;
private SomeDao Dao = PowerMockito.mock(SomeDao.class);
@Test
public void test_checkurl() throws Exception {
PowerMockito.doReturn("Value").when(Dao).getValue(Mockito.anyString());
SomeClass.checkurl("str1", "str2");
}
}
but it giving null pointer exception here. whats wrong is done in Mocking Dao Class