### Question:
SearchableRepositorySource implements RepositorySource { public void initialize( final RepositoryContext context ) throws RepositorySourceException { final String delegateSourceName = delegate.getName(); final RepositoryConnectionFactory originalConnectionFactory = context.getRepositoryConnectionFactory(); final RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() { public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException { if (delegateSourceName.equals(sourceName)) return delegate().getConnection(); return originalConnectionFactory.createConnection(sourceName); } }; final Observer observer = new Observer() { public void notify( final Changes changes ) { if (changes != null) { if (updateIndexesAsynchronously()) { executorService().submit(new Runnable() { public void run() { process(context.getExecutionContext(), changes); } }); } else { process(context.getExecutionContext(), changes); } } } }; final RepositoryContext newContext = new RepositoryContext() { public Subgraph getConfiguration( int depth ) { return context.getConfiguration(depth); } public ExecutionContext getExecutionContext() { return context.getExecutionContext(); } public Observer getObserver() { return observer; } public RepositoryConnectionFactory getRepositoryConnectionFactory() { return connectionFactory; } }; delegate.initialize(newContext); } SearchableRepositorySource( RepositorySource wrapped,
                                       SearchEngine searchEngine,
                                       ExecutorService executorService,
                                       boolean executeAsynchronously,
                                       boolean updateIndexesAsynchronously );  SearchableRepositorySource( RepositorySource wrapped,
                                       SearchEngine searchEngine ); String getName(); void close(); RepositorySourceCapabilities getCapabilities(); RepositoryConnection getConnection(); int getRetryLimit(); void initialize( final RepositoryContext context ); void setRetryLimit( int limit ); Reference getReference();  }### Answer:
@SuppressWarnings( "synthetic-access" ) @Test public void shouldInitializeByInitializingWrappedSourceWithCustomObserverAndConnectionFactory() { final RepositoryConnectionFactory mockConnectionFactory = mock(RepositoryConnectionFactory.class); RepositoryContext repoContext = new RepositoryContext() { public ExecutionContext getExecutionContext() { return context; } public Subgraph getConfiguration( int depth ) { return null; } public Observer getObserver() { return null; } public RepositoryConnectionFactory getRepositoryConnectionFactory() { return mockConnectionFactory; } }; final AtomicInteger called = new AtomicInteger(0); wrapped = new InMemoryRepositorySource(context) { private static final long serialVersionUID = 1L; @Override public void initialize( RepositoryContext context ) throws RepositorySourceException { called.incrementAndGet(); assertThat(context, is(notNullValue())); assertThat(context.getExecutionContext(), is(sameInstance(SearchableRepositorySourceTest.this.context))); assertThat(context.getObserver(), is(notNullValue())); assertThat(context.getRepositoryConnectionFactory(), is(notNullValue())); assertThat(context.getRepositoryConnectionFactory(), is(not(sameInstance(mockConnectionFactory)))); } }; searchable = newSynchronousSearchable(); searchable.initialize(repoContext); assertThat(called.get(), is(1)); }