I am using Jmockit for functional testing for that in one test method i am using if-else condition like below
@Ignore
@Test(expected = CoreServiceException.class)
public final void setExpectationsForOrchestration( @Mocked final int type,
@Mocked final Object request,
@Mocked final String responseFile) throws Exception{
new NonStrictExpectations() {
{
XStream xstream = new XStream();
File obligationResponseList = new File(mockDataDir
+ responseFile);
FileReader xmlReader = new FileReader(
obligationResponseList);
if (type == 1) {
orchestrationInstance
.retrieveServiceObligationResponseByServiceObligationRequest(
(ServiceObligationRequest) request,
(AppContext) any);
} else if (type ==2) {
orchestrationInstance
.retrieveServiceObligationEntitlementResponseByServiceObligationEntitlementRequest(
(ServiceObligationEntitlementRequest) request,
(AppContext) any);
} else if (type == 3) {
orchestrationInstance
.retrieveServiceObligationHeaderOfferResponseByServiceObligationProductRequest(
(ServiceObligationProductRequest) request,
(AppContext) any);
}
else if (type == 4) {
orchestrationInstance
.retrieveServiceObligationCustomerDocumentByServiceObligationRequest(
(ServiceObligationRequest) request,
(AppContext) any);
}
result = xstream.fromXML(xmlReader);
}
};
}
But while running i am getting this error
java.lang.IllegalArgumentException: Invalid conditional statement inside expectation block at com.hp.it.sbs.obligation.service.ObligationServiceImplMockTest_old$1.(ObligationServiceImplMockTest_old.java:2560) at com.hp.it.sbs.obligation.service.ObligationServiceImplMockTest_old.setExpectationsForOrchestration(ObligationServiceImplMockTest_old.java:2547) at com.hp.it.sbs.obligation.service.ObligationServiceImplMockTest_old.testRetrieveServiceObligationResponsesByServiceObligationRequests(ObligationServiceImplMockTest_old.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Can anyone answer on this . I am using the jmockit version 1.21