1 package org.apidesign.component;
3 import java.util.Iterator;
4 import org.junit.BeforeClass;
6 import org.netbeans.junit.MockServices;
7 import static org.junit.Assert.*;
9 // BEGIN: lookup.mockservices
10 public class InjectionSlotTest {
11 public InjectionSlotTest() {
15 public static void setUpClass() throws Exception {
16 // this is a support for "dynamic" registration of any class
17 // into the global pool of Lookup.getDefault() and java.util.ServiceLoader
18 // either in @BeforeClass or @Before register
19 // classes of the mock instances that you want your code
21 MockServices.setServices(ImplOne.class, ImplTwo.class);
25 public void singleSlot() {
26 InjectionSlot result = InjectionSlot.singleSlot();
27 assertNotNull("Some result found", result);
28 assertEquals("The first is ImplOne", ImplOne.class, result.getClass());
32 public void multiSlot() {
33 Iterator<? extends InjectionSlot> it = InjectionSlot.multiSlot().iterator();
34 assertTrue("Has at least one", it.hasNext());
35 assertEquals("The first is ImplOne", ImplOne.class, it.next().getClass());
36 assertTrue("Has two", it.hasNext());
37 assertEquals("The second is ImplTwo", ImplTwo.class, it.next().getClass());
38 assertFalse("No other instance registered", it.hasNext());
41 public static final class ImplOne extends InjectionSlot {
43 public static final class ImplTwo extends InjectionSlot {
46 // BEGIN: lookup.mockservices