2 * Copyright 2007 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.core;
18 import java.io.Serializable;
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;
25 import junit.framework.TestCase;
27 public class DefaultInterfaceDescriptorTest extends TestCase {
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));
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));
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));
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));
54 private static class MyMultiple implements Runnable, Serializable {
61 public void testMultipleRequiredOneProvidedMatch() {
62 ProvidedInterface provided = new DefaultProvidedInterface("name",
64 RequiredInterface required = new DefaultRequiredInterface("name",
65 new Class[] {Runnable.class, Serializable.class} );
66 assertTrue(required.implementedBy(provided));
69 public void testMultipleRequiredOneProvidedNoMatch() {
70 ProvidedInterface provided = new DefaultProvidedInterface("name",
72 RequiredInterface required = new DefaultRequiredInterface("name",
73 new Class[] { String.class, Runnable.class} );
74 assertFalse(required.implementedBy(provided));
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));
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));