The verify property is used within an Exemplar to expect that a given interaction takes place. Verify expressions are exactly the same as stub matching expressions; for more details on these see the Stub Match Expression section within the Test Isolation section of this guide.
For instance, returning to the example in the Test Isolation section, consider a booking system method that cancels a given booking. This calls a method on a service delegate that calls out to a remote service EJB to cancel a seat:
@Exemplar(args={"Booking/i1"}, expect="$arg1.isCancelled") public void cancelBooking(Booking booking) throws SeatNotFoundException { ... try { List<Integer> seatIDs = booking.getSeatIDs(); for (int seatID : seatIDs) { seatServiceDelegate.cancelSeat(seatID); } booking.setCancelled(); } catch (NamingException e) { throw new TechnicalException(e); } catch (RemoteException e) { throw new TechnicalException(e); } ... } public class SeatServiceDelegate { InitialContext ctx; ... public void cancelSeat(int seatID) throws NamingException, RemoteException, SeatNotFoundException { // Access remote service to cancel the given seat SeatService service = (SeatService) ctx.lookup("SeatService"); service.cancel(seatID); } ... }
We might want to verify that the SeatServiceDelegate.cancelSeat method is called. This is achevied by including a verify property:
@Exemplar(args={"Booking/i1"}, expect="$arg1.isCancelled", verify="SeatServiceDelegate.cancel(int)") public void cancelBooking(Booking booking) throws SeatNotFoundException { ... }
Alternatively we might want to verify that the cancel method is called with a seatID of over 5:
@Exemplar(args={"Booking/i1"}, expect="$arg1.isCancelled", verify="SeatServiceDelegate.cancel(>(arg,5))") public void cancelBooking(Booking booking) throws SeatNotFoundException { ... }