I would like to test that my call of Window.open(String)
is with the correct URL (to download a file).
Is there any better way of doing it, besides using a partial mock, like this?
MySUT sut = Mockito.spy(new MySUT());
String expectedURL = "http://www.example.com";
doNothing().when(sut).openWindow(expectedURL);
sut.doSomethingThatOpensURL();
verify(sut).openWindow(expectedURL);
Where openWindow(String)
is as simple as possible in MySUT
:
void openWindow(String url) {
Window.open(url);
}
Does GwtMockito give you something to test methods that execute native javascript like Window.open(String)
?
I suppose there is no ability to verify it using GwtMockito. But I believe it's possible using PowerMock and EasyMock. This mocking frameworks provide great flexibility to test static methods and 3rd party classes.
I've just created a simple example how you can test Window.open(). In my test case I'm just checking Window.alert(), for example.