KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > tests > LegacyBehaviorTests


1 /*
2  * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock.tests;
6
7 import java.io.IOException JavaDoc;
8
9 import junit.framework.AssertionFailedError;
10 import junit.framework.TestCase;
11
12 import org.easymock.MockControl;
13
14 public class LegacyBehaviorTests extends TestCase {
15
16     public void testThrowAfterThrowable() throws IOException JavaDoc {
17
18         MockControl<IMethods> control = MockControl
19                 .createControl(IMethods.class);
20         IMethods mock = control.getMock();
21
22         mock.throwsIOException(0);
23         control.setThrowable(new IOException JavaDoc());
24         control.setThrowable(new IOException JavaDoc(), MockControl.ONE_OR_MORE);
25
26         control.replay();
27
28         try {
29             mock.throwsIOException(0);
30             fail("IOException expected");
31         } catch (IOException JavaDoc expected) {
32         }
33
34         boolean exceptionOccured = true;
35         try {
36             control.verify();
37             exceptionOccured = false;
38         } catch (AssertionFailedError expected) {
39             assertEquals(
40                     "\n Expectation failure on verify:"
41                             + "\n throwsIOException(0): expected: at least 2, actual: 1",
42                     expected.getMessage());
43         }
44
45         if (!exceptionOccured)
46             fail("exception expected");
47
48         try {
49             mock.throwsIOException(0);
50             fail("IOException expected");
51         } catch (IOException JavaDoc expected) {
52         }
53
54         control.verify();
55
56         try {
57             mock.throwsIOException(0);
58             fail("IOException expected");
59         } catch (IOException JavaDoc expected) {
60         }
61
62         control.verify();
63     }
64 }
65
Popular Tags