5bfca072d2cc20cf4779eb5dc3c303c3766829d1
[utils] /
1 /*
2  * Copyright 2007 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 package org.wamblee.system.core;
17
18 import java.io.Serializable;
19
20 import org.wamblee.system.core.DefaultProvidedInterface;
21 import org.wamblee.system.core.DefaultRequiredInterface;
22 import org.wamblee.system.core.ProvidedInterface;
23 import org.wamblee.system.core.RequiredInterface;
24
25 import junit.framework.TestCase;
26
27 public class DefaultInterfaceDescriptorTest extends TestCase {
28
29         public void testOneRequiredOneProvidedMatch() { 
30                 ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
31                 RequiredInterface required = new DefaultRequiredInterface("name", String.class);
32                 assertTrue(required.implementedBy(provided));
33         }
34         
35         public void testOneRequiredOneProvidedMatchSubClass() { 
36                 ProvidedInterface provided = new DefaultProvidedInterface("name", Integer.class);
37                 RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
38                 assertTrue(required.implementedBy(provided));
39         }
40         
41         public void testOneRequiredOneProvidedNoMatch() { 
42                 ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
43                 RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
44                 assertFalse(required.implementedBy(provided));
45         }
46         
47         public void testOneRequiredMultipleProvidedMatch() { 
48                 ProvidedInterface provided = new DefaultProvidedInterface("name", 
49                                 new Class[] { String.class, Integer.class} );
50                 RequiredInterface required = new DefaultRequiredInterface("name", String.class);
51                 assertTrue(required.implementedBy(provided));
52         }
53         
54         private static class MyMultiple implements Runnable, Serializable { 
55                 @Override
56                 public void run() {
57                         // Empty        
58                 }
59         }
60         
61         public void testMultipleRequiredOneProvidedMatch() { 
62                 ProvidedInterface provided = new DefaultProvidedInterface("name", 
63                                 MyMultiple.class );
64                 RequiredInterface required = new DefaultRequiredInterface("name", 
65                                 new Class[] {Runnable.class, Serializable.class} );
66                 assertTrue(required.implementedBy(provided));
67         }
68         
69         public void testMultipleRequiredOneProvidedNoMatch() { 
70                 ProvidedInterface provided = new DefaultProvidedInterface("name", 
71                                 MyMultiple.class );
72                 RequiredInterface required = new DefaultRequiredInterface("name", 
73                                 new Class[] { String.class, Runnable.class} );
74                 assertFalse(required.implementedBy(provided));
75         }
76         
77         public void testMultipleRequiredMultipleProvidedMatch() { 
78                 ProvidedInterface provided = new DefaultProvidedInterface("name", 
79                                 new Class[] { Runnable.class, Serializable.class, String.class}  );
80                 RequiredInterface required = new DefaultRequiredInterface("name", 
81                                 new Class[] {Runnable.class, Serializable.class} );
82                 assertTrue(required.implementedBy(provided));
83         }
84         
85         public void testPrimitiveAndWrapperType() { 
86                 RequiredInterface req1 = new DefaultRequiredInterface("req1", int.class);
87                 RequiredInterface req2 = new DefaultRequiredInterface("req1", Integer.class);
88                 ProvidedInterface prov1 = new DefaultProvidedInterface("prov1", int.class);
89                 ProvidedInterface prov2 = new DefaultProvidedInterface("prov2", Integer.class);
90                 assertTrue(req1.implementedBy(prov1));
91                 assertTrue(req2.implementedBy(prov1));
92                 assertTrue(req1.implementedBy(prov2));
93                 assertTrue(req2.implementedBy(prov2));
94         }
95         
96 }