### Question:
ProxyFactoryImpl implements IProxyFactory { @Override public <T, K> K createProxy( T target ) throws ProxyException { Class<T> targetClass = (Class<T>) target.getClass(); if ( proxyUnwrapper != null ) { target = (T) proxyUnwrapper.unwrap( target ); targetClass = (Class<T>) target.getClass(); } logger.debug( "Proxy Request initiated for class: " + targetClass ); logger.debug( "Attempting to find Proxy Creator by class hierarchy: " + targetClass ); Class<?> parentClass = targetClass; K proxyWrapper = null; outer: while ( parentClass != null ) { for ( IProxyCreator<?> creator : creators ) { if ( creator.supports( parentClass ) ) { logger.debug( "Proxy creator found for : " + targetClass + " : " + creator.getClass() ); proxyWrapper = (K) creator.create( target ); if ( proxyWrapper != null ) { break outer; } } } parentClass = parentClass.getSuperclass(); } if ( proxyWrapper == null ) { logger.debug( "Attempting to find Proxy Creator by declared Interfaces: " + targetClass ); parentClass = targetClass; outer: while ( parentClass != null ) { Class<?>[] interfaces = parentClass.getInterfaces(); for ( Class<?> anInterface : interfaces ) { for ( IProxyCreator<?> creator : creators ) { if ( creator.supports( anInterface ) ) { logger.debug( "Proxy creator found for : " + targetClass + " : " + creator.getClass() ); proxyWrapper = (K) creator.create( target ); if ( proxyWrapper != null ) { break outer; } } } } parentClass = parentClass.getSuperclass(); } } if ( proxyWrapper == null ) { throw new ProxyException( "No Proxy Creator found for supplied target class: " + targetClass.getName() ); } return proxyWrapper; } ProxyFactoryImpl( ProxyUnwrapper proxyUnwrapper ); @Override K createProxy( T target ); @Override @SuppressWarnings( "unchecked" ) IProxyRegistration createAndRegisterProxy( T target, List<Class<?>> publishedClasses,
                                                           Map<String, Object> properties ); void setCreators( List<IProxyCreator<?>> creators );  }### Answer:
@Test public void testCreateProxy() throws Exception { ProxyFactoryImpl proxyFactory = new ProxyFactoryImpl( null ); IProxyCreator<String> creator = mock( IProxyCreator.class ); when( creator.supports( String.class )).thenReturn( true ); String target = "Hello World"; when( creator.create( target ) ).thenReturn( "Good Night" ); proxyFactory.setCreators( Collections.<IProxyCreator<?>>singletonList( creator ) ); IProxyRegistration proxy = proxyFactory .createAndRegisterProxy( target, Collections.<Class<?>>singletonList( CharSequence.class ), Collections.<String, Object>singletonMap( "key", "master" ) ); assertNotNull( proxy ); CharSequence registeredString = PentahoSystem.get( CharSequence.class, null, Collections.singletonMap( "key", "master" ) ); assertEquals( "Good Night", registeredString ); String plainProxy = proxyFactory.createProxy( target ); assertNotNull( proxy ); assertEquals( "Good Night", plainProxy ); }