Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3560

Make it easier to match URL arguments with Mockito

    XMLWordPrintable

Details

    • 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.

      Attachments

        Activity

          People

            mflorea Marius Dumitru Florea
            mflorea Marius Dumitru Florea
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: