jtulach@82: package org.apidesign.component; jtulach@82: jtulach@82: import java.util.Iterator; jtulach@82: import org.junit.BeforeClass; jtulach@82: import org.junit.Test; jtulach@82: import org.netbeans.junit.MockServices; jtulach@82: import static org.junit.Assert.*; jtulach@82: jtulach@82: // BEGIN: lookup.mockservices jtulach@82: public class InjectionSlotTest { jtulach@82: public InjectionSlotTest() { jtulach@82: } jtulach@82: jtulach@82: @BeforeClass jtulach@82: public static void setUpClass() throws Exception { jtulach@82: // this is a support for "dynamic" registration of any class jtulach@132: // into the global pool of Lookup.getDefault() and jtulach@132: // java.util.ServiceLoader jtulach@82: // either in @BeforeClass or @Before register jtulach@82: // classes of the mock instances that you want your code jtulach@82: // to find jtulach@82: MockServices.setServices(ImplOne.class, ImplTwo.class); jtulach@82: } jtulach@82: jtulach@82: @Test jtulach@82: public void singleSlot() { jtulach@82: InjectionSlot result = InjectionSlot.singleSlot(); jtulach@82: assertNotNull("Some result found", result); jtulach@132: assertEquals( jtulach@132: "The first is ImplOne", ImplOne.class, result.getClass() jtulach@132: ); jtulach@82: } jtulach@82: jtulach@82: @Test jtulach@82: public void multiSlot() { jtulach@132: Iterator it = jtulach@132: InjectionSlot.multiSlot().iterator(); jtulach@82: assertTrue("Has at least one", it.hasNext()); jtulach@132: assertEquals( jtulach@132: "The first is ImplOne", ImplOne.class, it.next().getClass() jtulach@132: ); jtulach@82: assertTrue("Has two", it.hasNext()); jtulach@132: assertEquals( jtulach@132: "The second is ImplTwo", ImplTwo.class, it.next().getClass() jtulach@132: ); jtulach@82: assertFalse("No other instance registered", it.hasNext()); jtulach@82: } jtulach@82: jtulach@82: public static final class ImplOne extends InjectionSlot { jtulach@82: } jtulach@82: public static final class ImplTwo extends InjectionSlot { jtulach@82: } jtulach@82: } jtulach@85: // END: lookup.mockservices