0
我不得不生产者:CDI:两位制片
@Produces
public IPaymentGateway getStripePaymentGateway(@StripeApiKey final String apiKey) {
return new StripeFluentAPI(apiKey);
}
@Produces
public IPaymentGateway getStripePaymentGatewayProxy() {
IPaymentGateway gateway = mock(IPaymentGateway.class);
ICustomer customer = mock(ICustomer.class);
when(gateway.customer()).thenReturn(customer);
return gateway;
}
第一个返回真正实现我的IPaymentGateway
的。另一方面,第二个返回代理对象。
为了我使用的是@ApplicationScoped
对象知道如果网关已启用或禁用:
@ApplicationScoped
public class ConfigurationResources {
public boolean isPaymentGatewayEnabled() {
return paymentGatewayEnabled;
}
}
所以,我想知道如何选择或其他生产者根据isPaymentGatewayEnabled
值。
您可以产生'IPaymentGateway'一个方法,并添加'ConfigurationResources'作为该方法的参数。然后,您可以生成“真实”bean或“isPaymentGatewayEnabled”值上的模拟依赖。 – Rouliboy