You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2020/10/08 18:32:36 UTC
[maven-surefire] 01/02: [GH] build fix
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch gh-build-fix
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit f919a473e9676d06290effd3ab2d4edd5fbd0ad8
Author: tibordigana <ti...@apache.org>
AuthorDate: Thu Oct 8 20:30:51 2020 +0200
[GH] build fix
---
.../booterclient/ForkingRunListenerTest.java | 75 +++++++++++++++++++---
1 file changed, 67 insertions(+), 8 deletions(-)
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java
index 8887e4d..a8eb91f 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java
@@ -53,6 +53,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -60,12 +61,8 @@ import static org.apache.maven.surefire.api.util.internal.Channels.newBufferedCh
import static org.apache.maven.surefire.api.util.internal.Channels.newChannel;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
/**
* @author Kristian Rosenvold
@@ -299,16 +296,15 @@ public class ForkingRunListenerTest
EH handler = new EH();
CountdownCloseable countdown = new CountdownCloseable( mock( Closeable.class ), 1 );
ConsoleLogger logger = mock( ConsoleLogger.class );
- ForkNodeArguments arguments = mock( ForkNodeArguments.class );
- when( arguments.dumpStreamText( anyString() ) ).thenReturn( new File( "" ) );
- when( arguments.getConsoleLogger() ).thenReturn( logger );
+ ForkNodeArgumentsMock arguments = new ForkNodeArgumentsMock( logger, new File( "" ) );
ReadableByteChannel channel = newChannel( new ByteArrayInputStream( stream ) );
try ( EventConsumerThread t = new EventConsumerThread( "t", channel, handler, countdown, arguments ) )
{
t.start();
countdown.awaitClosed();
verifyZeroInteractions( logger );
- verify( arguments, never() ).dumpStreamText( anyString() );
+ assertThat( arguments.isCalled() )
+ .isFalse();
for ( int i = 0, size = handler.countEventsInCache(); i < size; i++ )
{
events.add( handler.pullEvent() );
@@ -318,6 +314,69 @@ public class ForkingRunListenerTest
}
}
+ /**
+ * Threadsafe impl. Mockito and Powermock are not thread-safe.
+ */
+ private static class ForkNodeArgumentsMock implements ForkNodeArguments
+ {
+ private final ConcurrentLinkedQueue<String> dumpStreamText = new ConcurrentLinkedQueue<>();
+ private final ConcurrentLinkedQueue<String> logWarningAtEnd = new ConcurrentLinkedQueue<>();
+ private final ConsoleLogger logger;
+ private final File dumpStreamTextFile;
+
+ ForkNodeArgumentsMock( ConsoleLogger logger, File dumpStreamTextFile )
+ {
+ this.logger = logger;
+ this.dumpStreamTextFile = dumpStreamTextFile;
+ }
+
+ @Nonnull
+ @Override
+ public String getSessionId()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getForkChannelId()
+ {
+ return 0;
+ }
+
+ @Nonnull
+ @Override
+ public File dumpStreamText( @Nonnull String text )
+ {
+ dumpStreamText.add( text );
+ return dumpStreamTextFile;
+ }
+
+ @Nonnull
+ @Override
+ public File dumpStreamException( @Nonnull Throwable t )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void logWarningAtEnd( @Nonnull String text )
+ {
+ logWarningAtEnd.add( text );
+ }
+
+ @Nonnull
+ @Override
+ public ConsoleLogger getConsoleLogger()
+ {
+ return logger;
+ }
+
+ boolean isCalled()
+ {
+ return !dumpStreamText.isEmpty() || !logWarningAtEnd.isEmpty();
+ }
+ }
+
private static class EH implements EventHandler<Event>
{
private final BlockingQueue<Event> cache = new LinkedBlockingQueue<>();