Need help with writing test
Posted
by London
on Stack Overflow
See other posts from Stack Overflow
or by London
Published on 2010-05-26T11:35:36Z
Indexed on
2010/05/26
11:41 UTC
Read the original article
Hit count: 276
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.
© Stack Overflow or respective owner