Java Mockito错误,如单位案例上的org.Mockito.exceptions.misusing.ErrorTypeOfReturnValue
我正在尝试运行此测试用例,但我正在Java Mockito错误,如单位案例上的org.Mockito.exceptions.misusing.ErrorTypeOfReturnValue,java,mockito,Java,Mockito,我正在尝试运行此测试用例,但我正在 org.mockito.exceptions.misusing.WrongTypeOfReturnValue: Amount$$EnhancerByMockitoWithCGLIB$$3216e5a5 cannot be returned by getAmount() getAmount() should return Amount *** 完整测试用例 @RunWith(PowerMockRunner.class) @PrepareForTest(Ent
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Amount$$EnhancerByMockitoWithCGLIB$$3216e5a5 cannot be returned by getAmount()
getAmount() should return Amount
***
完整测试用例
@RunWith(PowerMockRunner.class)
@PrepareForTest(EntityFileEnricher.class)
public class EntityFileEnricherTest {
@InjectMocks
private EntityFileEnricher fileEnricher;
@Test
public void getInfoWithCredit() throws Exception {
fileEnricher = spy(fileEnricher);
CollectionType collectionType = mock(CollectionType.class);
doReturn(Arrays.asList(collectionType)).when(comsUtil).getPmtCollectionType(any(Order.class));
PaymentMethodType paymentMethod = mock(PaymentMethodType.class);
doReturn(paymentMethod).when(collectionType).getPaymentMethod();
com.example.orders.types.v2.PaymentInstrument paymentIns = mock(com.example.orders.types.v2.PaymentInstrument.class);
doReturn(paymentIns).when(paymentMethod).getPaymentInstrument();
doReturn("buyer_ins_key").when(paymentInstrument).getPaymentInstrumentKey();
EntityTotal entityTotal = mock(EntityTotal.class);
doReturn(entityTotal).when(collectionType).getTotalAmount();
Amount amount = mock(Amount.class);
doReturn(amount).when(entityTotal).getAmount(); // ERROR HERE
doReturn(1.0).when(amount).getValue();
....
entityTotal
是金额字段吗?@silentsudoAmount
是entityTotal
字段。
@RunWith(PowerMockRunner.class)
@PrepareForTest(EntityFileEnricher.class)
public class EntityFileEnricherTest {
@InjectMocks
private EntityFileEnricher fileEnricher;
@Test
public void getInfoWithCredit() throws Exception {
fileEnricher = spy(fileEnricher);
CollectionType collectionType = mock(CollectionType.class);
doReturn(Arrays.asList(collectionType)).when(comsUtil).getPmtCollectionType(any(Order.class));
PaymentMethodType paymentMethod = mock(PaymentMethodType.class);
doReturn(paymentMethod).when(collectionType).getPaymentMethod();
com.example.orders.types.v2.PaymentInstrument paymentIns = mock(com.example.orders.types.v2.PaymentInstrument.class);
doReturn(paymentIns).when(paymentMethod).getPaymentInstrument();
doReturn("buyer_ins_key").when(paymentInstrument).getPaymentInstrumentKey();
EntityTotal entityTotal = mock(EntityTotal.class);
doReturn(entityTotal).when(collectionType).getTotalAmount();
Amount amount = mock(Amount.class);
doReturn(amount).when(entityTotal).getAmount(); // ERROR HERE
doReturn(1.0).when(amount).getValue();
....