1 // Tags: JDK1.4 |
|
2 // Uses: TestService |
|
3 |
|
4 // Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 package gnu.testlet.javax.imageio.spi.ServiceRegistry; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 import java.util.List; |
|
29 import java.util.LinkedList; |
|
30 |
|
31 import javax.imageio.spi.RegisterableService; |
|
32 import javax.imageio.spi.ServiceRegistry; |
|
33 |
|
34 /** |
|
35 * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> |
|
36 */ |
|
37 public class registerServiceProvider |
|
38 implements Testlet |
|
39 { |
|
40 public void test(TestHarness h) |
|
41 { |
|
42 Throwable caught; |
|
43 ServiceRegistry registry; |
|
44 SomeService s1 = new SomeService(); |
|
45 TestService s2 = new TestService(); |
|
46 |
|
47 List categories = new LinkedList(); |
|
48 categories.add(SomeService.class); |
|
49 categories.add(RegisterableService.class); |
|
50 registry = new ServiceRegistry(categories.iterator()); |
|
51 |
|
52 // Check #1: Null argument --> IllegalArgumentException. |
|
53 caught = null; |
|
54 try |
|
55 { |
|
56 registry.registerServiceProvider(null); |
|
57 } |
|
58 catch (Exception ex) |
|
59 { |
|
60 caught = ex; |
|
61 } |
|
62 h.check(caught instanceof IllegalArgumentException); |
|
63 |
|
64 // Check #2: Register a service that does not implement |
|
65 // RegisterableService. |
|
66 registry.registerServiceProvider(s1); |
|
67 h.check(registry.contains(s1)); |
|
68 |
|
69 // Check #3: Register a RegisterableService. |
|
70 registry.registerServiceProvider(s2); |
|
71 h.check(registry.contains(s2)); |
|
72 |
|
73 // Check #4. |
|
74 h.check(s2.numRegistrations, 1); |
|
75 |
|
76 // Check #5. |
|
77 h.check(s2.lastRegisteredRegistry, registry); |
|
78 |
|
79 // Check #6. |
|
80 h.check(s2.lastRegisteredCategory, RegisterableService.class); |
|
81 } |
|
82 |
|
83 |
|
84 private static class SomeService |
|
85 { |
|
86 } |
|
87 } |
|