KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > atest > jmock > ExpectNeverAcceptanceTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package atest.jmock;
4
5 import org.jmock.Mock;
6 import org.jmock.MockObjectTestCase;
7 import org.jmock.core.DynamicMockError;
8
9
10 public class ExpectNeverAcceptanceTest
11         extends MockObjectTestCase
12 {
13     private static interface MockedInterface {
14         public void method();
15     }
16
17     public void testExpectNotCalledOverridesStubAndFailsIfCalled() {
18         Mock mock = mock(MockedInterface.class, "mock");
19
20         mock.stubs().method("method").withNoArguments();
21         mock.expects(never()).method("method").withNoArguments();
22
23         try {
24             ((MockedInterface)mock.proxy()).method();
25         }
26         catch (DynamicMockError error) {
27             return;
28         }
29         fail("DynamicMockError expected");
30     }
31
32     public void testExpectNotCalledVerifiesIfNotCalled() {
33         Mock mock = mock(MockedInterface.class, "mock");
34
35         mock.stubs().method("method").withNoArguments().isVoid();
36         mock.expects(never()).method("method").withNoArguments();
37     }
38 }
39
Popular Tags