1 /*
2 * Copyright (C) The JContainer Group. All rights reserved.
3 *
4 * This software is published under the terms of the JContainer
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.jcontainer.dna.impl;
9
10 import junit.framework.TestCase;
11 import org.jcontainer.dna.MissingResourceException;
12
13 public class DefaultResourceLocatorTestCase
14 extends TestCase
15 {
16 public void testLookupMissingResourceWithNoParent()
17 throws Exception
18 {
19 final DefaultResourceLocator locator = new DefaultResourceLocator();
20 assertEquals( "locator.contains(rez) post to insert",
21 false,
22 locator.contains( "rez" ) );
23
24 try
25 {
26 locator.lookup( "rez" );
27 }
28 catch( MissingResourceException e )
29 {
30 return;
31 }
32 fail( "Expected to fail looking up missing resource" );
33 }
34
35 public void testLookupMissingResourceWithParent()
36 throws Exception
37 {
38 final DefaultResourceLocator parent = new DefaultResourceLocator();
39 final DefaultResourceLocator locator = new DefaultResourceLocator( parent );
40 assertEquals( "locator.contains(rez) post to insert",
41 false,
42 locator.contains( "rez" ) );
43
44 try
45 {
46 locator.lookup( "rez" );
47 }
48 catch( MissingResourceException e )
49 {
50 return;
51 }
52 fail( "Expected to fail looking up missing resource" );
53 }
54
55 public void testLookupResourceInLocalLocator()
56 throws Exception
57 {
58 final Object resource = new Object();
59 final DefaultResourceLocator locator = new DefaultResourceLocator();
60 locator.put( "rez", resource );
61 assertEquals( "locator.contains(rez) post to insert",
62 true,
63 locator.contains( "rez" ) );
64
65 final Object result = locator.lookup( "rez" );
66 assertEquals( "locator.contains(rez) == resource",
67 resource, result );
68 }
69
70 public void testLookupResourceInParentLocator()
71 throws Exception
72 {
73 final Object resource = new Object();
74 final DefaultResourceLocator parent = new DefaultResourceLocator();
75 final DefaultResourceLocator locator = new DefaultResourceLocator( parent );
76 parent.put( "rez", resource );
77 assertEquals( "locator.contains(rez) post to insert",
78 true,
79 locator.contains( "rez" ) );
80
81 final Object result = locator.lookup( "rez" );
82 assertEquals( "locator.contains(rez) == resource",
83 resource, result );
84 }
85
86 public void testPutWithNullKey()
87 throws Exception
88 {
89 final DefaultResourceLocator locator = new DefaultResourceLocator();
90 try
91 {
92 locator.put( null, new Object() );
93 }
94 catch( NullPointerException e )
95 {
96 assertEquals( "key", e.getMessage() );
97 return;
98 }
99 fail( "Expect to fail to put resource with null key" );
100 }
101
102 public void testPutWithNullResource()
103 throws Exception
104 {
105 final DefaultResourceLocator locator = new DefaultResourceLocator();
106 try
107 {
108 locator.put( "rez", null );
109 }
110 catch( NullPointerException e )
111 {
112 assertEquals( "resource", e.getMessage() );
113 return;
114 }
115 fail( "Expect to fail to put resource with null resource" );
116 }
117 }
This page was automatically generated by Maven