1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/componentinjection/test/org/apidesign/component/InjectionSlotTest.java Sat Jun 14 09:53:43 2008 +0200
1.3 @@ -0,0 +1,46 @@
1.4 +package org.apidesign.component;
1.5 +
1.6 +import java.util.Iterator;
1.7 +import org.junit.BeforeClass;
1.8 +import org.junit.Test;
1.9 +import org.netbeans.junit.MockServices;
1.10 +import static org.junit.Assert.*;
1.11 +
1.12 +// BEGIN: lookup.mockservices
1.13 +public class InjectionSlotTest {
1.14 + public InjectionSlotTest() {
1.15 + }
1.16 +
1.17 + @BeforeClass
1.18 + public static void setUpClass() throws Exception {
1.19 + // this is a support for "dynamic" registration of any class
1.20 + // into the global pool of Lookup.getDefault() and java.util.ServiceLoader
1.21 + // either in @BeforeClass or @Before register
1.22 + // classes of the mock instances that you want your code
1.23 + // to find
1.24 + MockServices.setServices(ImplOne.class, ImplTwo.class);
1.25 + }
1.26 +
1.27 + @Test
1.28 + public void singleSlot() {
1.29 + InjectionSlot result = InjectionSlot.singleSlot();
1.30 + assertNotNull("Some result found", result);
1.31 + assertEquals("The first is ImplOne", ImplOne.class, result.getClass());
1.32 + }
1.33 +
1.34 + @Test
1.35 + public void multiSlot() {
1.36 + Iterator<? extends InjectionSlot> it = InjectionSlot.multiSlot().iterator();
1.37 + assertTrue("Has at least one", it.hasNext());
1.38 + assertEquals("The first is ImplOne", ImplOne.class, it.next().getClass());
1.39 + assertTrue("Has two", it.hasNext());
1.40 + assertEquals("The second is ImplTwo", ImplTwo.class, it.next().getClass());
1.41 + assertFalse("No other instance registered", it.hasNext());
1.42 + }
1.43 +
1.44 + public static final class ImplOne extends InjectionSlot {
1.45 + }
1.46 + public static final class ImplTwo extends InjectionSlot {
1.47 + }
1.48 +}
1.49 +// BEGIN: lookup.mockservices