import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.mockito.exceptions.verification.NoInteractionsWanted; import org.mockito.internal.util.MockUtil; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; public static class StrictMockAnswer implements Answer<Object> { private boolean strict = false; @Override public Object answer(InvocationOnMock invocation) throws Throwable { if (strict) { throw new NoInteractionsWanted(invocation.getMethod().getName()); } return null; } public void setStrict() { strict = true; } } public static void verifyNoUnstubbedInteractions(Object... mocks) { for (Object mock : mocks) { ((StrictMockAnswer) MockUtil.getMockHandler(mock).getMockSettings().getDefaultAnswer()).setStrict(); } } public void testGetImageAnnotationsNoData() throws IOException { final String userId = "user123"; Service1 service1 = mock(Service1.class, new StrictMockAnswer()); Service2 service2 = mock(Service2.class, new StrictMockAnswer()); MyController testee = new MyController(service1, service2); when(service1.createUser(userId, "Full Name")).thenReturn(new User(userId, ...)); doNothing().when(service2.activateUser(eq(userId), isA(PrivilegedUserGroup.class))); // void method call verifyNoUnstubbedInteractions(service1, service2); assertTrue(testee.createPrivilegedUser(userId)); }
window.dump()
function. The description of window.dump(message)
says, that on Linux the parent console is used for the output, and on Windows -console
is only necessary when process is not started with redirected output, so we don't need this option. Another obstacle is window.dump()
takes only one argument and does not add newline at the end of message. The solution is to use helper wrapper like the following:function dumpToConsole() { if ($.isFunction(dump)) { logOutput = ""; // Stringify all passed arguments: for (var i = 0; i < arguments.length; i++) { var obj = arguments[i]; if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean') { logOutput += obj; } else { logOutput += JSON.stringify(obj); } } logOutput += "\n"; dump(logOutput); } }
Firefox also needs to have the following profile option set to true
(by means of Java/Selenium or hardcoding the existing profile) so that window.dump()
has any effect:
FirefoxProfile firefoxProfile = getDefaultProfile(); firefoxProfile.setPreference("browser.dom.window.dump.enabled", true);
And finally the output of Firefox driver needs to be redirected to file or, in our case, to stdout
:
mvn -Dwebdriver.firefox.logfile=/dev/stdout ...
Firefox driver will take care of redirecting the Firefox output to the same file.
/dev/stdout
is the same for both Linux and Windows. All above instructions work equally on Windows and Linux.
References:
"Девица не хочет лезть в Окно" – device not compatible with Windows.