Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mockito错误,如单位案例上的org.Mockito.exceptions.misusing.ErrorTypeOfReturnValue_Java_Mockito - Fatal编程技术网

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
是金额字段吗?@silentsudo
Amount
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();
        ....