EasyMock matcher for class data type

后端 未结 2 768
情话喂你
情话喂你 2021-01-15 03:30

I am having nightmares with the syntax for this and easymock:

public void foo(Class clazz);

EasyMock.expects(object.foo(EasyMock.isA(???)));


        
相关标签:
2条回答
  • 2021-01-15 04:07

    You're attempting to verify a generic type that will be erased at runtime anyway.

    Use a capture object instead:

    Capture<Class<?>> classCapture = new Capture<Class<?>>();
    EasyMock.expect(object.foo(EasyMock.capture(classCapture)));
    
    // ... other test setup ...
    
    Assert.assertEquals(classCapture.getValue(), String.class);
    
    0 讨论(0)
  • 2021-01-15 04:21

    I think the following will also work as an expect statement if you don't want to use a Capture:

    EasyMock.expects(object.foo(EasyMock.isA(String.class.getClass())));
    
    0 讨论(0)
提交回复
热议问题