001 /*
002 * Created on Jun 28, 2004
003 *
004 * To change the template for this generated file go to
005 * Window - Preferences - Java - Code Generation - Code and Comments
006 */
007 package biz.xsoftware.examples.listener2;
008
009 import junit.framework.TestCase;
010 import biz.xsoftware.mock.MockObjectFactory;
011 import biz.xsoftware.mock.MockObject;
012
013 /**
014 * This example has the following tests
015 *
016 * testBasicListener
017 *
018 * When we create SysUnderTest, in setup we expected it to add
019 * a LegacyDisplayListener to the legacy system. In setup, we retrieved
020 * that listener so in the test we can now fire display update events
021 * and make sure the system does update the display.
022 *
023 * testTwoClearEvents
024 *
025 * In this test, we want to make sure that if the legacy system fires
026 * two clear events the system still works and there are no exceptions from
027 * our system back to the legacy system.
028 *
029 * @author Dean Hiller
030 */
031 public class TestExample extends TestCase {
032
033 private MockObject mockUserSvc;
034 private UserReplicationService sysUnderTest;
035 private UserListener userListener;
036
037 /**
038 * @showcode
039 */
040 public TestExample(String name) {
041 super(name);
042 }
043 /**
044 * @showcode
045 */
046 @Override
047 public void setUp() {
048 mockUserSvc = MockObjectFactory.createMock(UserService.class);
049
050 //Create the System Under Test using dependency injection....
051 sysUnderTest = new UserReplicationServiceImpl((UserService)mockUserSvc);
052
053 //As soon as we create the System Under Test, we expect the
054 //SysUnderTest will add a DisplayListener to the legacy system.
055 //We then retrieve that implementation of DisplayListener here
056 //for later use....
057 Object[] params = mockUserSvc.expect("addUserListener").getAllParams();
058 userListener = (UserListener)params[0];
059 }
060
061 @Override
062 public void tearDown() {
063
064 }
065
066 /**
067 * When we create SysUnderTest, in setup we expected it to add
068 * a UserListener to the UserService. In setup, we retrieved
069 * that listener so in the test we can now fire user added events
070 * and make sure the system does replicate users
071 *
072 * @showcode
073 */
074 public void testAddUser() {
075 String user="fakeUser1";
076 assertFalse(sysUnderTest.doesUserExist(user));
077 userListener.userAdded(user);
078
079 //verify it was updated
080 assertTrue(sysUnderTest.doesUserExist(user));
081 }
082
083 /**
084 * In this test, we want to make sure if the UserService fires addUser and
085 * then fires deleteUser that our user does not exist in
086 * UserReplicationService
087 *
088 * @showcode
089 */
090 public void testAddDeleteUser() {
091 String user="fakeUser3";
092 assertFalse(sysUnderTest.doesUserExist(user));
093 userListener.userAdded(user);
094
095 //verify it was updated
096 assertTrue(sysUnderTest.doesUserExist(user));
097
098 userListener.userDeleted(user);
099 assertFalse(sysUnderTest.doesUserExist(user));
100 }
101
102 }
|