Skip to content
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

#2617 User can safely add the same proxy filter many times #2630

Merged
merged 1 commit into from Jan 29, 2024

Conversation

asolntsev
Copy link
Member

it's convenient to store a filter into a constant, and add it before every open(url) - without checking if it was already added earlier.

var MY_CONSTANT_LOGGER = new RequestFilter() {...}
getSelenideProxy().addRequestFilter("request-logger", MY_CONSTANT_LOGGER);

it's convenient to store a filter into a constant, and add it before every `open(url)` - without checking if it was already added earlier.

```
var MY_CONSTANT_LOGGER = new RequestFilter() {...}
getSelenideProxy().addRequestFilter("request-logger", MY_CONSTANT_LOGGER);
```
@asolntsev asolntsev added this to the 7.1.0 milestone Jan 28, 2024
@asolntsev asolntsev self-assigned this Jan 28, 2024
Copy link

sonarcloud bot commented Jan 28, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@@ -116,15 +116,14 @@ public boolean isStarted() {
* @param requestFilter the filter
*/
public void addRequestFilter(String name, RequestFilter requestFilter) {
if (isRequestFilterAdded(name)) {
RequestFilter currentFilter = requestFilter(name);
if (currentFilter != null && !currentFilter.equals(requestFilter)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to use such verification and skip next currentFilter null check as well?

Suggested change
if (currentFilter != null && !currentFilter.equals(requestFilter)) {
if (Objects.equals(currentFilter, requestFilter)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rosolko Nice try, but no :)
Then this method will throw exception if currentFilter == null. But should not.

@@ -134,11 +133,14 @@ private boolean isRequestFilterAdded(String name) {
* @param responseFilter the filter
*/
public void addResponseFilter(String name, ResponseFilter responseFilter) {
if (responseFilters.containsKey(name)) {
ResponseFilter currentFilter = responseFilter(name);
if (currentFilter != null && !currentFilter.equals(responseFilter)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@asolntsev asolntsev merged commit 494e796 into main Jan 29, 2024
12 of 13 checks passed
@asolntsev asolntsev deleted the feature/2617-add-same-filter-many-times branch January 29, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User can safely call addRequestFilter/addResponseFilter with the same filter
2 participants