From: erik Date: Fri, 28 Mar 2008 23:18:20 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2@603~222 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=8e09c2df22e6f0937a1feb3ed3af4c1e20669776;p=utils --- diff --git a/trunk/system/general/src/main/java/org/wamblee/system/ProvidedServiceDescriptor.java b/trunk/system/general/src/main/java/org/wamblee/system/ProvidedServiceDescriptor.java new file mode 100644 index 00000000..94eb43d0 --- /dev/null +++ b/trunk/system/general/src/main/java/org/wamblee/system/ProvidedServiceDescriptor.java @@ -0,0 +1,7 @@ +package org.wamblee.system; + +import java.util.Collection; + +public interface ProvidedServiceDescriptor extends ServiceDescriptor { + // Empty +} diff --git a/trunk/system/general/src/test/java/org/wamblee/system/DefaultServiceDescriptorTest.java b/trunk/system/general/src/test/java/org/wamblee/system/DefaultServiceDescriptorTest.java new file mode 100644 index 00000000..b222d28d --- /dev/null +++ b/trunk/system/general/src/test/java/org/wamblee/system/DefaultServiceDescriptorTest.java @@ -0,0 +1,66 @@ +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)); + } + + +}