### Question:
DefaultComponentRegistrar implements ComponentRegistrar { public InstanceBuilder register(final Class<?>... mainInterfaces) { final Registration reg = new Registration(mainInterfaces); registry.add(reg); return new DefaultInstanceBuilder(reg); }  InstanceBuilder register(final Class<?>... mainInterfaces); List<ServiceRegistration> writeRegistry(final BundleContext ctx); List<HostComponentRegistration> getRegistry();  }### Answer:
@Test public void testRegister() { DefaultComponentRegistrar registrar = new DefaultComponentRegistrar(); Class[] ifs = new Class[]{Serializable.class}; registrar.register(ifs).forInstance("Foo").withName("foo").withProperty("jim", "bar"); HostComponentRegistration reg = registrar.getRegistry().get(0); assertNotNull(reg); assertEquals("Foo", reg.getInstance()); assertEquals(Serializable.class.getName(), reg.getMainInterfaces()[0]); assertEquals("foo", reg.getProperties().get(DefaultPropertyBuilder.BEAN_NAME)); assertEquals("bar", reg.getProperties().get("jim")); }
@Test public void testRegisterOnlyInterfaces() { DefaultComponentRegistrar registrar = new DefaultComponentRegistrar(); Class[] ifs = new Class[]{Object.class}; try { registrar.register(ifs).forInstance("Foo").withName("foo").withProperty("jim", "bar"); fail("Should have failed"); } catch (IllegalArgumentException ignored) { } }