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 2019/07/11 23:52:02 UTC
[maven-surefire] 02/02: fixed JaCoCo coverage in the package
'org.apache.maven.surefire.booter'
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch maven2surefire-jvm-communication
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 160e410d8d38616cad35da9d1dea9259efa6f78d
Author: tibordigana <ti...@apache.org>
AuthorDate: Fri Jul 12 01:51:20 2019 +0200
fixed JaCoCo coverage in the package 'org.apache.maven.surefire.booter'
---
.../maven/plugin/surefire/CommonReflector.java | 18 +++++-
.../maven/plugin/surefire/CommonReflectorTest.java | 50 +++++++++++++++
.../plugin/surefire/SurefireReflectorTest.java | 71 ----------------------
.../org/apache/maven/surefire/JUnit4SuiteTest.java | 2 -
.../maven/surefire/testset/TestListResolver.java | 2 +-
surefire-booter/pom.xml | 15 ++---
.../maven/surefire/booter/SurefireReflector.java | 15 -----
...=> DefaultMasterProcessChannelDecoderTest.java} | 5 +-
.../surefire/booter/IsolatedClassLoaderTest.java | 66 ++++++++++++++++++++
.../maven/surefire/booter/JUnit4SuiteTest.java | 5 +-
.../surefire/booter/SurefireReflectorTest.java | 28 ---------
11 files changed, 143 insertions(+), 134 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
index 835fb89..466148f 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
@@ -23,8 +23,8 @@ import org.apache.maven.plugin.surefire.extensions.SurefireConsoleOutputReporter
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
-import org.apache.maven.surefire.booter.SurefireReflector;
import org.apache.maven.surefire.util.SurefireReflectionException;
import javax.annotation.Nonnull;
@@ -71,7 +71,7 @@ public class CommonReflector
{
Class<?>[] args = { this.startupReportConfiguration, this.consoleLogger };
Object src = createStartupReportConfiguration( startupReportConfiguration );
- Object logger = SurefireReflector.createConsoleLogger( consoleLogger, surefireClassLoader );
+ Object logger = createConsoleLogger( consoleLogger, surefireClassLoader );
Object[] params = { src, logger };
return instantiateObject( DefaultReporterFactory.class.getName(), args, params, surefireClassLoader );
}
@@ -84,7 +84,6 @@ public class CommonReflector
int.class, String.class, String.class, boolean.class,
statelessTestsetReporter, consoleOutputReporter,
statelessTestsetInfoReporter );
- //noinspection BooleanConstructorCall
Object[] params = { reporterConfiguration.isUseFile(), reporterConfiguration.isPrintSummary(),
reporterConfiguration.getReportFormat(), reporterConfiguration.isRedirectTestOutputToFile(),
reporterConfiguration.getReportsDirectory(),
@@ -98,4 +97,17 @@ public class CommonReflector
};
return newInstance( constructor, params );
}
+
+ static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl )
+ {
+ try
+ {
+ Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() );
+ return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger );
+ }
+ catch ( Exception e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ }
}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java
index b00d131..b7d04c5 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java
@@ -23,15 +23,30 @@ import org.apache.maven.plugin.surefire.extensions.SurefireConsoleOutputReporter
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
+import org.apache.maven.plugin.surefire.log.api.PrintStreamLogger;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import java.io.File;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.maven.surefire.util.ReflectionUtils.getMethod;
+import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray;
import static org.fest.assertions.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.powermock.reflect.Whitebox.getInternalState;
public class CommonReflectorTest
@@ -93,4 +108,39 @@ public class CommonReflectorTest
assertThat( reportConfiguration.getConsoleOutputReporter().toString() )
.isEqualTo( consoleOutputReporter.toString() );
}
+
+ @Test
+ public void shouldProxyConsoleLogger()
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ ConsoleLogger logger = spy( new PrintStreamLogger( System.out ) );
+ Object mirror = CommonReflector.createConsoleLogger( logger, cl );
+ MatcherAssert.assertThat( mirror, is( notNullValue() ) );
+ MatcherAssert.assertThat( mirror.getClass().getInterfaces()[0].getName(), is( ConsoleLogger.class.getName() ) );
+ MatcherAssert.assertThat( mirror, is( not( sameInstance( (Object) logger ) ) ) );
+ MatcherAssert.assertThat( mirror, is( instanceOf( ConsoleLoggerDecorator.class ) ) );
+ invokeMethodWithArray( mirror, getMethod( mirror, "info", String.class ), "Hi There!" );
+ verify( logger, times( 1 ) ).info( "Hi There!" );
+ }
+
+ @Test
+ public void testCreateConsoleLogger()
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ ConsoleLogger consoleLogger = mock( ConsoleLogger.class );
+ ConsoleLogger decorator = (ConsoleLogger) CommonReflector.createConsoleLogger( consoleLogger, cl );
+ assertThat( decorator )
+ .isNotSameAs( consoleLogger );
+
+ assertThat( decorator.isDebugEnabled() ).isFalse();
+ when( consoleLogger.isDebugEnabled() ).thenReturn( true );
+ assertThat( decorator.isDebugEnabled() ).isTrue();
+ verify( consoleLogger, times( 2 ) ).isDebugEnabled();
+
+ decorator.info( "msg" );
+ ArgumentCaptor<String> argumentMsg = ArgumentCaptor.forClass( String.class );
+ verify( consoleLogger, times( 1 ) ).info( argumentMsg.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "msg" );
+ }
}
\ No newline at end of file
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireReflectorTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireReflectorTest.java
deleted file mode 100644
index 2553617..0000000
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireReflectorTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.apache.maven.plugin.surefire;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
-import org.apache.maven.plugin.surefire.log.api.PrintStreamLogger;
-import org.apache.maven.surefire.booter.IsolatedClassLoader;
-import org.apache.maven.surefire.booter.SurefireReflector;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.apache.maven.surefire.util.ReflectionUtils.getMethod;
-import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-/**
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @see ConsoleLogger
- * @see SurefireReflector
- * @since 2.20
- */
-public class SurefireReflectorTest
-{
- private ConsoleLogger logger;
- private ClassLoader cl;
-
- @Before
- public void prepareData()
- {
- logger = spy( new PrintStreamLogger( System.out ) );
- cl = new IsolatedClassLoader( Thread.currentThread().getContextClassLoader(), false, "role" );
- }
-
- @Test
- public void shouldProxyConsoleLogger()
- {
- Object mirror = SurefireReflector.createConsoleLogger( logger, cl );
- assertThat( mirror, is( notNullValue() ) );
- assertThat( mirror.getClass().getInterfaces()[0].getName(), is( ConsoleLogger.class.getName() ) );
- assertThat( mirror, is( not( sameInstance( (Object) logger ) ) ) );
- assertThat( mirror, is( instanceOf( ConsoleLoggerDecorator.class ) ) );
- invokeMethodWithArray( mirror, getMethod( mirror, "info", String.class ), "Hi There!" );
- verify( logger, times( 1 ) ).info( "Hi There!" );
- }
-}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
index d28a89c..254ff97 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
@@ -28,7 +28,6 @@ import org.apache.maven.plugin.surefire.AbstractSurefireMojoTest;
import org.apache.maven.plugin.surefire.CommonReflectorTest;
import org.apache.maven.plugin.surefire.MojoMocklessTest;
import org.apache.maven.plugin.surefire.SurefireHelperTest;
-import org.apache.maven.plugin.surefire.SurefireReflectorTest;
import org.apache.maven.plugin.surefire.SurefirePropertiesTest;
import org.apache.maven.plugin.surefire.booterclient.BooterDeserializerProviderConfigurationTest;
import org.apache.maven.plugin.surefire.booterclient.BooterDeserializerStartupConfigurationTest;
@@ -88,7 +87,6 @@ public class JUnit4SuiteTest extends TestCase
suite.addTest( new JUnit4TestAdapter( TestProvidingInputStreamTest.class ) );
suite.addTest( new JUnit4TestAdapter( TestLessInputStreamBuilderTest.class ) );
suite.addTest( new JUnit4TestAdapter( SPITest.class ) );
- suite.addTest( new JUnit4TestAdapter( SurefireReflectorTest.class ) );
suite.addTest( new JUnit4TestAdapter( SurefireHelperTest.class ) );
suite.addTest( new JUnit4TestAdapter( AbstractSurefireMojoTest.class ) );
suite.addTest( new JUnit4TestAdapter( DefaultForkConfigurationTest.class ) );
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java
index 266d06a..28b784f 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java
@@ -41,7 +41,7 @@ import static org.apache.maven.surefire.testset.ResolvedTest.Type.METHOD;
* composed of included and excluded tests.<br>
* The methods {@link #shouldRun(String, String)} are filters easily used in JUnit filter or TestNG.
* This class is independent of JUnit and TestNG API.<br>
- * It is accessed by Java Reflection API in {@link org.apache.maven.surefire.booter.SurefireReflector}
+ * It is accessed by Java Reflection API in {@code org.apache.maven.surefire.booter.SurefireReflector}
* using specific ClassLoader.
*/
public class TestListResolver
diff --git a/surefire-booter/pom.xml b/surefire-booter/pom.xml
index efa3124..d4bc382 100644
--- a/surefire-booter/pom.xml
+++ b/surefire-booter/pom.xml
@@ -122,18 +122,15 @@
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
- <id>jacoco-instrumentation</id>
+ <id>jacoco-agent</id>
<goals>
- <goal>instrument</goal>
- </goals>
- </execution>
- <execution>
- <id>restore-classes</id>
- <goals>
- <goal>restore-instrumented-classes</goal>
+ <goal>prepare-agent</goal>
</goals>
</execution>
</executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
@@ -145,7 +142,7 @@
</dependency>
</dependencies>
<configuration>
- <argLine>${jvm.args.tests}</argLine>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<includes>
<include>**/JUnit4SuiteTest.java</include>
</includes>
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
similarity index 96%
rename from surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
rename to surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
index df47df4..20ff510 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
@@ -19,8 +19,6 @@ package org.apache.maven.surefire.booter;
* under the License.
*/
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
import org.apache.maven.surefire.cli.CommandLineOption;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ReporterConfiguration;
@@ -369,17 +367,4 @@ public final class SurefireReflector
}
return ordinals;
}
-
- public static Object createConsoleLogger( ConsoleLogger consoleLogger, ClassLoader cl )
- {
- try
- {
- Class<?> decoratorClass = cl.loadClass( ConsoleLoggerDecorator.class.getName() );
- return getConstructor( decoratorClass, Object.class ).newInstance( consoleLogger );
- }
- catch ( Exception e )
- {
- throw new SurefireReflectionException( e );
- }
- }
}
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/DefaultMasterProcessChannelDecoderTest.java
similarity index 98%
rename from surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
rename to surefire-booter/src/test/java/org/apache/maven/surefire/booter/DefaultMasterProcessChannelDecoderTest.java
index c9ea095..62964f7 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessCommandTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/DefaultMasterProcessChannelDecoderTest.java
@@ -31,10 +31,9 @@ import static org.hamcrest.Matchers.*;
import static org.fest.assertions.Assertions.assertThat;
/**
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 2.19
+ * Tests for {@link DefaultMasterProcessChannelDecoder}.
*/
-public class MasterProcessCommandTest
+public class DefaultMasterProcessChannelDecoderTest
extends TestCase
{
public void testDataToByteArrayAndBack() throws IOException
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java
new file mode 100644
index 0000000..b424526
--- /dev/null
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java
@@ -0,0 +1,66 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.shared.utils.io.FileUtils;
+import org.apache.maven.surefire.providerapi.AbstractProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+
+import static java.io.File.pathSeparator;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Tests isolated CL.
+ */
+public class IsolatedClassLoaderTest
+{
+ private IsolatedClassLoader classLoader;
+
+ @Before
+ public void prepareClassLoader() throws Exception
+ {
+ classLoader = new IsolatedClassLoader( null, false, "role" );
+
+ String[] files = FileUtils.fileRead( new File( "target/test-classpath/cp.txt" ), "UTF-8" )
+ .split( pathSeparator );
+
+ for ( String file : files )
+ {
+ URL fileUrl = new File( file ).toURL();
+ classLoader.addURL( fileUrl );
+ }
+ }
+
+ @Test
+ public void shouldLoadIsolatedClass() throws Exception
+ {
+ Class<?> isolatedClass = classLoader.loadClass( AbstractProvider.class.getName() );
+ assertThat( isolatedClass, is( notNullValue() ) );
+ assertThat( isolatedClass.getName(), is( AbstractProvider.class.getName() ) );
+ assertThat( isolatedClass, is( not( (Class) AbstractProvider.class ) ) );
+ }
+}
\ No newline at end of file
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
index caea335..2ae250e 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
@@ -36,12 +36,13 @@ public class JUnit4SuiteTest extends TestCase
{
TestSuite suite = new TestSuite();
suite.addTest( new JUnit4TestAdapter( CommandReaderTest.class ) );
- suite.addTest( new JUnit4TestAdapter( MasterProcessCommandTest.class ) );
- suite.addTest( new JUnit4TestAdapter( SurefireReflectorTest.class ) );
suite.addTest( new JUnit4TestAdapter( PpidCheckerTest.class ) );
suite.addTest( new JUnit4TestAdapter( SystemUtilsTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( IsolatedClassLoaderTest.class ) );
suite.addTestSuite( ClasspathTest.class );
suite.addTestSuite( PropertiesWrapperTest.class );
+ suite.addTestSuite( DefaultMasterProcessChannelDecoderTest.class );
+ suite.addTestSuite( SurefireReflectorTest.class );
return suite;
}
}
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SurefireReflectorTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SurefireReflectorTest.java
index 9b3b7a8..9c06bc6 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SurefireReflectorTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SurefireReflectorTest.java
@@ -19,7 +19,6 @@ package org.apache.maven.surefire.booter;
*/
import junit.framework.TestCase;
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.ReporterFactory;
import org.apache.maven.surefire.report.RunListener;
@@ -30,7 +29,6 @@ import org.apache.maven.surefire.testset.TestArtifactInfo;
import org.apache.maven.surefire.testset.TestListResolver;
import org.apache.maven.surefire.testset.TestRequest;
import org.apache.maven.surefire.util.RunOrder;
-import org.mockito.ArgumentCaptor;
import java.io.File;
import java.lang.reflect.Method;
@@ -38,35 +36,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
public class SurefireReflectorTest
extends TestCase
{
- public void testCreateConsoleLogger()
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- ConsoleLogger consoleLogger = mock( ConsoleLogger.class );
- ConsoleLogger decorator = (ConsoleLogger) SurefireReflector.createConsoleLogger( consoleLogger, cl );
- assertThat( decorator )
- .isNotSameAs( consoleLogger );
-
- assertThat( decorator.isDebugEnabled() ).isFalse();
- when( consoleLogger.isDebugEnabled() ).thenReturn( true );
- assertThat( decorator.isDebugEnabled() ).isTrue();
- verify( consoleLogger, times( 2 ) ).isDebugEnabled();
-
- decorator.info( "msg" );
- ArgumentCaptor<String> argumentMsg = ArgumentCaptor.forClass( String.class );
- verify( consoleLogger, times( 1 ) ).info( argumentMsg.capture() );
- assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
- assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "msg" );
- }
-
public void testShouldCreateFactoryWithoutException()
{
ReporterFactory factory = new ReporterFactory()