Skip to content

Commit db99f16

Browse files
committed
[SUREFIRE-2046] Resolved TODOs. Updated callbacks ForkedProcessPropertyEventListener and ForkedProcessStandardOutErrEventListener.
1 parent 6e60b03 commit db99f16

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void handle( ReportEntry reportEntry )
211211
private final class SystemPropertiesListener implements ForkedProcessPropertyEventListener
212212
{
213213
@Override
214-
public void handle( RunMode runMode, String key, String value )
214+
public void handle( String key, String value, RunMode runMode, Long testRunId )
215215
{
216216
testVmSystemProperties.put( key, value );
217217
}
@@ -220,18 +220,18 @@ public void handle( RunMode runMode, String key, String value )
220220
private final class StdOutListener implements ForkedProcessStandardOutErrEventListener
221221
{
222222
@Override
223-
public void handle( RunMode runMode, String output, boolean newLine )
223+
public void handle( String output, boolean newLine, RunMode runMode, Long testRunId )
224224
{
225-
writeTestOutput( output, newLine, true );
225+
writeTestOutput( output, true, newLine, runMode, testRunId );
226226
}
227227
}
228228

229229
private final class StdErrListener implements ForkedProcessStandardOutErrEventListener
230230
{
231231
@Override
232-
public void handle( RunMode runMode, String output, boolean newLine )
232+
public void handle( String output, boolean newLine, RunMode runMode, Long testRunId )
233233
{
234-
writeTestOutput( output, newLine, false );
234+
writeTestOutput( output, false, newLine, runMode, testRunId );
235235
}
236236
}
237237

@@ -393,10 +393,10 @@ void dumpToLoFile( String msg )
393393
util.dumpStreamText( msg, reportsDir, forkNumber );
394394
}
395395

396-
private void writeTestOutput( String output, boolean newLine, boolean isStdout )
396+
private void writeTestOutput( String output, boolean isStdout, boolean newLine, RunMode runMode, Long testRunId )
397397
{
398398
getConsoleOutputReceiver()
399-
.writeTestOutput( new TestOutputReportEntry( output, isStdout, newLine, /*todo*/ null, null ) );
399+
.writeTestOutput( new TestOutputReportEntry( output, isStdout, newLine, runMode, testRunId ) );
400400
}
401401

402402
public Map<String, String> getTestVmSystemProperties()

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkedProcessEventNotifier.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,20 @@ else if ( event.isStandardStreamCategory() )
207207
ForkedProcessStandardOutErrEventListener listener = stdOutErrEventListeners.get( eventType );
208208
if ( listener != null )
209209
{
210-
listener.handle( standardStreamEvent.getRunMode(), standardStreamEvent.getMessage(), newLine );
210+
listener.handle( standardStreamEvent.getMessage(), newLine,
211+
standardStreamEvent.getRunMode(), standardStreamEvent.getTestRunId() );
211212
}
212213
}
213214
else if ( event.isSysPropCategory() )
214215
{
215216
SystemPropertyEvent systemPropertyEvent = (SystemPropertyEvent) event;
216217
RunMode runMode = systemPropertyEvent.getRunMode();
218+
Long testRunId = systemPropertyEvent.getTestRunId();
217219
String key = systemPropertyEvent.getKey();
218220
String value = systemPropertyEvent.getValue();
219221
if ( propertyEventListener != null )
220222
{
221-
propertyEventListener.handle( runMode, key, value );
223+
propertyEventListener.handle( key, value, runMode, testRunId );
222224
}
223225
}
224226
else if ( event.isTestCategory() )

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkedProcessPropertyEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
*/
2828
public interface ForkedProcessPropertyEventListener
2929
{
30-
void handle( RunMode runMode, String key, String value );
30+
void handle( String key, String value, RunMode runMode, Long testRunId );
3131
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkedProcessStandardOutErrEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
*/
2828
public interface ForkedProcessStandardOutErrEventListener
2929
{
30-
void handle( RunMode runMode, String output, boolean newLine );
30+
void handle( String output, boolean newLine, RunMode runMode, Long testRunId );
3131
}

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/ForkedProcessEventNotifierTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public void testStdOutStream() throws Exception
540540

541541
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
542542
StandardOutErrEventAssertionListener listener =
543-
new StandardOutErrEventAssertionListener( NORMAL_RUN, "msg", false );
543+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, "msg", false );
544544
notifier.setStdOutListener( listener );
545545

546546
EH eventHandler = new EH();
@@ -579,7 +579,7 @@ public void testStdOutStreamPrint() throws Exception
579579

580580
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
581581
StandardOutErrEventAssertionListener listener =
582-
new StandardOutErrEventAssertionListener( NORMAL_RUN, "", false );
582+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, "", false );
583583
notifier.setStdOutListener( listener );
584584

585585
EH eventHandler = new EH();
@@ -618,7 +618,7 @@ public void testStdOutStreamPrintWithNull() throws Exception
618618

619619
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
620620
StandardOutErrEventAssertionListener listener =
621-
new StandardOutErrEventAssertionListener( NORMAL_RUN, null, false );
621+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, null, false );
622622
notifier.setStdOutListener( listener );
623623

624624
EH eventHandler = new EH();
@@ -657,7 +657,7 @@ public void testStdOutStreamPrintln() throws Exception
657657

658658
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
659659
StandardOutErrEventAssertionListener listener =
660-
new StandardOutErrEventAssertionListener( NORMAL_RUN, "", true );
660+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, "", true );
661661
notifier.setStdOutListener( listener );
662662

663663
EH eventHandler = new EH();
@@ -696,7 +696,7 @@ public void testStdOutStreamPrintlnWithNull() throws Exception
696696

697697
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
698698
StandardOutErrEventAssertionListener listener =
699-
new StandardOutErrEventAssertionListener( NORMAL_RUN, null, true );
699+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, null, true );
700700
notifier.setStdOutListener( listener );
701701

702702
EH eventHandler = new EH();
@@ -735,7 +735,7 @@ public void testStdErrStream() throws Exception
735735

736736
ForkedProcessEventNotifier notifier = new ForkedProcessEventNotifier();
737737
StandardOutErrEventAssertionListener listener =
738-
new StandardOutErrEventAssertionListener( NORMAL_RUN, "msg", false );
738+
new StandardOutErrEventAssertionListener( NORMAL_RUN, 1L, "msg", false );
739739
notifier.setStdErrListener( listener );
740740

741741
EH eventHandler = new EH();
@@ -995,11 +995,12 @@ private static class PropertyEventAssertionListener implements ForkedProcessProp
995995
private final Map<?, ?> sysProps = System.getProperties();
996996
private final AtomicInteger counter = new AtomicInteger();
997997

998-
public void handle( RunMode runMode, String key, String value )
998+
public void handle( String key, String value, RunMode runMode, Long testRunId )
999999
{
10001000
called.set( true );
10011001
counter.incrementAndGet();
10021002
assertThat( runMode ).isEqualTo( NORMAL_RUN );
1003+
assertThat( testRunId ).isEqualTo( 1L );
10031004
assertTrue( sysProps.containsKey( key ) );
10041005
assertThat( sysProps.get( key ) ).isEqualTo( value );
10051006
}
@@ -1067,23 +1068,28 @@ private static class StandardOutErrEventAssertionListener implements ForkedProce
10671068
{
10681069
final AtomicBoolean called = new AtomicBoolean();
10691070
private final RunMode runMode;
1071+
private final long testRunId;
10701072
private final String output;
10711073
private final boolean newLine;
10721074

1073-
StandardOutErrEventAssertionListener( RunMode runMode, String output, boolean newLine )
1075+
StandardOutErrEventAssertionListener( RunMode runMode, long testRunId, String output, boolean newLine )
10741076
{
10751077
this.runMode = runMode;
1078+
this.testRunId = testRunId;
10761079
this.output = output;
10771080
this.newLine = newLine;
10781081
}
10791082

1080-
public void handle( RunMode runMode, String output, boolean newLine )
1083+
public void handle( String output, boolean newLine, RunMode runMode, Long testRunId )
10811084
{
10821085
called.set( true );
10831086

10841087
assertThat( runMode )
10851088
.isEqualTo( this.runMode );
10861089

1090+
assertThat( testRunId )
1091+
.isEqualTo( this.testRunId );
1092+
10871093
assertThat( output )
10881094
.isEqualTo( this.output );
10891095

0 commit comments

Comments
 (0)