Skip to content

Commit ef640c3

Browse files
committed
use better AssertJ assertion for Optionals and AtomicIntegers
`assertThat(X.get()).isEqualTo(2)` -> `assertThat(X).hasValue(2)`
1 parent 30ee0e7 commit ef640c3

19 files changed

+57
-63
lines changed

java/test/org/openqa/selenium/WebScriptExecuteTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void canExecuteScriptWithMinusZeroArgument() {
8585
"-0");
8686

8787
assertThat(value.getType()).isEqualTo("number");
88-
assertThat(value.getValue().get()).isEqualTo("-0");
88+
assertThat(value.getValue()).hasValue("-0");
8989
}
9090

9191
@Test
@@ -103,7 +103,7 @@ void canExecuteScriptWithInfinityArgument() {
103103
"Infinity");
104104

105105
assertThat(value.getType()).isEqualTo("number");
106-
assertThat(value.getValue().get()).isEqualTo("Infinity");
106+
assertThat(value.getValue()).hasValue("Infinity");
107107
}
108108

109109
@Test
@@ -121,7 +121,7 @@ void canExecuteScriptWithMinusInfinityArgument() {
121121
"-Infinity");
122122

123123
assertThat(value.getType()).isEqualTo("number");
124-
assertThat(value.getValue().get()).isEqualTo("-Infinity");
124+
assertThat(value.getValue()).hasValue("-Infinity");
125125
}
126126

127127
@Test
@@ -138,7 +138,7 @@ void canExecuteScriptWithNumberArgument() {
138138
1.4);
139139

140140
assertThat(value.getType()).isEqualTo("number");
141-
assertThat(value.getValue().get()).isEqualTo(1.4);
141+
assertThat(value.getValue()).hasValue(1.4);
142142
}
143143

144144
@Test
@@ -155,7 +155,7 @@ void canExecuteScriptWithIntegerArgument() {
155155
1);
156156

157157
assertThat(value.getType()).isEqualTo("number");
158-
assertThat(value.getValue().get()).isEqualTo(1L);
158+
assertThat(value.getValue()).hasValue(1L);
159159
}
160160

161161
@Test
@@ -172,7 +172,7 @@ void canExecuteScriptWithBooleanArgument() {
172172
true);
173173

174174
assertThat(value.getType()).isEqualTo("boolean");
175-
assertThat(value.getValue().get()).isEqualTo(true);
175+
assertThat(value.getValue()).hasValue(true);
176176
}
177177

178178
@Test
@@ -189,7 +189,7 @@ void canExecuteScriptWithBigIntArgument() {
189189
BigInteger.valueOf(42L));
190190

191191
assertThat(value.getType()).isEqualTo("bigint");
192-
assertThat(value.getValue().get()).isEqualTo("42");
192+
assertThat(value.getValue()).hasValue("42");
193193
}
194194

195195
@Test

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void canListenToUserPromptClosedEvent()
213213
UserPromptClosed userPromptClosed = future.get(5, TimeUnit.SECONDS);
214214
assertThat(userPromptClosed.getBrowsingContextId()).isEqualTo(context.getId());
215215
assertThat(userPromptClosed.getUserText().isPresent()).isTrue();
216-
assertThat(userPromptClosed.getUserText().get()).isEqualTo("selenium");
216+
assertThat(userPromptClosed.getUserText()).hasValue("selenium");
217217
assertThat(userPromptClosed.getAccepted()).isTrue();
218218
}
219219
}

java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void canLocateNodesWithCSSLocator() {
9494
assertThat(value.getType()).isEqualTo("node");
9595
assertThat(value.getValue().isPresent()).isTrue();
9696
NodeProperties properties = (NodeProperties) value.getValue().get();
97-
assertThat(properties.getLocalName().get()).isEqualTo("div");
97+
assertThat(properties.getLocalName()).hasValue("div");
9898
assertThat(properties.getAttributes().get()).hasSize(1);
9999
assertThat(properties.getAttributes().get().get("class")).isEqualTo("content");
100100
}
@@ -117,7 +117,7 @@ void canLocateNodesWithXPathLocator() {
117117
assertThat(value.getType()).isEqualTo("node");
118118
assertThat(value.getValue().isPresent()).isTrue();
119119
NodeProperties properties = (NodeProperties) value.getValue().get();
120-
assertThat(properties.getLocalName().get()).isEqualTo("div");
120+
assertThat(properties.getLocalName()).hasValue("div");
121121
assertThat(properties.getAttributes().get()).hasSize(1);
122122
assertThat(properties.getAttributes().get().get("class")).isEqualTo("content");
123123
}

java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void canCancelAuth() throws InterruptedException {
274274
}
275275

276276
latch.await(10, TimeUnit.SECONDS);
277-
assertThat(status.get()).isEqualTo(401);
277+
assertThat(status).hasValue(401);
278278
}
279279
}
280280

java/test/org/openqa/selenium/bidi/script/LocalValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void canCallFunctionWithDateArgument() {
392392
EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
393393
assertThat(successResult.getResult().getType()).isEqualTo("date");
394394
assertThat(successResult.getResult().getValue().isPresent()).isTrue();
395-
assertThat(successResult.getResult().getValue().get()).isEqualTo("2022-05-31T13:47:29.000Z");
395+
assertThat(successResult.getResult().getValue()).hasValue("2022-05-31T13:47:29.000Z");
396396
}
397397

398398
@Test

java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ void canAddPreloadScriptInASandbox() {
826826
script.evaluateFunctionInBrowsingContext(
827827
driver.getWindowHandle(), "sandbox", "window.bar", true, Optional.empty());
828828
assertThat(result.getResultType()).isEqualTo(EvaluateResult.Type.SUCCESS);
829-
assertThat(((EvaluateResultSuccess) result).getResult().getValue().get()).isEqualTo(2L);
829+
assertThat(((EvaluateResultSuccess) result).getResult().getValue()).hasValue(2L);
830830
}
831831

832832
@Test
@@ -843,7 +843,7 @@ void canRemovePreloadedScript() {
843843
script.evaluateFunctionInBrowsingContext(
844844
driver.getWindowHandle(), "window.bar", true, Optional.empty());
845845
assertThat(result.getResultType()).isEqualTo(EvaluateResult.Type.SUCCESS);
846-
assertThat(((EvaluateResultSuccess) result).getResult().getValue().get()).isEqualTo(2L);
846+
assertThat(((EvaluateResultSuccess) result).getResult().getValue()).hasValue(2L);
847847

848848
script.removePreloadScript(id);
849849

java/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ void canListenToChannelMessage()
5757
assertThat(message.getChannel()).isEqualTo("channel_name");
5858
assertThat(message.getData().getType()).isEqualTo("string");
5959
assertThat(message.getData().getValue().isPresent()).isTrue();
60-
assertThat(message.getData().getValue().get()).isEqualTo("foo");
60+
assertThat(message.getData().getValue()).hasValue("foo");
6161
assertThat(message.getSource().getRealm()).isNotNull();
6262
assertThat(message.getSource().getBrowsingContext().isPresent()).isTrue();
63-
assertThat(message.getSource().getBrowsingContext().get())
64-
.isEqualTo(driver.getWindowHandle());
63+
assertThat(message.getSource().getBrowsingContext()).hasValue(driver.getWindowHandle());
6564
}
6665
}
6766

java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void canAddAndGetCookie() {
251251
assertThat(resultCookie.isSecure()).isEqualTo(false);
252252
assertThat(resultCookie.getSameSite())
253253
.isEqualTo(org.openqa.selenium.bidi.network.Cookie.SameSite.LAX);
254-
assertThat(resultCookie.getExpiry().get()).isEqualTo(expiry);
254+
assertThat(resultCookie.getExpiry()).hasValue(expiry);
255255
assertThat(key.getSourceOrigin()).isNotNull();
256256
assertThat(key.getUserContext()).isNotNull();
257257
assertThat(key.getUserContext()).isEqualTo("default");

java/test/org/openqa/selenium/concurrent/LazyTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public class LazyTest {
2929

3030
@Test
3131
void trivialCase() {
32-
Lazy expression = Lazy.lazy(() -> "constant");
32+
Lazy<String> expression = Lazy.lazy(() -> "constant");
3333
assertThat(expression.get()).isEqualTo("constant");
3434
assertThat(expression.getIfInitialized()).contains("constant");
3535
}
3636

3737
@Test
3838
void getIfInitialized_returnsNothing_ifNotInitializedYet() {
39-
Lazy expression = Lazy.lazy(() -> "value#" + counter.incrementAndGet());
39+
Lazy<String> expression = Lazy.lazy(() -> "value#" + counter.incrementAndGet());
4040
assertThat(expression.getIfInitialized()).isEmpty();
4141
}
4242

4343
@Test
4444
void lazyEvaluatedExpression() {
45-
Lazy expression = Lazy.lazy(() -> "value#" + counter.incrementAndGet());
45+
Lazy<String> expression = Lazy.lazy(() -> "value#" + counter.incrementAndGet());
4646
assertThat(expression.get()).isEqualTo("value#1");
4747
assertThat(expression.get()).isEqualTo("value#1");
4848
assertThat(expression.getIfInitialized()).contains("value#1");
@@ -51,8 +51,8 @@ void lazyEvaluatedExpression() {
5151

5252
@Test
5353
void differentLazyInstances_produce_differentValues() {
54-
Lazy expression1 = Lazy.lazy(() -> "one#" + counter.incrementAndGet());
55-
Lazy expression2 = Lazy.lazy(() -> "two#" + counter.incrementAndGet());
54+
Lazy<String> expression1 = Lazy.lazy(() -> "one#" + counter.incrementAndGet());
55+
Lazy<String> expression2 = Lazy.lazy(() -> "two#" + counter.incrementAndGet());
5656
assertThat(expression1.get()).isEqualTo("one#1");
5757
assertThat(expression1.getIfInitialized()).contains("one#1");
5858
assertThat(expression2.getIfInitialized()).isEmpty();

java/test/org/openqa/selenium/grid/router/ProxyWebsocketTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void shouldForwardTextMessageToServer(Supplier<String> values)
141141
socket.sendText("Cheese!");
142142

143143
assertThat(latch.await(5, SECONDS)).isTrue();
144-
assertThat(text.get()).isEqualTo("Cheese!");
144+
assertThat(text).hasValue("Cheese!");
145145
}
146146
}
147147

@@ -184,7 +184,7 @@ public void onText(CharSequence data) {
184184
socket.sendText("Cheese!");
185185

186186
assertThat(latch.await(5, SECONDS)).isTrue();
187-
assertThat(text.get()).isEqualTo("Asiago");
187+
assertThat(text).hasValue("Asiago");
188188
}
189189
}
190190

@@ -272,7 +272,7 @@ public void onText(CharSequence data) {
272272
socket.sendText("Cheese!");
273273

274274
assertThat(latch.await(5, SECONDS)).isTrue();
275-
assertThat(text.get()).isEqualTo("Cheddar");
275+
assertThat(text).hasValue("Cheddar");
276276
}
277277

278278
secureProxyServer.stop();

0 commit comments

Comments
 (0)