This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch base64 in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/base64 by this push: new 26b4f6e unit tests for nextSegmentType() 26b4f6e is described below commit 26b4f6e0e8f5db5784726c9aa6f3d5d76fae4450 Author: tibordigana <tibordig...@apache.org> AuthorDate: Thu Sep 17 01:02:19 2020 +0200 unit tests for nextSegmentType() --- .../surefire/extensions/EventConsumerThread.java | 4 +- .../extensions/EventConsumerThreadTest.java | 156 +++++++++++++++++++++ 2 files changed, 158 insertions(+), 2 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java index 0c640f3..197e197 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThread.java @@ -389,7 +389,7 @@ public class EventConsumerThread extends CloseableDaemonThread } } - protected SegmentType[] nextSegmentType( ForkedProcessEventType eventType ) + static SegmentType[] nextSegmentType( ForkedProcessEventType eventType ) { switch ( eventType ) { @@ -693,7 +693,7 @@ public class EventConsumerThread extends CloseableDaemonThread EOF } - private enum SegmentType + enum SegmentType { RUN_MODE, STRING_ENCODING, diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java index a4211fe..cce6861 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/EventConsumerThreadTest.java @@ -2,12 +2,14 @@ package org.apache.maven.plugin.surefire.extensions; import org.apache.maven.plugin.surefire.extensions.EventConsumerThread.Memento; import org.apache.maven.plugin.surefire.extensions.EventConsumerThread.Segment; +import org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType; import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; import org.apache.maven.surefire.api.booter.ForkedProcessEventType; import org.apache.maven.surefire.api.event.Event; import org.apache.maven.surefire.extensions.EventHandler; import org.apache.maven.surefire.extensions.ForkNodeArguments; import org.apache.maven.surefire.extensions.util.CountdownCloseable; +import org.fest.assertions.Condition; import org.junit.Test; import javax.annotation.Nonnull; @@ -25,7 +27,13 @@ import static java.nio.charset.CodingErrorAction.REPLACE; 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 org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType.DATA_INT; +import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType.DATA_STRING; +import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType.END_OF_FRAME; +import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType.RUN_MODE; +import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.SegmentType.STRING_ENCODING; import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.mapEventTypes; +import static org.apache.maven.plugin.surefire.extensions.EventConsumerThread.nextSegmentType; import static org.apache.maven.surefire.api.booter.Constants.DEFAULT_STREAM_ENCODING; import static org.fest.assertions.Assertions.assertThat; import static org.powermock.reflect.Whitebox.invokeMethod; @@ -482,6 +490,123 @@ public class EventConsumerThreadTest thread.readCharset( memento ); } + @Test + public void shouldMapEventTypeToSegmentType() + { + SegmentType[] segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_BYE ); + assertThat( segmentTypes ) + .hasSize( 1 ) + .containsOnly( END_OF_FRAME ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_STOP_ON_NEXT_TEST ); + assertThat( segmentTypes ) + .hasSize( 1 ) + .containsOnly( END_OF_FRAME ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_NEXT_TEST ); + assertThat( segmentTypes ) + .hasSize( 1 ) + .containsOnly( END_OF_FRAME ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_CONSOLE_ERROR ); + assertThat( segmentTypes ) + .hasSize( 5 ) + .satisfies( new InOrder( STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_JVM_EXIT_ERROR ); + assertThat( segmentTypes ) + .hasSize( 5 ) + .satisfies( new InOrder( STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_CONSOLE_INFO ); + assertThat( segmentTypes ) + .hasSize( 3 ) + .satisfies( new InOrder( STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_CONSOLE_DEBUG ); + assertThat( segmentTypes ) + .hasSize( 3 ) + .satisfies( new InOrder( STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_CONSOLE_WARNING ); + assertThat( segmentTypes ) + .hasSize( 3 ) + .satisfies( new InOrder( STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_STDOUT ); + assertThat( segmentTypes ) + .hasSize( 4 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_STDOUT_NEW_LINE ); + assertThat( segmentTypes ) + .hasSize( 4 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_STDERR ); + assertThat( segmentTypes ) + .hasSize( 4 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_STDERR_NEW_LINE ); + assertThat( segmentTypes ) + .hasSize( 4 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_SYSPROPS ); + assertThat( segmentTypes ) + .hasSize( 5 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TESTSET_STARTING ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TESTSET_COMPLETED ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_STARTING ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_SUCCEEDED ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_FAILED ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_SKIPPED ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_ERROR ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + + segmentTypes = nextSegmentType( ForkedProcessEventType.BOOTERCODE_TEST_ASSUMPTIONFAILURE ); + assertThat( segmentTypes ) + .hasSize( 13 ) + .satisfies( new InOrder( RUN_MODE, STRING_ENCODING, DATA_STRING, DATA_STRING, DATA_STRING, DATA_STRING, + DATA_STRING, DATA_STRING, DATA_INT, DATA_STRING, DATA_STRING, DATA_STRING, END_OF_FRAME ) ); + } + private static class Channel implements ReadableByteChannel { private final byte[] bytes; @@ -583,4 +708,35 @@ public class EventConsumerThreadTest return null; } } + + private static class InOrder extends Condition<Object[]> + { + private final SegmentType[] expected; + + InOrder( SegmentType... expected ) + { + this.expected = expected; + } + + @Override + public boolean matches( Object[] values ) + { + if ( values == null && expected == null ) + { + return true; + } + else if ( values != null && expected != null && values.length == expected.length ) + { + boolean matches = true; + for ( int i = 0; i < values.length; i++ ) + { + + assertThat( values[i] ).isInstanceOf( SegmentType.class ); + matches &= values[i] == expected[i]; + } + return matches; + } + return false; + } + } }