1   // Copyright (c) 2003, Chad Woolley, All rights reserved.
2   
3   package org.virtualmock.rule;
4   
5   import junit.framework.Test;
6   import org.hansel.CoverageDecorator;
7   import org.virtualmock.call.RecordedCall;
8   import org.virtualmock.call.Signature;
9   import org.virtualmock.resource.ResourceKeys;
10  import org.virtualmock.test.testcase.EasyMockTestCase;
11  
12  
13  /***
14   * DOCUMENT ME! (Class)
15   *
16   * @author Chad Woolley
17   * @version $Revision: 1.6 $
18   */
19  public class AllRecordedCallsMustBeInvokedRuleTest extends EasyMockTestCase {
20      Rule rule = null;
21      private String key;
22      private int enforcementLevel = -1;
23  
24      /***
25       * Hansel support
26       *
27       * @return the decorated Test
28       */
29      public static Test suite() {
30          CoverageDecorator cd =
31              new CoverageDecorator(AllRecordedCallsMustBeInvokedRuleTest.class,
32                  new Class[] {AllRecordedCallsMustBeInvokedRule.class});
33          cd.setDisplayStatistics(true);
34  
35          return cd;
36      }
37  
38      /***
39       * Set up the test
40       *
41       * @throws Exception any exception thrown during setup.
42       */
43      public void setUp() throws Exception {
44          super.setUp();
45          key = "rulekey";
46          enforcementLevel = Rule.FAIL;
47          rule =
48              new AllRecordedCallsMustBeInvokedRule(key, enforcementLevel,
49                  mockCallManager, mockResourceManager);
50      }
51  
52      /***
53       * Test the getEnforcementLevel method
54       */
55      public void testCanGetEnforcementLevel() {
56          assertEquals(enforcementLevel, rule.getEnforcementLevel());
57      }
58  
59      /***
60       * Test the getKey method
61       */
62      public void testCanGetKey() {
63          assertEquals(key, rule.getKey());
64      }
65  
66      /***
67       * Test the getViolationMessages method
68       */
69      public void testGetViolationMessages() {
70          RecordedCall[] calls = new RecordedCall[1];
71          Signature signature = new Signature(Object.class, "myMethod");
72          RecordedCall recordedCall = new RecordedCall(signature);
73          calls[0] = recordedCall;
74  
75          mockCallManager.getUninvokedCalls();
76          controlCallManager.setReturnValue(calls);
77  
78          String expectedMessage = "THIS IS THE EXPECTED MESSAGE";
79          mockResourceManager.getString(ResourceKeys.RULE_FAIL_ALL_RECORDED_CALLS_MUST_BE_INVOKED,
80              recordedCall.toString());
81          controlResourceManager.setReturnValue(expectedMessage);
82  
83          controlCallManager.replay();
84          controlResourceManager.replay();
85  
86          String message = rule.getViolationMessages()[0];
87          assertEquals(expectedMessage, message);
88  
89          controlCallManager.verify();
90      }
91  }