(no commit message)
[utils] / system / general / src / test / java / org / wamblee / system / core / DefaultInterfaceDescriptorTest.java
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         
86 }