我有一个测试代码(使用jmockit 1.8):
public class BasicTest {
...
@Mocked("evaluateAlternateTerms")
WMSTK_BLT_Services wmstkBltServices;
@Before
public void setUp() {...}
@Test
public void testAlternativeDatesCalculationException() throws Throwable {
new Expectations() {{
withSameInstance(capacityService);
withSameInstance(buchungs);
Deencapsulation.invoke(wmstkBltServices, "evaluateAlternateTerms", CapacityService.class, List.class);
result = new KVWSException(new ErrorCode(1)) {
public String getMessage() {
return "TEST";
}
};
}};
KapazitaetAendernResponse result = alternativeDates(capacityService, buchungs);
assertThat(result.getFehlercode(), is((short) 9999));
assertThat(result.getFehlertext(), is("TEST"));
}
我试图使用模拟方法" evaluateAlternateTerms",但它发送错误:
java.lang.NullPointerException
at com.tsystems.kvws.WMSTK_BLT_Services.evaluateAlternateTerms(WMSTK_BLT_Services.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.tsystems.kvws.tests.wmstkKapazitaetsservices.alternativeDates.BasicTest$1.(BasicTest.java:81)
at com.tsystems.kvws.tests.wmstkKapazitaetsservices.alternativeDates.BasicTest.testAlternativeDatesCalculationException(BasicTest.java:78)
为什么??我做了模拟,它不能去:
evaluateAlternateTerms(WMSTK_BLT_Services.java:87)
P.S。这是alternativeDates方法:
private KapazitaetAendernResponse alternativeDates(CapacityService capacityService, List kapResBuchungs) throws Throwable {
return (KapazitaetAendernResponse) PrivateAccessor.invoke(new WmstkKapazitaetsservices(),
"alternativeDates", new Class[] {CapacityService.class, List.class},
new Object[] {capacityService, kapResBuchungs});
}
提前致谢!