@Test public void shouldProxyConsoleLogger() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); ConsoleLogger logger = spy( new PrintStreamLogger( System.out ) ); Object mirror = CommonReflector.createConsoleLogger( logger, cl ); MatcherAssert.assertThat( mirror, is( notNullValue() ) ); MatcherAssert.assertThat( mirror.getClass().getInterfaces()[0].getName(), is( ConsoleLogger.class.getName() ) ); MatcherAssert.assertThat( mirror, is( not( sameInstance( (Object) logger ) ) ) ); MatcherAssert.assertThat( mirror, is( instanceOf( ConsoleLoggerDecorator.class ) ) ); invokeMethodWithArray( mirror, getMethod( mirror, "info", String.class ), "Hi There!" ); verify( logger, times( 1 ) ).info( "Hi There!" ); }
static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl ) { try { Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() ); return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger ); } catch ( Exception e ) { throw new SurefireReflectionException( e ); } }
CommonReflector { static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl ) { try { Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() ); return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger ); } catch ( Exception e ) { throw new SurefireReflectionException( e ); } } }
CommonReflector { static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl ) { try { Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() ); return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger ); } catch ( Exception e ) { throw new SurefireReflectionException( e ); } } CommonReflector( @Nonnull ClassLoader surefireClassLoader ); }
CommonReflector { static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl ) { try { Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() ); return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger ); } catch ( Exception e ) { throw new SurefireReflectionException( e ); } } CommonReflector( @Nonnull ClassLoader surefireClassLoader ); Object createReportingReporterFactory( @Nonnull StartupReportConfiguration startupReportConfiguration,
                                                  @Nonnull ConsoleLogger consoleLogger ); }
CommonReflector { static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl ) { try { Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() ); return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger ); } catch ( Exception e ) { throw new SurefireReflectionException( e ); } } CommonReflector( @Nonnull ClassLoader surefireClassLoader ); Object createReportingReporterFactory( @Nonnull StartupReportConfiguration startupReportConfiguration,
                                                  @Nonnull ConsoleLogger consoleLogger );  }