This issue has been created
There are 6 updates, 1 comment.
 
 
XWiki Commons / cid:jira-generated-image-avatar-68e1798c-7d04-4a31-9de8-2d4d81a901ff XCOMMONS-3560 Open

Make it easier to match URL arguments with Mockito

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-19684890-4ec6-44b1-8a01-23953905aa72 Marius Dumitru Florea created this issue on 03/Feb/26 15:44
 
Summary: Make it easier to match URL arguments with Mockito
Issue Type: cid:jira-generated-image-avatar-68e1798c-7d04-4a31-9de8-2d4d81a901ff New Feature
Affects Versions: 17.10.3
Assignee: Unassigned
Components: Development Issues only - Test
Created: 03/Feb/26 15:44
Priority: cid:jira-generated-image-static-major-670bf4f3-2f8c-4af1-a0a4-3d3dac7bab0d Major
Reporter: Marius Dumitru Florea
Description:

Matching URL arguments with Mockito can be tricky. The issue is in the URL#equals() method which checks if the two URLs "reference equivalent hosts":

Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null.

This means that a line like this:

assertEquals(new URL("http://alice/test"), new URL("http://bob/test"));

might pass, depending on the environment where the test runs (i.e. depending on whether the URL domain / host is resolved or not).

In order to avoid this we need to use a custom URL argument matcher that compares the toString values. We could even have a generic "toStringEquals" matcher.

 
 

6 updates

 
cid:jira-generated-image-avatar-19684890-4ec6-44b1-8a01-23953905aa72 Changes by Marius Dumitru Florea on 03/Feb/26 15:45
 
Fix Version: 18.0.1
Fix Version: 18.1.0-rc-1
Fix Version: 17.10.4
Documentation in Release Notes: N/A
Documentation: N/A
Assignee: Marius Dumitru Florea
 
 

1 comment

 
cid:jira-generated-image-avatar-19684890-4ec6-44b1-8a01-23953905aa72 Marius Dumitru Florea on 03/Feb/26 15:49
 

Example usage:

import static org.xwiki.test.mockito.ArgumentMatchers.toStrEq;

...
when(this.browserTab.navigate(toStrEq(someURL))).thenReturn(true);
...
verify(this.browserTab, times(2)).navigate(toStrEq(someURL));