@Test @SuppressWarnings( "checkstyle:innerassignment" ) public void shouldCountSameNumberOfSystemProperties() throws IOException { Stream stream = Stream.newStream(); WritableBufferedByteChannel channel = newBufferedChannel( stream ); LegacyMasterProcessChannelEncoder encoder = new LegacyMasterProcessChannelEncoder( channel ); Map<String, String> sysProps = ObjectUtils.systemProps(); encoder.sendSystemProperties( sysProps ); channel.close(); for ( Entry<String, String> entry : sysProps.entrySet() ) { int[] k = toBytes( entry.getKey().length() ); int[] v = toBytes( entry.getValue() == null ? 1 : entry.getValue().getBytes( UTF_8 ).length ); ByteArrayOutputStream expectedFrame = new ByteArrayOutputStream(); expectedFrame.write( ":maven-surefire-event:sys-prop:normal-run:UTF-8:".getBytes( UTF_8 ) ); expectedFrame.write( k[0] ); expectedFrame.write( k[1] ); expectedFrame.write( k[2] ); expectedFrame.write( k[3] ); expectedFrame.write( ':' ); expectedFrame.write( v[0] ); expectedFrame.write( v[1] ); expectedFrame.write( v[2] ); expectedFrame.write( v[3] ); expectedFrame.write( ':' ); expectedFrame.write( ( entry.getValue() == null ? "\u0000" : entry.getValue() ).getBytes( UTF_8 ) ); expectedFrame.write( ':' ); assertThat( stream.toByteArray() ) .contains( expectedFrame.toByteArray() ); } }
@Override public void sendSystemProperties( Map<String, String> sysProps ) { CharsetEncoder encoder = DEFAULT_STREAM_ENCODING.newEncoder(); ByteBuffer result = null; for ( Iterator<Entry<String, String>> it = sysProps.entrySet().iterator(); it.hasNext(); ) { Entry<String, String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); int bufferLength = estimateBufferLength( BOOTERCODE_SYSPROPS, runMode, encoder, 0, key, value ); result = result != null && result.capacity() >= bufferLength ? result : ByteBuffer.allocate( bufferLength ); result.clear(); encode( encoder, result, BOOTERCODE_SYSPROPS, runMode, key, value ); boolean sendImmediately = !it.hasNext(); encodeAndPrintEvent( result, sendImmediately ); } }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { @Override public void sendSystemProperties( Map<String, String> sysProps ) { CharsetEncoder encoder = DEFAULT_STREAM_ENCODING.newEncoder(); ByteBuffer result = null; for ( Iterator<Entry<String, String>> it = sysProps.entrySet().iterator(); it.hasNext(); ) { Entry<String, String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); int bufferLength = estimateBufferLength( BOOTERCODE_SYSPROPS, runMode, encoder, 0, key, value ); result = result != null && result.capacity() >= bufferLength ? result : ByteBuffer.allocate( bufferLength ); result.clear(); encode( encoder, result, BOOTERCODE_SYSPROPS, runMode, key, value ); boolean sendImmediately = !it.hasNext(); encodeAndPrintEvent( result, sendImmediately ); } } }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { @Override public void sendSystemProperties( Map<String, String> sysProps ) { CharsetEncoder encoder = DEFAULT_STREAM_ENCODING.newEncoder(); ByteBuffer result = null; for ( Iterator<Entry<String, String>> it = sysProps.entrySet().iterator(); it.hasNext(); ) { Entry<String, String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); int bufferLength = estimateBufferLength( BOOTERCODE_SYSPROPS, runMode, encoder, 0, key, value ); result = result != null && result.capacity() >= bufferLength ? result : ByteBuffer.allocate( bufferLength ); result.clear(); encode( encoder, result, BOOTERCODE_SYSPROPS, runMode, key, value ); boolean sendImmediately = !it.hasNext(); encodeAndPrintEvent( result, sendImmediately ); } } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { @Override public void sendSystemProperties( Map<String, String> sysProps ) { CharsetEncoder encoder = DEFAULT_STREAM_ENCODING.newEncoder(); ByteBuffer result = null; for ( Iterator<Entry<String, String>> it = sysProps.entrySet().iterator(); it.hasNext(); ) { Entry<String, String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); int bufferLength = estimateBufferLength( BOOTERCODE_SYSPROPS, runMode, encoder, 0, key, value ); result = result != null && result.capacity() >= bufferLength ? result : ByteBuffer.allocate( bufferLength ); result.clear(); encode( encoder, result, BOOTERCODE_SYSPROPS, runMode, key, value ); boolean sendImmediately = !it.hasNext(); encodeAndPrintEvent( result, sendImmediately ); } } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); @Override MasterProcessChannelEncoder asRerunMode(); @Override MasterProcessChannelEncoder asNormalMode(); @Override boolean checkError(); @Override void onJvmExit(); @Override void sendSystemProperties( Map<String, String> sysProps ); @Override void testSetStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSetCompleted( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSucceeded( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testFailed( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSkipped( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testError( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testAssumptionFailure( ReportEntry reportEntry, boolean trimStackTraces ); @Override void stdOut( String msg, boolean newLine ); @Override void stdErr( String msg, boolean newLine ); @Override void consoleInfoLog( String message ); @Override void consoleErrorLog( String message ); @Override void consoleErrorLog( Throwable t ); @Override void consoleErrorLog( String message, Throwable t ); @Override void consoleErrorLog( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); @Override void consoleDebugLog( String message ); @Override void consoleWarningLog( String message ); @Override void bye(); @Override void stopOnNextTest(); @Override void acquireNextTest(); @Override void sendExitError( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { @Override public void sendSystemProperties( Map<String, String> sysProps ) { CharsetEncoder encoder = DEFAULT_STREAM_ENCODING.newEncoder(); ByteBuffer result = null; for ( Iterator<Entry<String, String>> it = sysProps.entrySet().iterator(); it.hasNext(); ) { Entry<String, String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); int bufferLength = estimateBufferLength( BOOTERCODE_SYSPROPS, runMode, encoder, 0, key, value ); result = result != null && result.capacity() >= bufferLength ? result : ByteBuffer.allocate( bufferLength ); result.clear(); encode( encoder, result, BOOTERCODE_SYSPROPS, runMode, key, value ); boolean sendImmediately = !it.hasNext(); encodeAndPrintEvent( result, sendImmediately ); } } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); @Override MasterProcessChannelEncoder asRerunMode(); @Override MasterProcessChannelEncoder asNormalMode(); @Override boolean checkError(); @Override void onJvmExit(); @Override void sendSystemProperties( Map<String, String> sysProps ); @Override void testSetStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSetCompleted( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSucceeded( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testFailed( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSkipped( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testError( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testAssumptionFailure( ReportEntry reportEntry, boolean trimStackTraces ); @Override void stdOut( String msg, boolean newLine ); @Override void stdErr( String msg, boolean newLine ); @Override void consoleInfoLog( String message ); @Override void consoleErrorLog( String message ); @Override void consoleErrorLog( Throwable t ); @Override void consoleErrorLog( String message, Throwable t ); @Override void consoleErrorLog( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); @Override void consoleDebugLog( String message ); @Override void consoleWarningLog( String message ); @Override void bye(); @Override void stopOnNextTest(); @Override void acquireNextTest(); @Override void sendExitError( StackTraceWriter stackTraceWriter, boolean trimStackTraces );  }