Skip to content

[java] Replacing some deprecated methods #15443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions java/src/org/openqa/selenium/grid/config/DescribedOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,9 +97,12 @@ private static Stream<DescribedOption> 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) {
Expand Down
30 changes: 24 additions & 6 deletions java/src/org/openqa/selenium/grid/graphql/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +30,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;

class Types {

Expand All @@ -39,7 +43,8 @@ private static GraphQLScalarType uriType() {
.coercing(
new Coercing<URI, String>() {
@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;
}
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -98,7 +109,8 @@ private static GraphQLScalarType urlType() {
.coercing(
new Coercing<URL, String>() {
@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;
}
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,14 +126,17 @@ private static Collection<SessionFactory> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private ProxyFactory(Class<? extends T> clazz) {
public T newInstance(Decorated<T> target) {
T instance;
try {
instance = (T) clazz.newInstance();
instance = clazz.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw new AssertionError("Unable to create new proxy", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,7 +138,7 @@ private class SlowLoadingElement extends SlowLoadableComponent<SlowLoadingElemen
private WebElement element;

public SlowLoadingElement(Clock clock, int timeOutInSeconds) {
super(clock, timeOutInSeconds);
super(clock, Duration.ofSeconds(timeOutInSeconds));
}

@Override
Expand Down Expand Up @@ -178,7 +179,7 @@ private class SlowLoadingElementList extends SlowLoadableComponent<SlowLoadingEl
private List<WebElement> elements;

public SlowLoadingElementList(Clock clock, int timeOutInSeconds) {
super(clock, timeOutInSeconds);
super(clock, Duration.ofSeconds(timeOutInSeconds));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/remote/RemoteLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RemoteLogsTest {

@BeforeEach
public void createMocksAndRemoteLogs() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
remoteLogs = new RemoteLogs(executeMethod, localLogs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ExpectedConditionsTest {

@BeforeEach
public void setUpMocks() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);

wait =
new FluentWait<>(mockDriver, mockClock, mockSleeper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FluentWaitTest {

@BeforeEach
public void createMocks() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testShouldCancelLoadingIfAnErrorIsDetected() {
private static class DetonatingSlowLoader extends SlowLoadableComponent<DetonatingSlowLoader> {

public DetonatingSlowLoader() {
super(Clock.systemDefaultZone(), 1);
super(Clock.systemDefaultZone(), Duration.ofSeconds(1L));
}

@Override
Expand All @@ -82,7 +82,7 @@ private static class SlowLoading extends SlowLoadableComponent<SlowLoading> {
private long loopCount;

public SlowLoading(Clock clock, int timeOutInSeconds, int counts) {
super(clock, timeOutInSeconds);
super(clock, Duration.ofSeconds(timeOutInSeconds));
this.counts = counts;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ private static class BasicSlowLoader extends SlowLoadableComponent<BasicSlowLoad
private final TickingClock clock;

public BasicSlowLoader(TickingClock clock, int timeOutInSeconds) {
super(clock, timeOutInSeconds);
super(clock, Duration.ofSeconds(timeOutInSeconds));
this.clock = clock;
}

Expand All @@ -148,7 +148,7 @@ protected void isLoaded() throws Error {
private static class HasError extends SlowLoadableComponent<HasError> {

public HasError() {
super(new TickingClock(), 1000);
super(new TickingClock(), Duration.ofSeconds(1000L));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WebDriverWaitTest {

@BeforeEach
public void createMocks() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading