--- /dev/null
+/*
+ * Copyright 2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.core;
+
+import java.io.Serializable;
+
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.DefaultRequiredInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+
+import junit.framework.TestCase;
+
+public class DefaultInterfaceDescriptorTest extends TestCase {
+
+ public void testOneRequiredOneProvidedMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedMatchSubClass() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name", Integer.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedNoMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredMultipleProvidedMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
+ new Class[] { String.class, Integer.class} );
+ RequiredInterface required = new DefaultRequiredInterface("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ private static class MyMultiple implements Runnable, Serializable {
+ @Override
+ public void run() {
+ // Empty
+ }
+ }
+
+ public void testMultipleRequiredOneProvidedMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
+ MyMultiple.class );
+ RequiredInterface required = new DefaultRequiredInterface("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredOneProvidedNoMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
+ MyMultiple.class );
+ RequiredInterface required = new DefaultRequiredInterface("name",
+ new Class[] { String.class, Runnable.class} );
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredMultipleProvidedMatch() {
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
+ new Class[] { Runnable.class, Serializable.class, String.class} );
+ RequiredInterface required = new DefaultRequiredInterface("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+
+}