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 email, String 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 email, String 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 constructEntry(String email, String name) { 39 return new MapEntry(email, name); 40 } 41 } 42 | Popular Tags |