Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:Java 6
-
Number of attachments :
Description
The deprecated documentation over Expectations "a" and "an" suggests using "any" or "aNonNull" as replacements. However, "a" and "an" check that the type of the actual parameter passed in matches the prescribed type whereas "any" and "aNonNull" do not.
I have a method foo.schedule(Event event) where I need my Expectation to check that a specific subclass of Event was passed in when this method is called.
For example, if there are two subclasses of Event, StartEvent and EndEvent, if you set an expectation of:
oneOf(foo).schedule((Event)with(a(StartEvent.class)));
then if you call schedule with an EndEvent, it will fail as expected.
However, if you set an expectation of
oneOf(foo).schedule(with(any(StartEvent.class)));
or
oneOf(foo).schedule(with(aNonNull(StartEvent.class)));
then if you call schedule with an EndEvent, then all expectations will pass.
Suggested temporary resolution:
Do not make a() and an() deprecated.
Suggested long term resolution (if possible):
add the type-checking behaviour to any() and aNonNull()