implements Testlet
{
public void test(TestHarness h)
{
Throwable caught;
ServiceRegistry registry;
List categories;
// Set-up.
categories = new LinkedList();
categories.add(String.class);
categories.add(RegisterableService.class);
registry = new ServiceRegistry(categories.iterator());
registry.registerServiceProvider("sheep", String.class);
registry.registerServiceProvider("goat", String.class);
registry.registerServiceProvider("cow", String.class);
// Check #1: Unknown category --> IllegalArgumentException.
caught = null;
try
{
registry.setOrdering(String.class, "foo", null);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught instanceof IllegalArgumentException);
// Check #2: Twice the same object --> IllegalArgumentException.
caught = null;
try
{
registry.setOrdering(String.class, "sheep", "sheep");
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught instanceof IllegalArgumentException);
// Check #3. Fails on JDK 1.4.1_01.
h.check(registry.setOrdering(String.class, "cow", "sheep"));
// Check #4. Fails on JDK 1.4.1_01.
h.check(registry.setOrdering(String.class, "sheep", "goat"));
// Check #5.
h.check(!registry.setOrdering(String.class, "sheep", "goat"));
// Check #6.
h.check(!registry.setOrdering(String.class, "cow", "sheep"));
// Check #7. Fails on JDK 1.4.1_01.
h.check(registry.unsetOrdering(String.class, "cow", "sheep"));
// Check #8.
h.check(!registry.unsetOrdering(String.class, "cow", "sheep"));
// Check #9. Fails on JDK 1.4.1_01.
h.check(registry.setOrdering(String.class, "cow", "sheep"));
}