Skip to content

Commit 988eb75

Browse files
committed
[java] Fixing Java 8 incompatibilities
1 parent 08a90a0 commit 988eb75

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

java/client/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void shouldBeAbleToFindElementsAboveAnother() {
4040
List<WebElement> elements = driver.findElements(withTagName("p").above(lowest));
4141
List<String> ids = elements.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
4242

43-
assertThat(ids).isEqualTo(List.of("mid", "above"));
43+
assertThat(ids).containsExactly("mid", "above");
4444
}
4545

4646
@Test
@@ -50,7 +50,7 @@ public void shouldBeAbleToCombineFilters() {
5050
List<WebElement> seen = driver.findElements(withTagName("td").above(By.id("center")).toRightOf(By.id("second")));
5151

5252
List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
53-
assertThat(ids).isEqualTo(singletonList("third"));
53+
assertThat(ids).containsExactly("third");
5454
}
5555

5656
@Test
@@ -69,6 +69,6 @@ public void exerciseNearLocator() {
6969
// 5-8. Diagonally close (pythagorus sorting, with top row first
7070
// because of DOM insertion order)
7171
List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
72-
assertThat(ids).isEqualTo(List.of("second", "eighth", "fourth", "sixth", "first", "third", "seventh", "ninth"));
72+
assertThat(ids).containsExactly("second", "eighth", "fourth", "sixth", "first", "third", "seventh", "ninth");
7373
}
7474
}

java/server/test/org/openqa/selenium/grid/node/CustomLocatorHandlerTest.java

+27-18
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,23 @@
5252
import java.time.Instant;
5353
import java.util.List;
5454
import java.util.Map;
55-
import java.util.Set;
5655
import java.util.UUID;
5756

5857
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
58+
import static java.util.Collections.emptyList;
59+
import static java.util.Collections.emptySet;
60+
import static java.util.Collections.singleton;
61+
import static java.util.Collections.singletonList;
62+
import static java.util.Collections.singletonMap;
5963
import static org.assertj.core.api.Assertions.assertThat;
6064
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6165
import static org.mockito.ArgumentMatchers.argThat;
6266
import static org.mockito.Mockito.when;
6367
import static org.openqa.selenium.json.Json.MAP_TYPE;
6468
import static org.openqa.selenium.remote.http.HttpMethod.POST;
6569

70+
import com.google.common.collect.ImmutableMap;
71+
6672
public class CustomLocatorHandlerTest {
6773

6874
private final Secret registrationSecret = new Secret("cheese");
@@ -85,11 +91,12 @@ public void partiallyBuildNode() {
8591
public void shouldRequireInputToHaveAUsingParameter() {
8692
Node node = nodeBuilder.build();
8793

88-
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(node, registrationSecret, Set.of());
94+
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(
95+
node, registrationSecret, emptySet());
8996

9097
HttpResponse res = handler.execute(
9198
new HttpRequest(POST, "/session/1234/element")
92-
.setContent(Contents.asJson(Map.of("value", "1234"))));
99+
.setContent(Contents.asJson(singletonMap("value", "1234"))));
93100

94101
assertThat(res.getStatus()).isEqualTo(HTTP_BAD_REQUEST);
95102
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(() -> Values.get(res, MAP_TYPE));
@@ -99,11 +106,12 @@ public void shouldRequireInputToHaveAUsingParameter() {
99106
public void shouldRequireInputToHaveAValueParameter() {
100107
Node node = nodeBuilder.build();
101108

102-
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(node, registrationSecret, Set.of());
109+
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(
110+
node, registrationSecret, emptySet());
103111

104112
HttpResponse res = handler.execute(
105113
new HttpRequest(POST, "/session/1234/element")
106-
.setContent(Contents.asJson(Map.of("using", "magic"))));
114+
.setContent(Contents.asJson(singletonMap("using", "magic"))));
107115

108116
assertThat(res.getStatus()).isEqualTo(HTTP_BAD_REQUEST);
109117
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(() -> Values.get(res, MAP_TYPE));
@@ -113,11 +121,12 @@ public void shouldRequireInputToHaveAValueParameter() {
113121
public void shouldRejectRequestWithAnUnknownLocatorMechanism() {
114122
Node node = nodeBuilder.build();
115123

116-
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(node, registrationSecret, Set.of());
124+
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(
125+
node, registrationSecret, emptySet());
117126

118127
HttpResponse res = handler.execute(
119128
new HttpRequest(POST, "/session/1234/element")
120-
.setContent(Contents.asJson(Map.of(
129+
.setContent(Contents.asJson(ImmutableMap.of(
121130
"using", "cheese",
122131
"value", "tasty"))));
123132

@@ -136,7 +145,7 @@ public void shouldCallTheGivenLocatorForALocator() {
136145
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(
137146
node,
138147
registrationSecret,
139-
Set.of(new CustomLocator() {
148+
singleton(new CustomLocator() {
140149
@Override
141150
public String getLocatorName() {
142151
return "cheese";
@@ -147,15 +156,15 @@ public By createBy(Object usingParameter) {
147156
return new By() {
148157
@Override
149158
public List<WebElement> findElements(SearchContext context) {
150-
return List.of();
159+
return emptyList();
151160
}
152161
};
153162
}
154163
}));
155164

156165
HttpResponse res = handler.with(new ErrorFilter()).execute(
157166
new HttpRequest(POST, "/session/1234/element")
158-
.setContent(Contents.asJson(Map.of(
167+
.setContent(Contents.asJson(ImmutableMap.of(
159168
"using", "cheese",
160169
"value", "tasty"))));
161170

@@ -171,13 +180,13 @@ public void shouldBeAbleToUseNodeAsWebDriver() {
171180
.thenReturn(
172181
new HttpResponse()
173182
.addHeader("Content-Type", Json.JSON_UTF_8)
174-
.setContent(Contents.asJson(Map.of(
175-
"value", List.of(Map.of(Dialect.W3C.getEncodedElementKey(), elementId))))));
183+
.setContent(Contents.asJson(singletonMap(
184+
"value", singletonList(singletonMap(Dialect.W3C.getEncodedElementKey(), elementId))))));
176185

177186
HttpHandler handler = new org.openqa.selenium.grid.node.CustomLocatorHandler(
178187
node,
179188
registrationSecret,
180-
Set.of(new CustomLocator() {
189+
singleton(new CustomLocator() {
181190
@Override
182191
public String getLocatorName() {
183192
return "cheese";
@@ -191,7 +200,7 @@ public By createBy(Object usingParameter) {
191200

192201
HttpResponse res = handler.execute(
193202
new HttpRequest(POST, "/session/1234/elements")
194-
.setContent(Contents.asJson(Map.of(
203+
.setContent(Contents.asJson(ImmutableMap.of(
195204
"using", "cheese",
196205
"value", "tasty"))));
197206

@@ -210,13 +219,13 @@ public void shouldBeAbleToRootASearchWithinAnElement() {
210219
.thenReturn(
211220
new HttpResponse()
212221
.addHeader("Content-Type", Json.JSON_UTF_8)
213-
.setContent(Contents.asJson(Map.of(
214-
"value", List.of(Map.of(Dialect.W3C.getEncodedElementKey(), elementId))))));
222+
.setContent(Contents.asJson(singletonMap(
223+
"value", singletonList(singletonMap(Dialect.W3C.getEncodedElementKey(), elementId))))));
215224

216225
HttpHandler handler = new CustomLocatorHandler(
217226
node,
218227
registrationSecret,
219-
Set.of(new CustomLocator() {
228+
singleton(new CustomLocator() {
220229
@Override
221230
public String getLocatorName() {
222231
return "cheese";
@@ -230,7 +239,7 @@ public By createBy(Object usingParameter) {
230239

231240
HttpResponse res = handler.execute(
232241
new HttpRequest(POST, "/session/1234/element/234345/elements")
233-
.setContent(Contents.asJson(Map.of(
242+
.setContent(Contents.asJson(ImmutableMap.of(
234243
"using", "cheese",
235244
"value", "tasty"))));
236245

0 commit comments

Comments
 (0)