2011-09-08 79 views
2

我試圖通過JMockit模擬帶有方法註釋的類,並發現沒有方法註釋可以通過反射獲取。字段註釋以intendet工作。我想念什麼?如何在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; 
    } 
+0

發行已結束。我可以通過從模擬中排除有問題的方法來解決問題(請參閱問題評論):下一版本正在解決問題:http://code.google.com/p/jmockit/issues/detail?id=184 –

回答

2

我能解決:

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

我也jmockit開始發行,這是acepted和修復在下一個版本中有所突破:

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