--- /dev/null
+package org.wamblee.system;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+public class DefaultServiceDescriptorTest extends TestCase {
+
+ public void testOneRequiredOneProvidedMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", String.class);
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedMatchSubClass() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", Integer.class);
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", Number.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredOneProvidedNoMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name", String.class);
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", Number.class);
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testOneRequiredMultipleProvidedMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
+ new Class[] { String.class, Integer.class} );
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name", String.class);
+ assertTrue(required.implementedBy(provided));
+ }
+
+ private static class MyMultiple implements Runnable, Serializable {
+ @Override
+ public void run() {
+ // Empty
+ }
+ }
+
+ public void testMultipleRequiredOneProvidedMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
+ MyMultiple.class );
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredOneProvidedNoMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
+ MyMultiple.class );
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
+ new Class[] { String.class, Runnable.class} );
+ assertFalse(required.implementedBy(provided));
+ }
+
+ public void testMultipleRequiredMultipleProvidedMatch() {
+ ProvidedServiceDescriptor provided = new DefaultProvidedServiceDescriptor("name",
+ new Class[] { Runnable.class, Serializable.class, String.class} );
+ RequiredServiceDescriptor required = new DefaultRequiredServiceDescriptor("name",
+ new Class[] {Runnable.class, Serializable.class} );
+ assertTrue(required.implementedBy(provided));
+ }
+
+
+}