I am trying to write a JUnit for below code but I am not getting any idea how to cover the code which is written in catch block statement. Please can any one write a sample JUni
You can use Mocking frameworks like Mockito
In your JUnit Test you can do something like
public class YourTest {
private ProductcacheDao productCacheDaoMock;
@Before
public void setup() throws Exception {
productCacheDaoMock = Mockito.mock(ProductcacheDao.class);
}
@org.junit.Test
public void test() {
// Given
Mockito.when(productCacheDaoMock.getProductLookUpData()).thenThrow(new RuntimeException());
// When
// do your stuff
productCacheDaoMock.getProductLookUpData();
// Then
// ...
}
}