This library allows you to use JavaBeans-style property matching for arguments when using EasyMock. Property matching is based on commons-beanutils as documented in Standard JavaBeans.
It's a TestNG test class with two test methods. The first, testSayHelloTo() uses the single-property matcher test. The second, testSay() uses the multiple-property matcher test by supplying a Map of property names to property values.
package test;
import static com.stephenduncanjr.easymock.EasyMockPropertyUtils.propEq;
/**
* Test the Service class.
*/
public class ServiceTest
{
/**
* Test the sayHelloTo method.
*/
@Test
public void testSayHelloTo()
{
String address = "someone@example.com";
MessagingService messagingService = createMock(MessagingService.class);
messagingService.sendMessage(propEq(Message.class, "address", address));
replay(messagingService);
Service service = new Service();
service.setMessagingService(messagingService);
service.sayHelloTo(address);
verify(messagingService);
}
/**
* Test the say method.
*/
@Test
public void testSay()
{
String address = "someone@example.com";
String text = "some text";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("address", address);
properties.put("message", text);
MessagingService messagingService = createMock(MessagingService.class);
messagingService.sendMessage(propEq(Message.class, properties));
replay(messagingService);
Service service = new Service();
service.setMessagingService(messagingService);
service.say(address, text);
verify(messagingService);
}
/**
* Test the say method.
*/
@Test
public void testSayAgain()
{
String address = "someone@example.com";
String text = "some text";
Message message = new Message();
message.setAddress(address);
message.setMessage(text);
MessagingService messagingService = createMock(MessagingService.class);
messagingService.sendMessage(propEq(message));
replay(messagingService);
Service service = new Service();
service.setMessagingService(messagingService);
service.say(address, text);
verify(messagingService);
}
}