### Question:
DefaultComponentRegistrar implements ComponentRegistrar { public List<ServiceRegistration> writeRegistry(final BundleContext ctx) { final ArrayList<ServiceRegistration> services = new ArrayList<ServiceRegistration>(); for (final HostComponentRegistration reg : new ArrayList<HostComponentRegistration>(registry)) { if (Arrays.asList(reg.getMainInterfaceClasses()).contains(HostContainer.class)) { log.warn("Cannot register a HostContainer as a host component, skipping"); registry.remove(reg); continue; } final String[] names = reg.getMainInterfaces(); reg.getProperties().put(HOST_COMPONENT_FLAG, Boolean.TRUE.toString()); final String beanName = reg.getProperties().get(PropertyBuilder.BEAN_NAME); if (beanName == null) { String genKey = String.valueOf(Arrays.asList(reg.getMainInterfaces()).hashCode()); reg.getProperties().put(PropertyBuilder.BEAN_NAME, "hostComponent-" + genKey); } if (log.isDebugEnabled()) { log.debug("Registering: " + Arrays.asList(names) + " instance " + reg.getInstance() + "with properties: " + reg.getProperties()); } if (names.length == 0) { log.warn("Host component " + beanName + " of instance " + reg.getInstance() + " has no interfaces"); } Object service = reg.getInstance(); if (!ContextClassLoaderStrategy.USE_PLUGIN.name().equals(reg.getProperties().get(PropertyBuilder.CONTEXT_CLASS_LOADER_STRATEGY))) { service = wrapService(reg.getMainInterfaceClasses(), reg.getInstance()); } final ServiceRegistration sreg = ctx.registerService(names, service, reg.getProperties()); if (sreg != null) { services.add(sreg); } } return Collections.unmodifiableList(services); }  InstanceBuilder register(final Class<?>... mainInterfaces); List<ServiceRegistration> writeRegistry(final BundleContext ctx); List<HostComponentRegistration> getRegistry();  }### Answer:
@Test public void testWriteRegistry() { Class[] ifs = new Class[]{Serializable.class}; DefaultComponentRegistrar registrar = new DefaultComponentRegistrar(); registrar.register(ifs).forInstance("Foo").withName("foo"); Mock mockBundleContext = new Mock(BundleContext.class); registerInMock(mockBundleContext, ifs, "Foo", "foo"); registrar.writeRegistry((BundleContext) mockBundleContext.proxy()); mockBundleContext.verify(); }