0
假設我有一個抽象類,它的子類擴展了,我想模擬一個在超類的受保護數據類型中使用的類。問題是需要模擬的類是默認數據類型,所以它不能在包外部訪問。讓我舉個例子說明我的觀點。謝謝你的幫助。抽象類的默認類型變量
class protectedVariableClass{
public SomeObject someObject1;
public SomeObject someObject2;
}
public abstract class superClass {
protected protectedVariableClass protectedVariableClass;
..................
.................
}
public class subClass extends superClass {
protected boolean someMethod() {
protectedVariableClass.someObject1.printValue;
}
}
現在,當我嘗試使用Jmockit進行測試時,我無法爲超類的Protected變量創建模擬。
public class SubClassTest{
@Mocked
private protectedVariableClass mockedObject; // Cannot access the class with default data type outside package.
@Test
public void testClass {
subClass s1 = new subClass();
s1.someMethod();
}
}