01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.net.URL;
18:
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.ioc.Resource;
21: import org.apache.tapestry.services.Context;
22: import org.testng.annotations.Test;
23:
24: public class ContextResourceTest extends InternalBaseTestCase {
25: @Test
26: public void get_url() throws Exception {
27: URL url = getClass().getResource("ContextResourceTest.class");
28:
29: Context context = mockContext();
30:
31: expect(context.getResource("/foo/Bar.txt")).andReturn(url);
32:
33: replay();
34:
35: Resource r = new ContextResource(context, "foo/Bar.txt");
36:
37: assertSame(r.toURL(), url);
38:
39: verify();
40: }
41:
42: @Test
43: public void to_string() {
44: Context context = mockContext();
45:
46: replay();
47:
48: Resource r = new ContextResource(context, "foo/Bar.txt");
49:
50: assertEquals(r.toString(), "context:foo/Bar.txt");
51:
52: verify();
53: }
54:
55: @Test
56: public void hash_code() {
57: Context context1 = mockContext();
58: Context context2 = mockContext();
59:
60: replay();
61:
62: Resource r1 = new ContextResource(context1, "foo");
63: Resource r2 = new ContextResource(context1, "foo");
64: Resource r3 = new ContextResource(context2, "foo");
65: Resource r4 = new ContextResource(context1, "bar");
66:
67: assertTrue(r1.hashCode() == r2.hashCode());
68: assertFalse(r1.hashCode() == r3.hashCode());
69: assertFalse(r1.hashCode() == r4.hashCode());
70:
71: verify();
72: }
73:
74: @Test
75: public void equals() {
76: Context context1 = mockContext();
77: Context context2 = mockContext();
78: Resource r = mockResource();
79:
80: replay();
81:
82: Resource r1 = new ContextResource(context1, "foo");
83: Resource r2 = new ContextResource(context1, "foo");
84: Resource r3 = new ContextResource(context2, "foo");
85: Resource r4 = new ContextResource(context1, "bar");
86:
87: assertTrue(r1.equals(r2));
88: assertFalse(r1.equals(r3));
89: assertFalse(r1.equals(r4));
90:
91: assertFalse(r1.equals(null));
92: assertTrue(r1.equals(r1));
93:
94: assertFalse(r1.equals(r));
95:
96: verify();
97: }
98: }
|