Skip to content

Commit 11d1077

Browse files
committed
[java] Adding unit tests for driver commands to manage a VirtualAuthenticator
1 parent 29d3131 commit 11d1077

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

java/client/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java

+31-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import static java.util.Collections.EMPTY_LIST;
2121
import static java.util.Collections.emptyMap;
2222
import static java.util.Collections.singletonList;
23+
import static java.util.Collections.singletonMap;
2324
import static org.assertj.core.api.Assertions.assertThat;
2425
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
25-
import static org.mockito.ArgumentMatchers.argThat;
2626
import static org.mockito.Mockito.mock;
27-
import static org.mockito.Mockito.verify;
2827
import static org.mockito.Mockito.verifyNoMoreInteractions;
28+
import static org.mockito.Mockito.when;
2929
import static org.openqa.selenium.remote.WebDriverFixture.errorResponder;
3030
import static org.openqa.selenium.remote.WebDriverFixture.webDriverExceptionResponder;
3131
import static org.openqa.selenium.remote.WebDriverFixture.echoCapabilities;
@@ -51,9 +51,10 @@
5151
import org.openqa.selenium.WebElement;
5252
import org.openqa.selenium.WindowType;
5353
import org.openqa.selenium.testing.UnitTests;
54+
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticator;
55+
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions;
5456

5557
import java.io.IOException;
56-
import java.io.UncheckedIOException;
5758
import java.net.URL;
5859
import java.time.Duration;
5960
import java.util.Arrays;
@@ -661,6 +662,33 @@ public void canHandleIME() {
661662
new CommandPayload(DriverCommand.IME_GET_AVAILABLE_ENGINES, emptyMap()));
662663
}
663664

665+
@Test
666+
public void canAddVirtualAuthenticator() {
667+
WebDriverFixture fixture = new WebDriverFixture(
668+
echoCapabilities, valueResponder("authId"));
669+
670+
VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions();
671+
VirtualAuthenticator auth = fixture.driver.addVirtualAuthenticator(options);
672+
673+
assertThat(auth.getId()).isEqualTo("authId");
674+
fixture.verifyCommands(
675+
new CommandPayload(DriverCommand.ADD_VIRTUAL_AUTHENTICATOR, options.toMap()));
676+
}
677+
678+
@Test
679+
public void canRemoveVirtualAuthenticator() {
680+
WebDriverFixture fixture = new WebDriverFixture(
681+
echoCapabilities, nullValueResponder);
682+
VirtualAuthenticator auth = mock(VirtualAuthenticator.class);
683+
when(auth.getId()).thenReturn("authId");
684+
685+
fixture.driver.removeVirtualAuthenticator(auth);
686+
687+
fixture.verifyCommands(
688+
new CommandPayload(DriverCommand.REMOVE_VIRTUAL_AUTHENTICATOR,
689+
singletonMap("authenticatorId", "authId")));
690+
}
691+
664692
@Test
665693
public void canHandleWebDriverExceptionThrownByCommandExecutor() {
666694
WebDriverFixture fixture = new WebDriverFixture(

java/client/test/org/openqa/selenium/remote/WebDriverFixture.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public WebDriverFixture(Capabilities capabilities, Function<Command, Response>..
6060
}
6161

6262
@SafeVarargs
63-
final static CommandExecutor prepareExecutorMock(Function<Command, Response>... handlers) {
63+
public static CommandExecutor prepareExecutorMock(Function<Command, Response>... handlers) {
6464
CommandExecutor executor = mock(CommandExecutor.class);
6565
try {
6666
OngoingStubbing<Response> callChain = when(executor.execute(any()));

0 commit comments

Comments
 (0)