Menu ▾ ▴

#26 Mock.expect() can't handle null values for method parameters

open
nobody
None
5
2003-11-12
2003-11-12
No

In mock interface I have method setAttribute(
name:String, value:String):void. So, I wrote the
following condition:

mockServletContext.expect( "setAttribute", new
ConstraintMatcher() {
public boolean matches( Object[] args) {
if( "myname".equals( args[ 0])) {
return true;
}
return false;
}
public Object[] getConstraints() {
return new Object[] {};
}
});

This code should handle any value. However if method is
called with null value I have an exception:

java.lang.NullPointerException
at
com.mockobjects.dynamic.DynamicUtil.join(DynamicUtil.java:118)
at
com.mockobjects.dynamic.DynamicUtil.methodToString(DynamicUtil.java:104)
at
com.mockobjects.dynamic.CallCollection.createUnexpectedCallError(CallCollection.java:11)
at com.mockobjects.dynamic.CallBag.call(CallBag.java:31)
at com.mockobjects.dynamic.Mock.invoke(Mock.java:88)
at $Proxy0.setAttribute(Unknown Source)
.....

Am I doing something wrong?

Discussion

  • Andriy Palamarchuk

    Logged In: YES
    user_id=437388

    See the same problem in current CVS. My test case:

    import com.mockobjects.dynamic.Mock;

    public class Class1 {

    public static interface Interface1 {
    void show(Object value);
    }

    public static void main(String[] args) {
    final Mock mockInterface1 = new Mock(Interface1.class);
    mockInterface1.expect("show", (Object) null);
    ((Interface1) mockInterface1.proxy()).show(null);
    mockInterface1.verify();
    }
    }

     

Log in to post a comment.