diff --git a/java/src/org/openqa/selenium/grid/config/DescribedOption.java b/java/src/org/openqa/selenium/grid/config/DescribedOption.java index 3e5aa4e25b133..e3378923ea639 100644 --- a/java/src/org/openqa/selenium/grid/config/DescribedOption.java +++ b/java/src/org/openqa/selenium/grid/config/DescribedOption.java @@ -26,6 +26,7 @@ import com.google.common.collect.Sets; import com.google.common.primitives.Primitives; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; @@ -96,9 +97,12 @@ private static Stream getAllFields(HasRoles hasRoles) { ConfigValue configValue = field.getAnnotation(ConfigValue.class); String fieldValue = ""; try { - Object fieldInstance = field.get(clazz.newInstance()); + Object fieldInstance = field.get(clazz.getDeclaredConstructor().newInstance()); fieldValue = fieldInstance == null ? "" : fieldInstance.toString(); - } catch (IllegalAccessException | InstantiationException ignore) { + } catch (IllegalAccessException + | InstantiationException + | InvocationTargetException + | NoSuchMethodException ignore) { // We'll swallow this exception since we are just trying to get field's default value } if (param != null && configValue != null) { diff --git a/java/src/org/openqa/selenium/grid/graphql/Types.java b/java/src/org/openqa/selenium/grid/graphql/Types.java index 5bb2a21fa2b1a..8e0b0fd97bb1f 100644 --- a/java/src/org/openqa/selenium/grid/graphql/Types.java +++ b/java/src/org/openqa/selenium/grid/graphql/Types.java @@ -17,7 +17,10 @@ package org.openqa.selenium.grid.graphql; +import graphql.GraphQLContext; +import graphql.execution.CoercedVariables; import graphql.language.StringValue; +import graphql.language.Value; import graphql.schema.Coercing; import graphql.schema.CoercingParseLiteralException; import graphql.schema.CoercingParseValueException; @@ -27,6 +30,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.Locale; class Types { @@ -39,7 +43,8 @@ private static GraphQLScalarType uriType() { .coercing( new Coercing() { @Override - public String serialize(Object o) throws CoercingSerializeException { + public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) + throws CoercingSerializeException { if (o instanceof String) { return (String) o; } @@ -52,7 +57,8 @@ public String serialize(Object o) throws CoercingSerializeException { } @Override - public URI parseValue(Object input) throws CoercingParseValueException { + public URI parseValue(Object input, GraphQLContext graphQLContext, Locale locale) + throws CoercingParseValueException { if (input == null) { return null; } @@ -77,7 +83,12 @@ public URI parseValue(Object input) throws CoercingParseValueException { } @Override - public URI parseLiteral(Object input) throws CoercingParseLiteralException { + public URI parseLiteral( + Value input, + CoercedVariables variables, + GraphQLContext graphQLContext, + Locale locale) + throws CoercingParseLiteralException { if (!(input instanceof StringValue)) { throw new CoercingParseLiteralException("Cannot convert to URL: " + input); } @@ -98,7 +109,8 @@ private static GraphQLScalarType urlType() { .coercing( new Coercing() { @Override - public String serialize(Object o) throws CoercingSerializeException { + public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) + throws CoercingSerializeException { if (o instanceof String) { return (String) o; } @@ -111,7 +123,8 @@ public String serialize(Object o) throws CoercingSerializeException { } @Override - public URL parseValue(Object input) throws CoercingParseValueException { + public URL parseValue(Object input, GraphQLContext graphQLContext, Locale locale) + throws CoercingParseValueException { if (input == null) { return null; } @@ -136,7 +149,12 @@ public URL parseValue(Object input) throws CoercingParseValueException { } @Override - public URL parseLiteral(Object input) throws CoercingParseLiteralException { + public URL parseLiteral( + Value input, + CoercedVariables variables, + GraphQLContext graphQLContext, + Locale locale) + throws CoercingParseLiteralException { if (!(input instanceof StringValue)) { throw new CoercingParseLiteralException("Cannot convert to URL: " + input); } diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java b/java/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java index 600f516b02992..67605a9f3d762 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.time.Duration; import java.util.ArrayList; import java.util.Collection; @@ -125,14 +126,17 @@ private static Collection createSessionFactory( // We do this to give each Node slot its own instance of the DriverService.Builder. // This is important because the Node processes many new session requests // and the DriverService creation needs to be thread safe. - Object driverBuilder = clazz.newInstance(); + Object driverBuilder = clazz.getDeclaredConstructor().newInstance(); driverServiceBuilder = ((DriverService.Builder) driverBuilder).usingAnyFreePort(); if (!webDriverExecutablePath.isEmpty()) { driverServiceBuilder = driverServiceBuilder.usingDriverExecutable(new File(webDriverExecutablePath)); } - } catch (InstantiationException | IllegalAccessException e) { + } catch (InstantiationException + | IllegalAccessException + | InvocationTargetException + | NoSuchMethodException e) { throw new IllegalArgumentException( String.format("Class %s could not be found or instantiated", clazz)); } diff --git a/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java b/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java index f500774138277..52213273c4353 100644 --- a/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java +++ b/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java @@ -233,7 +233,7 @@ private ProxyFactory(Class clazz) { public T newInstance(Decorated target) { T instance; try { - instance = (T) clazz.newInstance(); + instance = clazz.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new AssertionError("Unable to create new proxy", e); } diff --git a/java/src/org/openqa/selenium/support/pagefactory/AjaxElementLocator.java b/java/src/org/openqa/selenium/support/pagefactory/AjaxElementLocator.java index 3cbd1090d5115..74a1e62d7bf7f 100644 --- a/java/src/org/openqa/selenium/support/pagefactory/AjaxElementLocator.java +++ b/java/src/org/openqa/selenium/support/pagefactory/AjaxElementLocator.java @@ -19,6 +19,7 @@ import java.lang.reflect.Field; import java.time.Clock; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import org.openqa.selenium.NoSuchElementException; @@ -137,7 +138,7 @@ private class SlowLoadingElement extends SlowLoadableComponent elements; public SlowLoadingElementList(Clock clock, int timeOutInSeconds) { - super(clock, timeOutInSeconds); + super(clock, Duration.ofSeconds(timeOutInSeconds)); } @Override diff --git a/java/test/org/openqa/selenium/remote/RemoteLogsTest.java b/java/test/org/openqa/selenium/remote/RemoteLogsTest.java index d0fed2661fc30..c3e07c7fadda9 100644 --- a/java/test/org/openqa/selenium/remote/RemoteLogsTest.java +++ b/java/test/org/openqa/selenium/remote/RemoteLogsTest.java @@ -50,7 +50,7 @@ class RemoteLogsTest { @BeforeEach public void createMocksAndRemoteLogs() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); remoteLogs = new RemoteLogs(executeMethod, localLogs); } diff --git a/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java b/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java index 6a7aa226826f4..8588f15abcc57 100644 --- a/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java +++ b/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java @@ -47,7 +47,7 @@ class TracedCommandExecutorTest { @BeforeEach public void createMocksAndTracedCommandExecutor() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); when(tracer.getCurrentContext()).thenReturn(traceContext); when(traceContext.createSpan(anyString())).thenReturn(span); tracedCommandExecutor = new TracedCommandExecutor(commandExecutor, tracer); diff --git a/java/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java b/java/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java index d7cccb7616a38..7729f0db751c7 100644 --- a/java/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java +++ b/java/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java @@ -89,7 +89,7 @@ class ExpectedConditionsTest { @BeforeEach public void setUpMocks() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); wait = new FluentWait<>(mockDriver, mockClock, mockSleeper) diff --git a/java/test/org/openqa/selenium/support/ui/FluentWaitTest.java b/java/test/org/openqa/selenium/support/ui/FluentWaitTest.java index 1d2129f5366da..0a4fdbdfa3b25 100644 --- a/java/test/org/openqa/selenium/support/ui/FluentWaitTest.java +++ b/java/test/org/openqa/selenium/support/ui/FluentWaitTest.java @@ -49,7 +49,7 @@ class FluentWaitTest { @BeforeEach public void createMocks() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/java/test/org/openqa/selenium/support/ui/SlowLoadableComponentTest.java b/java/test/org/openqa/selenium/support/ui/SlowLoadableComponentTest.java index c14b676c35f62..5052ac680ff65 100644 --- a/java/test/org/openqa/selenium/support/ui/SlowLoadableComponentTest.java +++ b/java/test/org/openqa/selenium/support/ui/SlowLoadableComponentTest.java @@ -62,7 +62,7 @@ void testShouldCancelLoadingIfAnErrorIsDetected() { private static class DetonatingSlowLoader extends SlowLoadableComponent { public DetonatingSlowLoader() { - super(Clock.systemDefaultZone(), 1); + super(Clock.systemDefaultZone(), Duration.ofSeconds(1L)); } @Override @@ -82,7 +82,7 @@ private static class SlowLoading extends SlowLoadableComponent { private long loopCount; public SlowLoading(Clock clock, int timeOutInSeconds, int counts) { - super(clock, timeOutInSeconds); + super(clock, Duration.ofSeconds(timeOutInSeconds)); this.counts = counts; } @@ -127,7 +127,7 @@ private static class BasicSlowLoader extends SlowLoadableComponent { public HasError() { - super(new TickingClock(), 1000); + super(new TickingClock(), Duration.ofSeconds(1000L)); } @Override diff --git a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java index 50d396b049702..eebe7dfe4a300 100644 --- a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java +++ b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java @@ -55,7 +55,7 @@ class WebDriverWaitTest { @BeforeEach public void createMocks() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java b/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java index b7759733956f9..bd8eef33a56a3 100644 --- a/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java +++ b/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java @@ -29,6 +29,7 @@ import java.util.Base64; import java.util.List; import java.util.Map; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -239,7 +240,10 @@ void testAddResidentCredential() { "getCredential([]).then(arguments[arguments.length - 1]);"); assertThat(response).asInstanceOf(MAP).containsEntry("status", "OK"); - assertThat(response).extracting("attestation.userHandle").asList().containsExactly(1L); + assertThat(response) + .extracting("attestation.userHandle") + .asInstanceOf(InstanceOfAssertFactories.LIST) + .containsExactly(1L); } @Test