// Tags: JDK1.4 // Copyright (C) 2004 Sascha Brawer // This file is part of Mauve. // Mauve is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // Mauve is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Mauve; see the file COPYING. If not, write to // the Free Software Foundation, 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. package gnu.testlet.javax.imageio.spi.ServiceRegistry; import gnu.testlet.Testlet; import gnu.testlet.TestHarness; import java.util.*; import javax.imageio.spi.RegisterableService; import javax.imageio.spi.ServiceRegistry; /** * @author Sascha Brawer */ public class setOrdering 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(List.class, "foo", "bar"); } 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. h.check(registry.setOrdering(String.class, "cow", "sheep")); // Check #4. h.check(registry.setOrdering(String.class, "sheep", "goat")); // Check #5. Iterator iter = registry.getServiceProviders(String.class, true); h.check(iter.next(), "cow"); // Check #6. h.check(iter.next(), "sheep"); // Check #7. h.check(iter.next(), "goat"); // Check #8. h.check(!iter.hasNext()); } }