paymentBusinessService クラスは、BusinessService クラスの依存性注入で利用できます。アプリケーション sc = Applicaition.applicationValidation(this.deal);
Application sc = BusinessService.applicationValidation(this.deal); とします。
package com.core.business.service.dp.fulfillment;
import com.core.business.service.dp.payment.PaymentBusinessService;
public class BusinessServiceImpl implements BusinessService { // Actual Impl Class
private PaymentBusinessService paymentBusinessService = PluginSystem.INSTANCE.getPluginInjector().getInstance(PaymentBusinessService.class);
@Transactional( rollbackOn = Throwable.class)
public Application applicationValidation (final Deal deal) throws BasePersistenceException {
Application application = (Application) ApplicationDTOFactory.eINSTANCE.createApplication();
//External Call we want to Mock
String report = paymentBusinessService.checkForCreditCardReport(deal.getId());
if (report != null) {
application.settingSomething(true);
}
return application;
}
}
@Test(enabled = true)// Test Class
public void testReCalculatePrepaids() throws Exception {
PaymentBusinessService paymentBusinessService = mock(PaymentBusinessService.class);
//Mocking External Call
when(paymentBusinessService.checkForCreditCardReport(this.deal.getId())).thenReturn(new String("Decline by only Me"));
String report = paymentBusinessService.checkForCreditCardReport(this.deal.getId());
//Calling Impl Class whose one external call is mocked
Application sc = BusinessService.applicationValidation(this.deal);
}