I'm trying to write a test for this class its called Receiver :
public void get(People person) {
if(null != person) {
LOG.info("Person with ID " + person.getId() + " received");
processor.process(person);
}else{
LOG.info("Person not received abort!");
}
}
Here is the test :
@Test
public void testReceivePerson(){
context.checking(new Expectations() {{
receiver.get(person);
atLeast(1).of(person).getId();
will(returnValue(String.class));
}});
}
Note: receiver is the instance of Receiver class(real not mock), processor is the instance of Processor class(real not mock) which processes the person(mock object of People class). GetId is a String not int method that is not mistake.
Test fails : unexpected invocation of person.getId()
I'm using jMock any help would be appreciated. As I understood when I call this get
method to execute it properly I need to mock person.getId()
, and I've been sniping around in circles for a while now any help would be appreciated.
If I understand correctly, you have to move the line receiver.get(person); after the scope of context.checking - because this is the execution of your test and not setting expectation. So give this one a go:
@Test
public void testReceivePerson(){
context.checking(new Expectations() {{
atLeast(1).of(person).getId();
will(returnValue(String.class));
}});
receiver.get(person);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With