| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TestExample |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Created on Jun 28, 2004 | |
| 3 | * | |
| 4 | * To change the template for this generated file go to | |
| 5 | * Window - Preferences - Java - Code Generation - Code and Comments | |
| 6 | */ | |
| 7 | package biz.xsoftware.examples.listener2; | |
| 8 | ||
| 9 | import junit.framework.TestCase; | |
| 10 | import biz.xsoftware.mock.MockObjectFactory; | |
| 11 | import biz.xsoftware.mock.MockObject; | |
| 12 | ||
| 13 | /** | |
| 14 | * This example has the following tests | |
| 15 | * | |
| 16 | * testBasicListener | |
| 17 | * | |
| 18 | * When we create SysUnderTest, in setup we expected it to add | |
| 19 | * a LegacyDisplayListener to the legacy system. In setup, we retrieved | |
| 20 | * that listener so in the test we can now fire display update events | |
| 21 | * and make sure the system does update the display. | |
| 22 | * | |
| 23 | * testTwoClearEvents | |
| 24 | * | |
| 25 | * In this test, we want to make sure that if the legacy system fires | |
| 26 | * two clear events the system still works and there are no exceptions from | |
| 27 | * our system back to the legacy system. | |
| 28 | * | |
| 29 | * @author Dean Hiller | |
| 30 | */ | |
| 31 | public class TestExample extends TestCase { | |
| 32 | ||
| 33 | private MockObject mockUserSvc; | |
| 34 | private UserReplicationService sysUnderTest; | |
| 35 | private UserListener userListener; | |
| 36 | ||
| 37 | /** | |
| 38 | * @showcode | |
| 39 | */ | |
| 40 | public TestExample(String name) { | |
| 41 | 2 | super(name); |
| 42 | 2 | } |
| 43 | /** | |
| 44 | * @showcode | |
| 45 | */ | |
| 46 | @Override | |
| 47 | public void setUp() { | |
| 48 | 2 | mockUserSvc = MockObjectFactory.createMock(UserService.class); |
| 49 | ||
| 50 | //Create the System Under Test using dependency injection.... | |
| 51 | 2 | sysUnderTest = new UserReplicationServiceImpl((UserService)mockUserSvc); |
| 52 | ||
| 53 | //As soon as we create the System Under Test, we expect the | |
| 54 | //SysUnderTest will add a DisplayListener to the legacy system. | |
| 55 | //We then retrieve that implementation of DisplayListener here | |
| 56 | //for later use.... | |
| 57 | 2 | Object[] params = mockUserSvc.expect("addUserListener").getAllParams(); |
| 58 | 2 | userListener = (UserListener)params[0]; |
| 59 | 2 | } |
| 60 | ||
| 61 | @Override | |
| 62 | public void tearDown() { | |
| 63 | ||
| 64 | 2 | } |
| 65 | ||
| 66 | /** | |
| 67 | * When we create SysUnderTest, in setup we expected it to add | |
| 68 | * a UserListener to the UserService. In setup, we retrieved | |
| 69 | * that listener so in the test we can now fire user added events | |
| 70 | * and make sure the system does replicate users | |
| 71 | * | |
| 72 | * @showcode | |
| 73 | */ | |
| 74 | public void testAddUser() { | |
| 75 | 1 | String user="fakeUser1"; |
| 76 | 1 | assertFalse(sysUnderTest.doesUserExist(user)); |
| 77 | 1 | userListener.userAdded(user); |
| 78 | ||
| 79 | //verify it was updated | |
| 80 | 1 | assertTrue(sysUnderTest.doesUserExist(user)); |
| 81 | 1 | } |
| 82 | ||
| 83 | /** | |
| 84 | * In this test, we want to make sure if the UserService fires addUser and | |
| 85 | * then fires deleteUser that our user does not exist in | |
| 86 | * UserReplicationService | |
| 87 | * | |
| 88 | * @showcode | |
| 89 | */ | |
| 90 | public void testAddDeleteUser() { | |
| 91 | 1 | String user="fakeUser3"; |
| 92 | 1 | assertFalse(sysUnderTest.doesUserExist(user)); |
| 93 | 1 | userListener.userAdded(user); |
| 94 | ||
| 95 | //verify it was updated | |
| 96 | 1 | assertTrue(sysUnderTest.doesUserExist(user)); |
| 97 | ||
| 98 | 1 | userListener.userDeleted(user); |
| 99 | 1 | assertFalse(sysUnderTest.doesUserExist(user)); |
| 100 | 1 | } |
| 101 | ||
| 102 | } |