jMock

Cookbook Matcher example for Instance of a Type only works with parameters of type Object

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.4.0
  • Fix Version/s: 2.5.0
  • Component/s: Documentation
  • Labels:
    None
  • Number of attachments :
    0

Description

The cookbook example for testing a method must be called with an argument that is an ActionEvent only works if the method "doSomething" has a signature of void doSomething(Object).

This is due to the the Hamcrest matcher "instanceOf" being typed to Object rather than T.

This is the example in question:

one (mock).doSomething(with(instanceOf(ActionEvent.class)));

Activity

Hide
Nat Pryce added a comment -

We've discussed this on the jMock mailing list. Thanks to Java's "special" implementation of generic types, the Java 5 and 6 compiler cannot compile code that uses instanceOf if instanceOf is defined with the appropriate generic constraints.

I'll have to remove it from the documentation and deprecate the function until the Java language definition is fixed.

--Nat

Show
Nat Pryce added a comment - We've discussed this on the jMock mailing list. Thanks to Java's "special" implementation of generic types, the Java 5 and 6 compiler cannot compile code that uses instanceOf if instanceOf is defined with the appropriate generic constraints. I'll have to remove it from the documentation and deprecate the function until the Java language definition is fixed. --Nat
Hide
Nat Pryce added a comment -

Deprecations checked into svn and documentation fix published to website

Show
Nat Pryce added a comment - Deprecations checked into svn and documentation fix published to website

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: