Commons DbUtils
  1. Commons DbUtils
  2. DBUTILS-9

[dbutils] MockResultSet needs to handle equals and hashCode

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      Please amend MockResultSet#invoke like this in order to handel equals,
      hashCode, and toString

      public Object invoke(Object proxy, Method method, Object[] args)
      throws Throwable {

      String methodName = method.getName();

      if (methodName.equals("getMetaData"))

      { //... }

      else if (methodName.equals("equals"))

      { return Boolean.valueOf(proxy == args[0]); }

      else if (methodName.equals("hashCode"))

      { return Integer.valueOf(System.identityHashCode(proxy)); }

      else if (methodName.equals("toString"))

      { return proxy.toString(); }

      return null;
      }

      This addition makes proxies generated by MockResultSet usable in Maps. That
      might not look like a big deal, but it is. Among other things, EasyMock keeps
      arguments and return values in Maps. With the addition, MockResultSet proxies
      can be used with mock objects created by EasyMock.

      Michael

        Activity

        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Henri Yandell made changes -
        Fix Version/s 1.1 [ 12311973 ]
        Henri Yandell made changes -
        Affects Version/s 1.0 Final [ 12311724 ]
        Henri Yandell made changes -
        Key COM-1660 DBUTILS-9
        Component/s DbUtils [ 12311110 ]
        Affects Version/s 1.0 Final [ 12311651 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Project Commons [ 12310458 ] Commons DbUtils [ 12310470 ]
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 31786 12341812
        Hide
        David Graham added a comment -

        I added toString, equals, and hashCode implementations to MockResultSet and
        MockResultSetMetaData. A couple things though:

        • return Integer.valueOf(System.identityHashCode(proxy)) does not compile so I
          changed it to return new Integer(System.identityHashCode(proxy))
        • return proxy.toString() causes an infinite loop so I changed it to return
          "MockResultSet " + System.identityHashCode(proxy)
        Show
        David Graham added a comment - I added toString, equals, and hashCode implementations to MockResultSet and MockResultSetMetaData. A couple things though: return Integer.valueOf(System.identityHashCode(proxy)) does not compile so I changed it to return new Integer(System.identityHashCode(proxy)) return proxy.toString() causes an infinite loop so I changed it to return "MockResultSet " + System.identityHashCode(proxy)
        Michael Schuerig created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Michael Schuerig
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development