JMock inattendu invocation
Ci-dessous, j'essaie juste de se moquer d'une classe nommée TestWrapper et la valeur "permettant" expecations sur elle. Cependant, lors de la définition des attentes j'obtiens l'erreur. Lors de l'utilisation d'easymock et tout simplement la mise en attentes, cela ne semble pas se produire
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Before;
import org.junit.Test;
import java.math.BigDecimal;
public class CustomerPaymentProgramConverterTest {
TestWrapper paymentType;
Mockery mockery = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
@Before
public void setupMethod() {
paymentType = mockery.mock(TestWrapper.class);
}
@Test
public void testFromWebService() {
mockery.checking(new Expectations() {{
//debugger throws error on the line below.
allowing(paymentType.getScheduledPaymentAmount());
will(returnValue(new BigDecimal(123)));
allowing(paymentType.getScheduledPaymentConfirmationNumber());
will(returnValue(121212L));
}});
}
}
TestWrapper.class
//Class I am mocking using JMock
public class TestWrapper {
public java.math.BigDecimal getScheduledPaymentAmount() {
return new BigDecimal(123);
}
public long getScheduledPaymentConfirmationNumber() {
return 123L;
}
}
Erreur D'Assertion..
java.lang.AssertionError: unexpected invocation: paymentProgramScheduledPaymentTypeTestWrapper.getScheduledPaymentAmount()
no expectations specified: did you...
- forget to start an expectation with a cardinality clause?
- call a mocked method to specify the parameter of an expectation?
what happened before this: nothing!
at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56)
at org.jmock.Mockery.dispatch(Mockery.java:218)
at org.jmock.Mockery.access$000(Mockery.java:43)
at org.jmock.Mockery$MockObject.invoke(Mockery.java:258)
Je crois que c'est la classe d'erreur le message fait allusion quand il vous demande "avez-vous" "appeler un moqué de méthode pour spécifier le paramètre d'une attente?"
OriginalL'auteur Himalay Majumdar | 2011-11-14
Vous devez vous connecter pour publier un commentaire.
Vous êtes à l'aide de la JMock API de manière incorrecte. Il devrait être
C'est dire que lorsque vous appelez la méthode en cours de test (que vous ne semblez pas être en train de faire dans votre test) vous attendent des appels à ces méthodes pour le retour de ces valeurs. Le PaymentType serait une dépendance dans votre classe de test qui vous sont habitées.
Voir JMock Prise En Main
Aussi, vous avez une compliation de l'erreur dans la méthode @before
OriginalL'auteur blank