Details
-
New Feature
-
Resolution: Fixed
-
Major
-
17.10.3
-
None
-
Unknown
-
N/A
-
N/A
-
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.