zoltanmeze commented on code in PR #518: URL: https://github.com/apache/maven-surefire/pull/518#discussion_r848495107
########## surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java: ########## @@ -258,6 +258,56 @@ public void shouldReadString() throws Exception .isEqualTo( "0123456789" ); } + @Test + public void shouldReadStringOverflowOnNewLine() throws Exception + { + StringBuilder s = new StringBuilder( 1025 ); + for ( int i = 0; i < 10; i++ ) + { + s.append( PATTERN1 ); + } + s.append( PATTERN1, 0, 23 ); + s.append( "\u00FA\n" ); // 2-bytes encoded character + LF + + Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() ); + + Mock thread = new Mock( channel, new MockForkNodeArguments(), + Collections.<Segment, ForkedProcessEventType>emptyMap() ); + + Memento memento = thread.new Memento(); + + assertThat( (String) invokeMethod( thread, "readString", memento, 1026 ) ) + .isEqualTo( s.toString() ); + + assertThat ( memento.getByteBuffer().remaining() ) + .isEqualTo( 0 ); + } + + @Test + public void shouldReadStringOverflowOn4BytesEncodedSymbol() throws Exception + { + StringBuilder s = new StringBuilder( 1024 ); Review Comment: Already changed that StringBuilder capacity from 1024 to 1025 in the morning. It doesn't change anything, StringBuilder increases the capacity internally if initial capacity is low. Cannot think of any other tests. That first one was happening in some of my tests. Once I figured out what's making those errors and just tried some other cases. Originally I included both of these tests as ITs, but didn't push that commit because it's actually testing the same thing and unit tests are much faster: https://github.com/apache/maven-surefire/commit/7af78437c91bd2c7245e92170b3da9a47dcf32b4 :point_up: It's same as https://github.com/zoltanmeze/surefire-corrupted-channel but without random. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org