如何在JMockit模拟实例中保留方法注释

时间:2011-09-08 13:54:11

标签: java jmockit

我尝试通过JMockit使用方法注释来模拟类,并发现没有方法注释可以通过反射来检索。字段注释作为用户工作。我想念一下吗?

嘲讽:

    @Test
public void testThatSetterInjectionIsBombedProperlyOnNonAssignability(@Mocked final WithInjectableMethods injectable,
                                                                      @Mocked final TextView textView,
                                                                      @Mocked final Button button) {

有问题的课程:

class WithInjectableMethods extends Activity {

    private android.view.View asView;

    private Button button;

    // shall be left alone
    private View notInjected = null;
    // shall be injected


    @InjectView(id = 239)
    private void setAsView(View asView) {
        this.asView = asView;
    }

    @InjectView(id = 555)
    public void setButton(Button button) {
        this.button = button;
    }

    public void setNotInjected(View notInjected) {
        this.notInjected = notInjected;
    }

1 个答案:

答案 0 :(得分:2)

我能够解决这个问题:

   @Mocked(methods = {"setAsView", "setButton", "notInjected"}, inverse = true) final WithInjectableMethods injectable,

我也开始在jmockit上发布问题,它在下一个版本中得到了认可和修复:

http://code.google.com/p/jmockit/issues/detail?id=184