-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java] Refactor tests #16684
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
base: trunk
Are you sure you want to change the base?
[java] Refactor tests #16684
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
1b27e98 to
ef640c3
Compare
…ssTypes` 1. `Assertions.assertThat` is the standard, primary entry point for AssertJ assertions. It works for all types and automatically picks specialized assertion classes when available. 2. `AssertionsForClassTypes.assertThat` is a legacy / niche entry point intended for cases where type inference conflicts with AssertJ’s overloaded `assertThat` methods.
…one construct "try/fail/catch(expected)".
`assertThat($$.size()).isEqualTo(2)` -> `assertThat($$).hasSize(2)`
`assertThat(X.get()).isEqualTo(2)` -> `assertThat(X).hasValue(2)`
ef640c3 to
d9d9a0d
Compare
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||||
User description
💥 What does this PR do?
Improve tests:
assertThatThrownBy🔄 Types of changes
PR Type
Tests
Description
Comprehensive refactoring of Java test files to improve code quality and consistency:
Replaced JUnit assertions with AssertJ methods: Standardized assertion patterns across 50+ test files by replacing
assertEquals(),.size(), and.get()calls with idiomatic AssertJ methods likeassertThat().isEqualTo(),hasSize(), andhasValue()Removed try-catch blocks: Eliminated exception handling boilerplate by using
assertThatThrownBy()andassertThatCode()for exception testing, or propagating exceptions withthrowsdeclarationsConsolidated AssertJ imports: Unified fragmented imports from
AssertionsForClassTypesandAssertionsForInterfaceTypesto the singleAssertionsclass for consistencyImproved error messages: Enhanced debugging information in exception messages and
fail()calls by including contextual details like session IDs and credential informationCode cleanup: Removed unused imports, fixed variable naming typos, and simplified resource management with try-with-resources blocks
Updated IDE configuration: Modified code style settings to increase import-on-demand thresholds and standardize package import preferences
Diagram Walkthrough
File Walkthrough
44 files
LocalNewSessionQueueTest.java
Refactor tests to use AssertJ assertions and remove try-catchjava/test/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueueTest.java
assertEquals→assertThat().isEqualTo())assertThatThrownByfor exceptiontesting
java.util.*andjava.util.concurrent.*randomUUID()and replacedUUID.randomUUID()calls
hasSize(),isEmpty(),containsExactly()JmxTest.java
Remove try-catch blocks and simplify exception handlingjava/test/org/openqa/selenium/grid/router/JmxTest.java
throws Exceptionto test methodsjavax.management.*fail()import from JUnitTakesScreenshotTest.java
Remove try-catch blocks and use AssertJ assertionsjava/test/org/openqa/selenium/TakesScreenshotTest.java
throws IOExceptionto test methodsfail()calls with AssertJ assertionscatching them
assertThat().containsExactlyInAnyOrderElementsOf()for colorcomparison
LogInspectorTest.java
Replace size assertions and remove exception handling boilerplatejava/test/org/openqa/selenium/bidi/log/LogInspectorTest.java
.size()with AssertJhasSize()methodthrows TimeoutExceptionto methodserrorLogfuture→errorLogFuture)WebScriptExecuteTest.java
Standardize AssertJ imports and use hasValue/hasSize methodsjava/test/org/openqa/selenium/WebScriptExecuteTest.java
AssertionsForClassTypestoAssertions.get()calls with AssertJhasValue()method.size()with AssertJhasSize()methodNetworkCommandsTest.java
Refactor to use AssertJ and remove exception handling boilerplatejava/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java
AssertionsForClassTypestoAssertionsCOMPLETEfromReadinessStateassertThatThrownByfor exceptiontesting
them
.get()withhasValue()assertionTakesFullPageScreenshotTest.java
Remove try-catch blocks and use AssertJ assertionsjava/test/org/openqa/selenium/firefox/TakesFullPageScreenshotTest.java
throws IOExceptionto test methodsfail()calls with AssertJ assertionsassertThat().containsExactlyInAnyOrderElementsOf()for colorcomparison
ScriptCommandsTest.java
Standardize AssertJ imports and use hasSize/hasValue methodsjava/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java
AssertionsbeforeAssertionsForClassTypes.size()with AssertJhasSize()method.get()withhasValue()assertionPageLoadTimeOutTest.java
Replace try-catch with assertThatThrownBy and improve assertionsjava/test/org/openqa/selenium/PageLoadTimeOutTest.java
currentTimeMillis()andassertThatThrownByassertThatThrownByfor exceptiontesting
isBetween()assertionBrowser.*LocateNodesTest.java
Standardize AssertJ imports and use hasSize/hasValue methodsjava/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java
AssertionsForClassTypestoAssertions.size()with AssertJhasSize()method.get()withhasValue()assertionBrowserimportsLocalValueTest.java
Standardize AssertJ imports and use hasSize/hasValue methodsjava/test/org/openqa/selenium/bidi/script/LocalValueTest.java
AssertionsForClassTypestoAssertions.size()with AssertJhasSize()method.get()withhasValue()assertionEndToEndTest.java
Replace try-catch with assertThatThrownBy and improve assertionsjava/test/org/openqa/selenium/grid/router/EndToEndTest.java
assertThatThrownByfor exceptiontesting
assertThatThrownByimport.as()methodWebScriptTest.java
Replace try-catch with assertThatThrownBy and use hasSize methodjava/test/org/openqa/selenium/WebScriptTest.java
Assertions.*wildcardassertThatThrownByfor exceptiontesting
.size()with AssertJhasSize()methodNodeOptionsTest.java
Replace try-catch with assertThatThrownBy and improve assertionsjava/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java
assertThatThrownByfor exceptiontesting
assertThatThrownByimport.as()and.hasMessage()methodsfail()importHeartBeatTest.java
Remove try-catch and use try-with-resources for resource managementjava/test/org/openqa/selenium/grid/distributor/HeartBeatTest.java
throws InterruptedExceptionto testmethod
LocalNoderesource managementRetryRequestTest.java
Replace atomic variable assertions with hasValue methodjava/test/org/openqa/selenium/remote/http/RetryRequestTest.java
.get()with AssertJhasValue()method on atomic variablesSessionQueueGridTest.java
Remove try-catch blocks and simplify exception handlingjava/test/org/openqa/selenium/grid/router/SessionQueueGridTest.java
throws Exceptionto test methodsjava.util.concurrent.*LocalDistributorTest.java
Replace size assertions with hasSize methodjava/test/org/openqa/selenium/grid/distributor/local/LocalDistributorTest.java
.size()with AssertJhasSize()methodfail()call with exception message and causeChromeDriverFunctionalTest.java
Replace try-catch with assertThatThrownBy and use try-with-resourcesjava/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java
assertThatThrownByfor exceptiontesting
AssertionsclassChromeDriverServiceresource managementCorrectEventFiringTest.java
Replace try-catch with assertThatCode and improve assertionsjava/test/org/openqa/selenium/CorrectEventFiringTest.java
Assertions.*wildcardassertThatCodeandassertThatassertions
.as()methodEdgeDriverFunctionalTest.java
Replace try-catch with assertThatThrownBy and use try-with-resourcesjava/test/org/openqa/selenium/edge/EdgeDriverFunctionalTest.java
assertThatThrownByfor exceptiontesting
AssertionsclassEdgeDriverServiceresource managementRemoteFirefoxDriverTest.java
Replace try-catch with assertThatCode and remove unused importsjava/test/org/openqa/selenium/firefox/RemoteFirefoxDriverTest.java
assertThatCodefor exception testingMalformedURLException,WebDriverException)assertThatCodeimportRemotableByTest.java
Use static import and replace get assertions with hasValuejava/test/org/openqa/selenium/remote/RemotableByTest.java
ImmutableMap.of().get()with AssertJhasValue()methodImmutableMapimport in favor of static method importDragAndDropTest.java
Replace try-catch with assertThatThrownBy and improve assertionsjava/test/org/openqa/selenium/bidi/input/DragAndDropTest.java
assertThatThrownByfor exceptiontesting
assertThatThrownByimport.as()and.hasMessageContaining()methods
CallFunctionParameterTest.java
Standardize AssertJ imports and use hasSize methodjava/test/org/openqa/selenium/bidi/script/CallFunctionParameterTest.java
AssertionsForClassTypestoAssertions.size()with AssertJhasSize()methodStorageCommandsTest.java
Replace size and get assertions with hasSize and hasValuejava/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java
.size()with AssertJhasSize()method.get()withhasValue()assertionScriptEventsTest.java
Standardize AssertJ imports and use hasValue methodjava/test/org/openqa/selenium/bidi/script/ScriptEventsTest.java
AssertionsForClassTypestoAssertions.get()withhasValue()assertionBrowserimportsNetworkEventsTest.java
Standardize AssertJ imports and use hasSize methodjava/test/org/openqa/selenium/bidi/network/NetworkEventsTest.java
AssertionsForClassTypestoAssertions.size()with AssertJhasSize()methodBrowserimportsEvaluateParametersTest.java
Standardize AssertJ imports and use hasSize methodjava/test/org/openqa/selenium/bidi/script/EvaluateParametersTest.java
AssertionsForClassTypestoAssertions.size()with AssertJhasSize()methodExpectedConditionsTest.java
Add static import and replace size assertions with hasSizejava/test/org/openqa/selenium/support/ui/ExpectedConditionsTest.java
cssSelector.size()with AssertJhasSize()methodSessionQueueGridWithTimeoutTest.java
Remove try-catch blocks and fix method namingjava/test/org/openqa/selenium/grid/router/SessionQueueGridWithTimeoutTest.java
throws Exceptionto test methodExecutionException,TimeoutException)shouldBeAbleToDeleteTimedoutSessions→shouldBeAbleToDeleteTimedOutSessions)FirefoxDriverTest.java
Replace try-catch with assertThatThrownByjava/test/org/openqa/selenium/firefox/FirefoxDriverTest.java
assertThatThrownByfor exceptiontesting
AssertionsclassNetworkInterceptorTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/devtools/NetworkInterceptorTest.java
AssertionsForClassTypesandAssertionsForInterfaceTypesto unifiedAssertionsclassmaintainability
RemoteWebDriverBiDiTest.java
Consolidate imports and use AssertJ hasSize() methodjava/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java
AssertionsForClassTypesto unifiedAssertionsclass
Browserwith explicit imports forIEandSAFARIassertThat(logEntry.getArgs().size()).isEqualTo(1)withassertThat(logEntry.getArgs()).hasSize(1)ClosureTestStatement.java
Remove unnecessary try-catch and unused importsjava/test/org/openqa/selenium/javascript/ClosureTestStatement.java
fail()andWebDriverExceptiondriver.get()call, allowing exceptionsto propagate naturally
catching
WebNetworkTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/WebNetworkTest.java
AssertionsForClassTypesto unifiedAssertionsclassSetTimezoneOverrideTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/emulation/SetTimezoneOverrideTest.java
AssertionsForClassTypesto unifiedAssertionsclass
SetScriptingEnabledTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/emulation/SetScriptingEnabledTest.java
AssertionsForClassTypesto unifiedAssertionsclass
BiDiTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/BiDiTest.java
AssertionsForClassTypesto unifiedAssertionsclass
AddInterceptParametersTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/network/AddInterceptParametersTest.java
AssertionsForClassTypesto unifiedAssertionsclass
SetGeolocationOverrideTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/emulation/SetGeolocationOverrideTest.java
AssertionsForClassTypesto unifiedAssertionsclass
BiDiSessionTest.java
Consolidate AssertJ imports to unified Assertions classjava/test/org/openqa/selenium/bidi/BiDiSessionTest.java
AssertionsForClassTypesto unifiedAssertionsclass
RemoteWebDriverDownloadTest.java
Consolidate imports using wildcard notationjava/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java
for
org.openqa.seleniumpackageSafariDriverTest.java
Consolidate AssertJ imports using wildcard notationjava/test/org/openqa/selenium/safari/SafariDriverTest.java
from
Assertionsclass20 files
LazyTest.java
Add generic type parameters to Lazy declarationsjava/test/org/openqa/selenium/concurrent/LazyTest.java
Lazyvariable declarationsVirtualAuthenticatorTest.java
Use AssertJ hasSize() method and improve error messagesjava/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java
assertThat(credentialList.size()).isEqualTo(1)withassertThat(credentialList).hasSize(1)for more idiomatic AssertJ usageassertThat(credentials.size()).isEqualTo(2)withassertThat(credentials).hasSize(2)fail()call to include the unrecognizedcredential ID for better debugging
RemoteWebDriverBuilderTest.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/remote/RemoteWebDriverBuilderTest.java
assertThat(seen.get()).isEqualTo(uri)withassertThat(seen).hasValue(uri)in four test methodsProxyWebsocketTest.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/grid/router/ProxyWebsocketTest.java
assertThat(text.get()).isEqualTo("Cheese!")withassertThat(text).hasValue("Cheese!")in three test methodsPrintOptionsTest.java
Use AssertJ hasSize() method for collection assertionsjava/test/org/openqa/selenium/print/PrintOptionsTest.java
assertThat(map.size()).isEqualTo(7)withassertThat(map).hasSize(7)assertThat(margin.size()).isEqualTo(4)withassertThat(margin).hasSize(4)assertThat(page.size()).isEqualTo(2)withassertThat(page).hasSize(2)RedisBackedSessionMapTest.java
Use assertThatThrownBy() and consolidate importsjava/test/org/openqa/selenium/grid/sessionmap/redis/RedisBackedSessionMapTest.java
AssertionsassertThatThrownBy()for cleanerexception assertion
fail()call in favor of AssertJ's exception handlingElementFindingTest.java
Use AssertJ hasSize() method for list assertionsjava/test/org/openqa/selenium/ElementFindingTest.java
assertThat(elements.size()).isEqualTo(2)withassertThat(elements).hasSize(2)WebElementToJsonConverterTest.java
Use AssertJ hasSize() method for map assertionsjava/test/org/openqa/selenium/remote/WebElementToJsonConverterTest.java
assertThat(map.size()).isEqualTo(1)withassertThat(map).hasSize(1)in two test methodsRedisBackedSessionMap.java
Improve error message with session ID informationjava/src/org/openqa/selenium/grid/sessionmap/redis/RedisBackedSessionMap.java
NoSuchSessionExceptionto include thesession ID for better debugging
JdbcBackedSessionMap.java
Improve error message with session ID informationjava/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMap.java
NoSuchSessionExceptionto include thesession ID for better debugging
WebSocketTestBase.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/remote/internal/WebSocketTestBase.java
assertThat(message.get()).isEqualTo("Hello, World!")withassertThat(message).hasValue("Hello, World!")assertThat(message.get()).isEqualTo("brie".getBytes(UTF_8))with
assertThat(message).hasValue("brie".getBytes(UTF_8))RelayOptionsTest.java
Use AssertJ hasSize() method for collection assertionsjava/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java
assertThat(sessionFactories.get(chrome).size()).isEqualTo(2)with
assertThat(sessionFactories.get(chrome)).hasSize(2)ChildrenFindingTest.java
Use AssertJ hasSize() method for list assertionsjava/test/org/openqa/selenium/ChildrenFindingTest.java
assertThat(allPs.size()).isEqualTo(children.size())withassertThat(allPs).hasSize(children.size())CookieImplementationTest.java
Use AssertJ hasSize() method for collection assertionsjava/test/org/openqa/selenium/CookieImplementationTest.java
assertThat(cookies.size()).isEqualTo(countBefore + 2)withassertThat(cookies).hasSize(countBefore + 2)DistributorNodeAvailabilityTest.java
Use AssertJ hasSize() method for collection assertionsjava/test/org/openqa/selenium/grid/distributor/DistributorNodeAvailabilityTest.java
assertThat(status.getNodes().size()).isEqualTo(1)withassertThat(status.getNodes()).hasSize(1)FilterTest.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/remote/http/FilterTest.java
assertThat(rootCalls.get()).isEqualTo(1)withassertThat(rootCalls).hasValue(1)assertThat(filterOneCount.get()).isEqualTo(1)withassertThat(filterOneCount).hasValue(1)assertThat(filterTwoCount.get()).isEqualTo(1)withassertThat(filterTwoCount).hasValue(1)NettyServerTest.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/netty/server/NettyServerTest.java
assertThat(count.get()).isEqualTo(1)withassertThat(count).hasValue(1)in two test methodsJsonTest.java
Use AssertJ hasSize() method for map assertionsjava/test/org/openqa/selenium/json/JsonTest.java
assertThat(converted.size()).isEqualTo(1)withassertThat(converted).hasSize(1)EventFiringDecoratorTest.java
Use AssertJ hasValue() for Optional assertionsjava/test/org/openqa/selenium/support/events/EventFiringDecoratorTest.java
assertThat(invocationCount.get()).isEqualTo(1)withassertThat(invocationCount).hasValue(1)JsonOutputTest.java
Use AssertJ hasSize() method for collection assertionsjava/test/org/openqa/selenium/json/JsonOutputTest.java
assertThat(converted.size()).isEqualTo(1)withassertThat(converted).hasSize(1)1 files
Project.xml
Update IDE code style configuration settings.idea/codeStyles/Project.xml
CLASS_COUNT_TO_USE_IMPORT_ON_DEMANDandNAMES_COUNT_TO_USE_IMPORT_ON_DEMANDfrom 99 to 999PACKAGES_TO_USE_IMPORT_ON_DEMANDconfiguration forjava.awtandjavax.swingXML_LEGACY_SETTINGS_IMPORTEDoption1 files
modules.xml
Fix file ending with newline.idea/modules.xml
9 files