KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > examples > mailinglist > MockListAction


1 package com.mockobjects.examples.mailinglist;
2
3 import com.mockobjects.MockObject;
4 import com.mockobjects.ExpectationList;
5 import com.mockobjects.MapEntry;
6 import com.mockobjects.ExpectationCounter;
7
8 public class MockListAction extends MockObject implements ListAction {
9     private ExpectationList members = new ExpectationList("MockListAction.members");
10     private ExpectationCounter memberCount = new ExpectationCounter("MockListAction.count");
11     private MailingListException memberException = null;
12
13     public void applyTo(String JavaDoc email, String JavaDoc name) throws MailingListException {
14         memberCount.inc();
15         if (null != memberException) {
16             throw memberException;
17         }
18         members.addActual(constructEntry(email, name));
19     }
20
21     public void addExpectedMember(String JavaDoc email, String JavaDoc name) {
22         members.addExpected(constructEntry(email, name));
23     }
24
25     public void setExpectedMemberCount(int count) {
26         memberCount.setExpected(count);
27     }
28
29     public void setExpectNoMembers() {
30         memberCount.setExpectNothing();
31         members.setExpectNothing();
32     }
33
34     public void setupThrowExceptionOnMember(MailingListException exception) {
35         memberException = exception;
36     }
37
38     private Object JavaDoc constructEntry(String JavaDoc email, String JavaDoc name) {
39         return new MapEntry(email, name);
40     }
41 }
42
Popular Tags