1
2
3 package org.virtualmock.resource;
4
5 import junit.framework.Test;
6 import junit.framework.TestCase;
7 import junit.framework.TestSuite;
8 import org.virtualmock.resource.ResourceKeys;
9 import org.virtualmock.resource.ResourceManager;
10
11
12 /***
13 * Tests the AlwaysMatcher class
14 *
15 * @author Chad Woolley
16 * @version $Revision: 1.1 $
17 */
18 public class ResourceManagerTest extends TestCase {
19 ResourceManager resourceManager = null;
20
21 /***
22 * Test constructor
23 *
24 * @param testTitle title of the test
25 */
26 public ResourceManagerTest(String testTitle) {
27 super(testTitle);
28 }
29
30 /***
31 * Set up the test
32 *
33 * @throws Exception any exception thrown during setup.
34 */
35 public void setUp() throws Exception {
36 super.setUp();
37 resourceManager = new ResourceManager("virtualmock", "en", "US");
38 }
39
40 /***
41 * Hansel support
42 *
43 * @return the decorated Test
44 *
45 * @todo re-enable Hansel when resource bundle issues are resolved
46 */
47 public static Test suite() {
48
49
50
51
52
53
54
55 TestSuite suite = new TestSuite("ResourceManagerTest");
56 suite.addTestSuite(ResourceManagerTest.class);
57
58 return suite;
59 }
60
61 /***
62 * Tear down the test
63 *
64 * @throws Exception any exception thrown during teardown.
65 */
66 public void tearDown() throws Exception {
67 super.tearDown();
68 }
69
70 /***
71 * Test the getString method with four args
72 */
73 public void testCanGetStringWithFourArgs() {
74 assertEquals("Four args AAA BBB CCC DDD",
75 resourceManager.getString("unittest.dummy4", "AAA", "BBB", "CCC",
76 "DDD"));
77 }
78
79 /***
80 * Test the getString method with one arg
81 */
82 public void testCanGetStringWithOneArg() {
83 assertTrue(resourceManager.getString(
84 ResourceKeys.RULE_FAIL_ALL_RECORDED_CALLS_MUST_BE_INVOKED,
85 "XXX").endsWith("XXX"));
86 }
87
88 /***
89 * Test the getString method with three args
90 */
91 public void testCanGetStringWithThreeArgs() {
92 assertEquals("Three args AAA BBB CCC",
93 resourceManager.getString("unittest.dummy3", "AAA", "BBB", "CCC"));
94 }
95
96 /***
97 * Test the getString method with two args
98 */
99 public void testCanGetStringWithTwoArgs() {
100 assertEquals("Two args AAA BBB",
101 resourceManager.getString("unittest.dummy2", "AAA", "BBB"));
102 }
103
104 /***
105 * Tests that init() will only initialize once. This test is really just
106 * to provide Hansel coverage.
107 */
108 public void testCanOnlyInitializeOnce() {
109 resourceManager.getString(ResourceKeys.RULE_FAIL_ALL_RECORDED_CALLS_MUST_BE_INVOKED);
110 resourceManager.getString(ResourceKeys.RULE_FAIL_ALL_RECORDED_CALLS_MUST_BE_INVOKED);
111 }
112
113 /***
114 * Test the getString method
115 */
116 public void testGetString() {
117 assertNotNull(resourceManager.getString(
118 ResourceKeys.RULE_FAIL_ALL_RECORDED_CALLS_MUST_BE_INVOKED));
119 }
120
121 /***
122 * Test the getString method fails if key is not found
123 */
124 public void testGetStringFailsIfKeyNotFound() {
125 try {
126 resourceManager.getString("xxx");
127 fail("Expected exception");
128 } catch (RuntimeException e) {
129 }
130 }
131 }