01: /*
02: * Copyright (C) The DNA Group. All rights reserved.
03: *
04: * This software is published under the terms of the DNA
05: * Software License version 1.1, a copy of which has been included
06: * with this distribution in the LICENSE.txt file.
07: */
08: package org.codehaus.dna.impl;
09:
10: import junit.framework.TestCase;
11:
12: import org.codehaus.dna.MissingResourceException;
13: import org.codehaus.dna.impl.DefaultResourceLocator;
14:
15: public class DefaultResourceLocatorTestCase extends TestCase {
16: public void testLookupMissingResourceWithNoParent()
17: throws Exception {
18: final DefaultResourceLocator locator = new DefaultResourceLocator();
19: assertEquals("locator.contains(rez) post to insert", false,
20: locator.contains("rez"));
21:
22: try {
23: locator.lookup("rez");
24: } catch (MissingResourceException e) {
25: return;
26: }
27: fail("Expected to fail looking up missing resource");
28: }
29:
30: public void testLookupMissingResourceWithParent() throws Exception {
31: final DefaultResourceLocator parent = new DefaultResourceLocator();
32: final DefaultResourceLocator locator = new DefaultResourceLocator(
33: parent);
34: assertEquals("locator.contains(rez) post to insert", false,
35: locator.contains("rez"));
36:
37: try {
38: locator.lookup("rez");
39: } catch (MissingResourceException e) {
40: return;
41: }
42: fail("Expected to fail looking up missing resource");
43: }
44:
45: public void testLookupResourceInLocalLocator() throws Exception {
46: final Object resource = new Object();
47: final DefaultResourceLocator locator = new DefaultResourceLocator();
48: locator.put("rez", resource);
49: assertEquals("locator.contains(rez) post to insert", true,
50: locator.contains("rez"));
51:
52: final Object result = locator.lookup("rez");
53: assertEquals("locator.contains(rez) == resource", resource,
54: result);
55: }
56:
57: public void testLookupResourceInParentLocator() throws Exception {
58: final Object resource = new Object();
59: final DefaultResourceLocator parent = new DefaultResourceLocator();
60: final DefaultResourceLocator locator = new DefaultResourceLocator(
61: parent);
62: parent.put("rez", resource);
63: assertEquals("locator.contains(rez) post to insert", true,
64: locator.contains("rez"));
65:
66: final Object result = locator.lookup("rez");
67: assertEquals("locator.contains(rez) == resource", resource,
68: result);
69: }
70:
71: public void testPutWithNullKey() throws Exception {
72: final DefaultResourceLocator locator = new DefaultResourceLocator();
73: try {
74: locator.put(null, new Object());
75: } catch (NullPointerException e) {
76: assertEquals("key", e.getMessage());
77: return;
78: }
79: fail("Expect to fail to put resource with null key");
80: }
81:
82: public void testPutWithNullResource() throws Exception {
83: final DefaultResourceLocator locator = new DefaultResourceLocator();
84: try {
85: locator.put("rez", null);
86: } catch (NullPointerException e) {
87: assertEquals("resource", e.getMessage());
88: return;
89: }
90: fail("Expect to fail to put resource with null resource");
91: }
92: }
|