Skip to content

Commit b905412

Browse files
[java] Replacing some deprecated methods
In several locations I've removed some minor deprecated code and used the the recommended replacements.
1 parent dbf3dae commit b905412

File tree

13 files changed

+32
-24
lines changed

13 files changed

+32
-24
lines changed

java/src/org/openqa/selenium/grid/config/DescribedOption.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.collect.Sets;
2727
import com.google.common.primitives.Primitives;
2828
import java.lang.reflect.Field;
29+
import java.lang.reflect.InvocationTargetException;
2930
import java.lang.reflect.ParameterizedType;
3031
import java.lang.reflect.Type;
3132
import java.util.Arrays;
@@ -96,9 +97,9 @@ private static Stream<DescribedOption> getAllFields(HasRoles hasRoles) {
9697
ConfigValue configValue = field.getAnnotation(ConfigValue.class);
9798
String fieldValue = "";
9899
try {
99-
Object fieldInstance = field.get(clazz.newInstance());
100+
Object fieldInstance = field.get(clazz.getDeclaredConstructor().newInstance());
100101
fieldValue = fieldInstance == null ? "" : fieldInstance.toString();
101-
} catch (IllegalAccessException | InstantiationException ignore) {
102+
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ignore) {
102103
// We'll swallow this exception since we are just trying to get field's default value
103104
}
104105
if (param != null && configValue != null) {

java/src/org/openqa/selenium/grid/graphql/Types.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
package org.openqa.selenium.grid.graphql;
1919

20+
import graphql.GraphQLContext;
21+
import graphql.execution.CoercedVariables;
2022
import graphql.language.StringValue;
23+
import graphql.language.Value;
2124
import graphql.schema.Coercing;
2225
import graphql.schema.CoercingParseLiteralException;
2326
import graphql.schema.CoercingParseValueException;
@@ -27,6 +30,7 @@
2730
import java.net.URI;
2831
import java.net.URISyntaxException;
2932
import java.net.URL;
33+
import java.util.Locale;
3034

3135
class Types {
3236

@@ -39,7 +43,7 @@ private static GraphQLScalarType uriType() {
3943
.coercing(
4044
new Coercing<URI, String>() {
4145
@Override
42-
public String serialize(Object o) throws CoercingSerializeException {
46+
public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) throws CoercingSerializeException {
4347
if (o instanceof String) {
4448
return (String) o;
4549
}
@@ -52,7 +56,7 @@ public String serialize(Object o) throws CoercingSerializeException {
5256
}
5357

5458
@Override
55-
public URI parseValue(Object input) throws CoercingParseValueException {
59+
public URI parseValue(Object input, GraphQLContext graphQLContext, Locale locale) throws CoercingParseValueException {
5660
if (input == null) {
5761
return null;
5862
}
@@ -77,7 +81,7 @@ public URI parseValue(Object input) throws CoercingParseValueException {
7781
}
7882

7983
@Override
80-
public URI parseLiteral(Object input) throws CoercingParseLiteralException {
84+
public URI parseLiteral(Value<?> input, CoercedVariables variables, GraphQLContext graphQLContext, Locale locale) throws CoercingParseLiteralException {
8185
if (!(input instanceof StringValue)) {
8286
throw new CoercingParseLiteralException("Cannot convert to URL: " + input);
8387
}
@@ -98,7 +102,7 @@ private static GraphQLScalarType urlType() {
98102
.coercing(
99103
new Coercing<URL, String>() {
100104
@Override
101-
public String serialize(Object o) throws CoercingSerializeException {
105+
public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) throws CoercingSerializeException {
102106
if (o instanceof String) {
103107
return (String) o;
104108
}
@@ -111,7 +115,7 @@ public String serialize(Object o) throws CoercingSerializeException {
111115
}
112116

113117
@Override
114-
public URL parseValue(Object input) throws CoercingParseValueException {
118+
public URL parseValue(Object input, GraphQLContext graphQLContext, Locale locale) throws CoercingParseValueException {
115119
if (input == null) {
116120
return null;
117121
}
@@ -136,7 +140,7 @@ public URL parseValue(Object input) throws CoercingParseValueException {
136140
}
137141

138142
@Override
139-
public URL parseLiteral(Object input) throws CoercingParseLiteralException {
143+
public URL parseLiteral(Value<?> input, CoercedVariables variables, GraphQLContext graphQLContext, Locale locale) throws CoercingParseLiteralException {
140144
if (!(input instanceof StringValue)) {
141145
throw new CoercingParseLiteralException("Cannot convert to URL: " + input);
142146
}

java/src/org/openqa/selenium/grid/log/TerseFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public synchronized String format(final LogRecord record) {
9595
return buffer.toString();
9696
}
9797

98-
private String levelNumberToCommonsLevelName(Level level) {
98+
private static String levelNumberToCommonsLevelName(Level level) {
9999
switch (level.intValue()) {
100100
case FINE:
101101
return "DEBUG";

java/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121
import java.io.File;
22+
import java.lang.reflect.InvocationTargetException;
2223
import java.time.Duration;
2324
import java.util.ArrayList;
2425
import java.util.Collection;
@@ -125,14 +126,14 @@ private static Collection<SessionFactory> createSessionFactory(
125126
// We do this to give each Node slot its own instance of the DriverService.Builder.
126127
// This is important because the Node processes many new session requests
127128
// and the DriverService creation needs to be thread safe.
128-
Object driverBuilder = clazz.newInstance();
129+
Object driverBuilder = clazz.getDeclaredConstructor().newInstance();
129130
driverServiceBuilder =
130131
((DriverService.Builder<?, ?>) driverBuilder).usingAnyFreePort();
131132
if (!webDriverExecutablePath.isEmpty()) {
132133
driverServiceBuilder =
133134
driverServiceBuilder.usingDriverExecutable(new File(webDriverExecutablePath));
134135
}
135-
} catch (InstantiationException | IllegalAccessException e) {
136+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
136137
throw new IllegalArgumentException(
137138
String.format("Class %s could not be found or instantiated", clazz));
138139
}

java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private ProxyFactory(Class<? extends T> clazz) {
233233
public T newInstance(Decorated<T> target) {
234234
T instance;
235235
try {
236-
instance = (T) clazz.newInstance();
236+
instance = clazz.getDeclaredConstructor().newInstance();
237237
} catch (ReflectiveOperationException e) {
238238
throw new AssertionError("Unable to create new proxy", e);
239239
}

java/src/org/openqa/selenium/support/pagefactory/AjaxElementLocator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.lang.reflect.Field;
2121
import java.time.Clock;
22+
import java.time.Duration;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425
import org.openqa.selenium.NoSuchElementException;
@@ -137,7 +138,7 @@ private class SlowLoadingElement extends SlowLoadableComponent<SlowLoadingElemen
137138
private WebElement element;
138139

139140
public SlowLoadingElement(Clock clock, int timeOutInSeconds) {
140-
super(clock, timeOutInSeconds);
141+
super(clock, Duration.ofSeconds(timeOutInSeconds));
141142
}
142143

143144
@Override
@@ -178,7 +179,7 @@ private class SlowLoadingElementList extends SlowLoadableComponent<SlowLoadingEl
178179
private List<WebElement> elements;
179180

180181
public SlowLoadingElementList(Clock clock, int timeOutInSeconds) {
181-
super(clock, timeOutInSeconds);
182+
super(clock, Duration.ofSeconds(timeOutInSeconds));
182183
}
183184

184185
@Override

java/test/org/openqa/selenium/remote/RemoteLogsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RemoteLogsTest {
5050

5151
@BeforeEach
5252
public void createMocksAndRemoteLogs() {
53-
MockitoAnnotations.initMocks(this);
53+
MockitoAnnotations.openMocks(this);
5454
remoteLogs = new RemoteLogs(executeMethod, localLogs);
5555
}
5656

java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TracedCommandExecutorTest {
4747

4848
@BeforeEach
4949
public void createMocksAndTracedCommandExecutor() {
50-
MockitoAnnotations.initMocks(this);
50+
MockitoAnnotations.openMocks(this);
5151
when(tracer.getCurrentContext()).thenReturn(traceContext);
5252
when(traceContext.createSpan(anyString())).thenReturn(span);
5353
tracedCommandExecutor = new TracedCommandExecutor(commandExecutor, tracer);

java/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ExpectedConditionsTest {
8989

9090
@BeforeEach
9191
public void setUpMocks() {
92-
MockitoAnnotations.initMocks(this);
92+
MockitoAnnotations.openMocks(this);
9393

9494
wait =
9595
new FluentWait<>(mockDriver, mockClock, mockSleeper)

java/test/org/openqa/selenium/support/ui/FluentWaitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FluentWaitTest {
4949

5050
@BeforeEach
5151
public void createMocks() {
52-
MockitoAnnotations.initMocks(this);
52+
MockitoAnnotations.openMocks(this);
5353
}
5454

5555
@Test

0 commit comments

Comments
 (0)