Skip to content

Commit

Permalink
[SUREFIRE-2058] Add static import for emptyMap and remove explicit ty…
Browse files Browse the repository at this point in the history
…pe arguments
  • Loading branch information
zoltanmeze committed Apr 13, 2022
1 parent 8615d16 commit 0b1c564
Showing 1 changed file with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.CharBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.CharsetDecoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand All @@ -51,6 +50,7 @@
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.apache.maven.surefire.api.booter.Constants.DEFAULT_STREAM_ENCODING;
import static org.apache.maven.surefire.api.booter.ForkedProcessEventType.BOOTERCODE_STDOUT;
Expand Down Expand Up @@ -196,8 +196,7 @@ public void shouldReadInt() throws Exception
{
Channel channel = new Channel( new byte[] {0x01, 0x02, 0x03, 0x04, ':'}, 1 );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();

Expand All @@ -210,8 +209,7 @@ public void shouldReadInteger() throws Exception
{
Channel channel = new Channel( new byte[] {(byte) 0xff, 0x01, 0x02, 0x03, 0x04, ':'}, 1 );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
assertThat( thread.readInteger( memento ) )
Expand All @@ -223,8 +221,7 @@ public void shouldReadNullInteger() throws Exception
{
Channel channel = new Channel( new byte[] {(byte) 0x00, ':'}, 1 );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
assertThat( thread.readInteger( memento ) )
Expand All @@ -237,8 +234,7 @@ public void shouldNotReadString() throws Exception
Channel channel = new Channel( PATTERN1.getBytes(), PATTERN1.length() );
channel.read( ByteBuffer.allocate( 100 ) );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
invokeMethod( thread, "readString", memento, 10 );
Expand All @@ -249,8 +245,7 @@ public void shouldReadString() throws Exception
{
Channel channel = new Channel( PATTERN1.getBytes(), PATTERN1.length() );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
String s = invokeMethod( thread, "readString", memento, 10 );
Expand All @@ -271,8 +266,7 @@ public void shouldReadStringOverflowOnNewLine() throws Exception

Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();

Expand All @@ -296,8 +290,7 @@ public void shouldReadStringOverflowOn4BytesEncodedSymbol() throws Exception

Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();

Expand All @@ -319,8 +312,7 @@ public void shouldReadStringShiftedBuffer() throws Exception

Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
// whatever position will be compacted to 0
Expand All @@ -341,8 +333,7 @@ public void shouldReadStringShiftedInput() throws Exception
Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() );
channel.read( ByteBuffer.allocate( 997 ) );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
assertThat( (String) invokeMethod( thread, "readString", memento, PATTERN1.length() ) )
Expand All @@ -362,8 +353,7 @@ public void shouldReadMultipleStringsAndShiftedInput() throws Exception
Channel channel = new Channel( s.toString().getBytes( UTF_8 ), s.length() );
channel.read( ByteBuffer.allocate( 1997 ) );

Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
// whatever position will be compacted to 0
Expand Down Expand Up @@ -391,8 +381,7 @@ public void shouldDecode3BytesEncodedSymbol() throws Exception
}

Channel channel = new Channel( input, 64 * 1024 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );
Memento memento = thread.new Memento();
String decodedOutput = invokeMethod( thread, "readString", memento, input.length );

Expand Down Expand Up @@ -466,8 +455,7 @@ public void shouldEventTypeReachedMalformedHeader() throws Exception
{
byte[] stream = ":xxxxx-xxxxxxxx-xxxxx:\u000E:xxx".getBytes( UTF_8 );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -479,8 +467,7 @@ public void shouldReadEmptyString() throws Exception
{
byte[] stream = "\u0000\u0000\u0000\u0000::".getBytes( UTF_8 );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -494,8 +481,7 @@ public void shouldReadNullString() throws Exception
{
byte[] stream = "\u0000\u0000\u0000\u0001:\u0000:".getBytes( UTF_8 );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -509,8 +495,7 @@ public void shouldReadSingleCharString() throws Exception
{
byte[] stream = "\u0000\u0000\u0000\u0001:A:".getBytes( UTF_8 );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -524,8 +509,7 @@ public void shouldReadThreeCharactersString() throws Exception
{
byte[] stream = "\u0000\u0000\u0000\u0003:ABC:".getBytes( UTF_8 );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -539,8 +523,7 @@ public void shouldReadDefaultCharset() throws Exception
{
byte[] stream = "\u0005:UTF-8:".getBytes( US_ASCII );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -555,8 +538,7 @@ public void shouldReadNonDefaultCharset() throws Exception
{
byte[] stream = ( (char) 10 + ":ISO_8859_1:" ).getBytes( US_ASCII );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand All @@ -571,10 +553,9 @@ public void shouldSetNonDefaultCharset()
{
byte[] stream = {};
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Memento memento = thread.new Memento();
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( ISO_8859_1 );
assertThat( memento.getDecoder().charset() ).isEqualTo( ISO_8859_1 );

Expand All @@ -591,8 +572,7 @@ public void malformedCharset() throws Exception
{
byte[] stream = ( (char) 8 + ":ISO_8859:" ).getBytes( US_ASCII );
Channel channel = new Channel( stream, 1 );
Mock thread = new Mock( channel, new MockForkNodeArguments(),
Collections.<Segment, ForkedProcessEventType>emptyMap() );
Mock thread = new Mock( channel, new MockForkNodeArguments(), emptyMap() );

Memento memento = thread.new Memento();
memento.setCharset( UTF_8 );
Expand Down

0 comments on commit 0b1c564

Please sign in to comment.