Skip to content

Commit ec555e9

Browse files
committed
use better AssertJ assertion for collection size
`assertThat($$.size()).isEqualTo(2)` -> `assertThat($$).hasSize(2)`
1 parent 794820d commit ec555e9

26 files changed

+63
-67
lines changed

java/test/org/openqa/selenium/ChildrenFindingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void testFindingElementsOnElementByXPathShouldFindTopLevelElements() {
4242
WebElement parent = driver.findElement(By.id("multiline"));
4343
List<WebElement> allPs = driver.findElements(By.xpath("//p"));
4444
List<WebElement> children = parent.findElements(By.xpath("//p"));
45-
assertThat(allPs.size()).isEqualTo(children.size());
45+
assertThat(allPs).hasSize(children.size());
4646
}
4747

4848
@Test

java/test/org/openqa/selenium/CookieImplementationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void testGetAllCookies() {
119119

120120
openAnotherPage();
121121
cookies = driver.manage().getCookies();
122-
assertThat(cookies.size()).isEqualTo(countBefore + 2);
122+
assertThat(cookies).hasSize(countBefore + 2);
123123

124124
assertThat(cookies.contains(one)).isTrue();
125125
assertThat(cookies.contains(two)).isTrue();

java/test/org/openqa/selenium/ElementFindingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ void testShouldNotBeAbleToLocateByLinkTextMultipleElementsThatDoNotExist() {
708708
void testShouldBeAbleToFindMultipleElementsByPartialLinkText() {
709709
driver.get(pages.xhtmlTestPage);
710710
List<WebElement> elements = driver.findElements(By.partialLinkText("ick me"));
711-
assertThat(elements.size()).isEqualTo(2);
711+
assertThat(elements).hasSize(2);
712712
}
713713

714714
@Test

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void canExecuteScriptWithArrayArgument() {
212212

213213
assertThat(value.getType()).isEqualTo("array");
214214
List<RemoteValue> values = (List<RemoteValue>) value.getValue().get();
215-
assertThat(values.size()).isEqualTo(2);
215+
assertThat(values).hasSize(2);
216216
}
217217

218218
@Test
@@ -235,7 +235,7 @@ void canExecuteScriptWithSetArgument() {
235235

236236
assertThat(value.getType()).isEqualTo("set");
237237
List<RemoteValue> values = (List<RemoteValue>) value.getValue().get();
238-
assertThat(values.size()).isEqualTo(2);
238+
assertThat(values).hasSize(2);
239239
}
240240

241241
@Test
@@ -276,7 +276,7 @@ void canExecuteScriptWithMapArgument() {
276276
assertThat(value.getType()).isEqualTo("map");
277277

278278
Map<Object, RemoteValue> values = (Map<Object, RemoteValue>) value.getValue().get();
279-
assertThat(values.size()).isEqualTo(2);
279+
assertThat(values).hasSize(2);
280280
}
281281

282282
@Test
@@ -299,7 +299,7 @@ void canExecuteScriptWithObjectArgument() {
299299
assertThat(value.getType()).isEqualTo("object");
300300

301301
Map<Object, RemoteValue> values = (Map<Object, RemoteValue>) value.getValue().get();
302-
assertThat(values.size()).isEqualTo(6);
302+
assertThat(values).hasSize(6);
303303
}
304304

305305
@Test

java/test/org/openqa/selenium/WebScriptTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void canAddConsoleMessageHandler()
5656
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
5757

5858
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
59-
assertThat(logEntry.getArgs().size()).isEqualTo(1);
59+
assertThat(logEntry.getArgs()).hasSize(1);
6060
assertThat(logEntry.getArgs().get(0).getType()).isEqualTo("string");
6161
assertThat(logEntry.getType()).isEqualTo("console");
6262
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void canLocateNodes() {
4949
LocateNodeParameters parameters = new LocateNodeParameters(Locator.css("div"));
5050

5151
List<RemoteValue> elements = browsingContext.locateNodes(parameters);
52-
assertThat(elements.size()).isEqualTo(13);
52+
assertThat(elements).hasSize(13);
5353
}
5454

5555
@Test
@@ -61,7 +61,7 @@ void canLocateNodesWithJustLocator() {
6161
driver.get(pages.xhtmlTestPage);
6262

6363
List<RemoteValue> elements = browsingContext.locateNodes(Locator.css("div"));
64-
assertThat(elements.size()).isEqualTo(13);
64+
assertThat(elements).hasSize(13);
6565
}
6666

6767
@Test
@@ -95,7 +95,7 @@ void canLocateNodesWithCSSLocator() {
9595
assertThat(value.getValue().isPresent()).isTrue();
9696
NodeProperties properties = (NodeProperties) value.getValue().get();
9797
assertThat(properties.getLocalName().get()).isEqualTo("div");
98-
assertThat(properties.getAttributes().get().size()).isEqualTo(1);
98+
assertThat(properties.getAttributes().get()).hasSize(1);
9999
assertThat(properties.getAttributes().get().get("class")).isEqualTo("content");
100100
}
101101

@@ -118,7 +118,7 @@ void canLocateNodesWithXPathLocator() {
118118
assertThat(value.getValue().isPresent()).isTrue();
119119
NodeProperties properties = (NodeProperties) value.getValue().get();
120120
assertThat(properties.getLocalName().get()).isEqualTo("div");
121-
assertThat(properties.getAttributes().get().size()).isEqualTo(1);
121+
assertThat(properties.getAttributes().get()).hasSize(1);
122122
assertThat(properties.getAttributes().get().get("class")).isEqualTo("content");
123123
}
124124

@@ -154,7 +154,7 @@ void canLocateNodesWithMaxNodeCount() {
154154
new LocateNodeParameters(Locator.css("div")).setMaxNodeCount(4);
155155

156156
List<RemoteValue> elements = browsingContext.locateNodes(parameters);
157-
assertThat(elements.size()).isEqualTo(4);
157+
assertThat(elements).hasSize(4);
158158
}
159159

160160
@Test
@@ -193,7 +193,7 @@ void canLocateNodesGivenStartNodes() {
193193
.setMaxNodeCount(50);
194194

195195
List<RemoteValue> elements = browsingContext.locateNodes(parameters);
196-
assertThat(elements.size()).isEqualTo(35);
196+
assertThat(elements).hasSize(35);
197197
}
198198

199199
@Test
@@ -209,7 +209,7 @@ void canLocateNodesInAGivenSandbox() {
209209
new LocateNodeParameters(Locator.css("div")).setSandbox(sandbox).setMaxNodeCount(1);
210210

211211
List<RemoteValue> elements = browsingContext.locateNodes(parameters);
212-
assertThat(elements.size()).isEqualTo(1);
212+
assertThat(elements).hasSize(1);
213213

214214
String nodeId = elements.get(0).getSharedId().get();
215215

java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void canListenToConsoleLog() throws ExecutionException, InterruptedException, Ti
5656
assertThat(source.getBrowsingContext().isPresent()).isTrue();
5757
assertThat(source.getRealm()).isNotNull();
5858
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
59-
assertThat(logEntry.getArgs().size()).isEqualTo(1);
59+
assertThat(logEntry.getArgs()).hasSize(1);
6060
assertThat(logEntry.getArgs().get(0).getType()).isEqualTo("string");
6161
assertThat(logEntry.getType()).isEqualTo("console");
6262
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
@@ -78,7 +78,7 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim
7878
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
7979

8080
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
81-
assertThat(logEntry.getArgs().size()).isEqualTo(1);
81+
assertThat(logEntry.getArgs()).hasSize(1);
8282
assertThat(logEntry.getType()).isEqualTo("console");
8383
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
8484
assertThat(logEntry.getMethod()).isEqualTo("log");
@@ -91,12 +91,12 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim
9191
ConsoleLogEntry errorLogEntry = errorLogFuture.get(5, TimeUnit.SECONDS);
9292

9393
assertThat(errorLogEntry.getText()).isEqualTo("I am console error");
94-
assertThat(errorLogEntry.getArgs().size()).isEqualTo(1);
94+
assertThat(errorLogEntry.getArgs()).hasSize(1);
9595
assertThat(errorLogEntry.getType()).isEqualTo("console");
9696
assertThat(errorLogEntry.getLevel()).isEqualTo(LogLevel.ERROR);
9797
assertThat(errorLogEntry.getMethod()).isEqualTo("error");
9898
assertThat(errorLogEntry.getStackTrace()).isNotNull();
99-
assertThat(errorLogEntry.getStackTrace().getCallFrames().size()).isEqualTo(2);
99+
assertThat(errorLogEntry.getStackTrace().getCallFrames()).hasSize(2);
100100
}
101101
}
102102

@@ -207,7 +207,7 @@ void canFilterLogs() throws ExecutionException, InterruptedException, TimeoutExc
207207

208208
ConsoleLogEntry consoleLogEntry = logEntry.getConsoleLogEntry().get();
209209
assertThat(consoleLogEntry.getText()).isEqualTo("Hello, world!");
210-
assertThat(consoleLogEntry.getArgs().size()).isEqualTo(1);
210+
assertThat(consoleLogEntry.getArgs()).hasSize(1);
211211
assertThat(consoleLogEntry.getType()).isEqualTo("console");
212212
assertThat(consoleLogEntry.getLevel()).isEqualTo(LogLevel.INFO);
213213
assertThat(consoleLogEntry.getMethod()).isEqualTo("log");
@@ -232,7 +232,7 @@ void canListenToConsoleLogForABrowsingContext()
232232
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
233233

234234
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
235-
assertThat(logEntry.getArgs().size()).isEqualTo(1);
235+
assertThat(logEntry.getArgs()).hasSize(1);
236236
assertThat(logEntry.getType()).isEqualTo("console");
237237
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
238238
assertThat(logEntry.getMethod()).isEqualTo("log");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void canListenToResponseCompletedEventWithCookie()
117117
BeforeRequestSent requestSent = future.get(5, TimeUnit.SECONDS);
118118
String windowHandle = driver.getWindowHandle();
119119
assertThat(requestSent.getBrowsingContextId()).isEqualTo(windowHandle);
120-
assertThat(requestSent.getRequest().getCookies().size()).isEqualTo(1);
120+
assertThat(requestSent.getRequest().getCookies()).hasSize(1);
121121
assertThat(requestSent.getRequest().getCookies().get(0).getName()).isEqualTo("foo");
122122
assertThat(requestSent.getRequest().getCookies().get(0).getValue().getValue())
123123
.isEqualTo("bar");

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void canCallFunctionWithArguments() {
133133
EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
134134
assertThat(successResult.getResult().getType()).isEqualTo("array");
135135
assertThat(successResult.getResult().getValue().isPresent()).isTrue();
136-
assertThat(((List<Object>) successResult.getResult().getValue().get()).size()).isEqualTo(2);
136+
assertThat(((List<Object>) successResult.getResult().getValue().get())).hasSize(2);
137137
}
138138
}
139139

@@ -339,8 +339,7 @@ void canCallFunctionThatThrowsException() {
339339
assertThat(exception.getExceptionDetails().getText()).contains("SyntaxError:");
340340
assertThat(exception.getExceptionDetails().getLineNumber()).isPositive();
341341
assertThat(exception.getExceptionDetails().getColumnNumber()).isPositive();
342-
assertThat(exception.getExceptionDetails().getStacktrace().getCallFrames().size())
343-
.isEqualTo(0);
342+
assertThat(exception.getExceptionDetails().getStacktrace().getCallFrames()).hasSize(0);
344343
}
345344
}
346345

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ void canEvaluateScriptThatThrowsException() {
119119
assertThat(exception.getExceptionDetails().getException().getType()).isEqualTo("error");
120120
assertThat(exception.getExceptionDetails().getText()).contains("SyntaxError:");
121121
assertThat(exception.getExceptionDetails().getLineNumber()).isGreaterThanOrEqualTo(0);
122-
assertThat(exception.getExceptionDetails().getStacktrace().getCallFrames().size())
123-
.isEqualTo(0);
122+
assertThat(exception.getExceptionDetails().getStacktrace().getCallFrames()).hasSize(0);
124123
}
125124
}
126125

0 commit comments

Comments
 (0)