-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
use proper AssertJ asserts that generate a useful error message #16707
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
use proper AssertJ asserts that generate a useful error message #16707
Conversation
|
Thank you, @asolntsev for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
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 ✨No code suggestions found for the PR. |
In case of test failure, it's important that the error message shows all the needed information: what was the actual/expected value etc. This commit makes many asserts show this info.
For example,
* `assertThat(a == b).isTrue()` does NOT show what were `a` and `b` values;
* `assertThat(list.contain("foo")).isTrue()` does NOT show what was the `list` value;
* `assertThat(model == 32 || model == 64).isTrue()` does NOT show what was `model` value
etc.
b22498f to
9ba2391
Compare
it seems this functionality has been implemented in Edge.
User description
In case of test failure, it's important that the error message shows all the needed information: what was the actual/expected value etc. This commit makes many asserts show this info.
For example,
assertThat(a == b).isTrue()does NOT show what wereaandbvalues;assertThat(list.contain("foo")).isTrue()does NOT show what was thelistvalue;assertThat(model == 32 || model == 64).isTrue()does NOT show what wasmodelvalueetc.
💥 What does this PR do?
Replaces some AssertJ asserts by similar, but better asserts.
🔄 Types of changes
PR Type
Tests, Enhancement
Description
Replace weak AssertJ assertions with stronger alternatives for better error messages
Use
hasValue(),isEmpty(),isPresent()instead of.isPresent().isTrue()Apply
asInstanceOf()with type factories for type-safe assertionsSimplify test code with
containsExactly(),containsEntry(),anyMatch()Add
equals(),hashCode(),toString()methods to value objectsDiagram Walkthrough
File Walkthrough
41 files
Replace Optional assertions with hasValue/isEmptyImprove Optional and List assertions with better methodsSimplify list assertions and use List.of() factoryReplace Optional checks with hasValue() assertionsUse asInstanceOf() for type-safe collection assertionsReplace type casts with asInstanceOf() and improve assertionsReplace Optional assertions with hasValue() methodImprove Map assertions with containsKey/doesNotContainKeyUse static import for assertThat instead of AssertionsReplace collection contains checks with direct assertionsSimplify cookie assertions and extract helper methodReplace Optional checks with isPresent and hasValueReplace AtomicBoolean.get() assertions with direct checksUse asInstanceOf() for Map type assertionsReplace Optional.isPresent().isTrue() with isPresent()Replace set contains checks with direct assertionsRefactor test helper to use Optional.map() and isEmpty()Simplify Map assertions with containsEntry()Replace fuzzy position matching with isCloseTo() offsetUse assumeThat and improve numeric assertionsReplace fuzzy matching with isCloseTo() assertionsReplace AtomicBoolean.get() with direct assertionsImprove File assertions with isDirectory() and startsWith()Replace string endsWith check with assertion methodReplace stream anyMatch check with assertion methodImprove numeric assertions with isIn() methodReplace contains check with assertion methodSimplify cookie set assertions with contains()Replace type check with isInstanceOf() assertionRename helper method for clarity and improve assertionsReplace string startsWith/endsWith checks with assertionsChain File assertions with exists() and isNotEmpty()Replace numeric comparisons with isGreaterThan()Replace File.exists() check with assertion methodReplace AtomicBoolean.get() and improve string assertionsAdd suppression annotation for removal warningsReplace contains check with assertion methodUse containsIgnoringCase() for style attribute checkUse containsIgnoringCase() for style attribute checkReplace AtomicBoolean.get() with direct assertionChain Boolean assertions with isInstanceOf() and isEqualTo()5 files
Add equals, hashCode, toString methods to RegExpValueReplace HashMap with Map.of() factory methodAdd toString() method for better debuggingAdd toString() method for better debuggingImprove error message formatting with quoted architecture1 files
Add jspecify dependency for null annotations2 files