I am trying to make test cases junits for the function using selenium webelement as argument.
I am trying to mock the element but this test case is giving error. The method for which I am trying to make test case is this.
@Override
public boolean isDownloadStarted(WebDriver driver) {
boolean isDownloadStarted = false;
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
if (tabs.size() == 1) {
isDownloadStarted = true;
}
return isDownloadStarted;
}
The test case is which is giving null pointer exception
DownloadStatusListenerImpl status;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
status = new DownloadStatusListenerImpl();
}
@Test
public void testDownloadStatusListenerImpl() {
Mockito.when(status.isDownloadStarted(Mockito.any(WebDriver.class))).thenReturn(true);
assertEquals(true, status.isDownloadStarted(Mockito.any(WebDriver.class)));
}