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 2015/04/04 14:18:02 UTC

maven-surefire git commit: [SUREFIRE] Using JUnit 4.12 Stopwatch in surefire-junit47

Repository: maven-surefire
Updated Branches:
  refs/heads/master 71160434f -> 6d28e29ad


[SUREFIRE] Using JUnit 4.12 Stopwatch in surefire-junit47


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/6d28e29a
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/6d28e29a
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/6d28e29a

Branch: refs/heads/master
Commit: 6d28e29ade0a053a463919e1d223baa0d3332abd
Parents: 7116043
Author: Tibor17 <ti...@lycos.com>
Authored: Sat Apr 4 14:10:48 2015 +0200
Committer: Tibor17 <ti...@lycos.com>
Committed: Sat Apr 4 14:10:48 2015 +0200

----------------------------------------------------------------------
 surefire-providers/surefire-junit47/pom.xml     |  2 +-
 .../pc/OptimizedParallelComputerTest.java       |  3 --
 .../pc/ParallelComputerBuilderTest.java         | 24 +++++-----
 .../junitcore/pc/ParallelComputerUtilTest.java  | 14 +++---
 .../maven/surefire/junitcore/pc/Stopwatch.java  | 46 --------------------
 5 files changed, 22 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6d28e29a/surefire-providers/surefire-junit47/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/pom.xml b/surefire-providers/surefire-junit47/pom.xml
index 78b35c8..087c01e 100644
--- a/surefire-providers/surefire-junit47/pom.xml
+++ b/surefire-providers/surefire-junit47/pom.xml
@@ -41,7 +41,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.8.1</version>
+      <version>4.12</version>
       <scope>provided</scope>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6d28e29a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/OptimizedParallelComputerTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/OptimizedParallelComputerTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/OptimizedParallelComputerTest.java
index 7860f9f..67d7683 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/OptimizedParallelComputerTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/OptimizedParallelComputerTest.java
@@ -57,9 +57,6 @@ public final class OptimizedParallelComputerTest
     @Rule
     public final ExpectedException exception = ExpectedException.none();
 
-    @Rule
-    public final Stopwatch runtime = new Stopwatch();
-
     @BeforeClass
     public static void beforeClass()
     {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6d28e29a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
index 7311ff2..d81e92e 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
@@ -27,6 +27,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.Stopwatch;
 import org.junit.runner.Description;
 import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
@@ -48,6 +49,7 @@ import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNot.not;
 import static org.apache.maven.surefire.junitcore.pc.RangeMatcher.between;
 import static org.junit.Assert.*;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 /**
  * @author Tibor Digana (tibor17)
@@ -62,7 +64,7 @@ public class ParallelComputerBuilderTest
     private static volatile Runnable shutdownTask;
 
     @Rule
-    public final Stopwatch runtime = new Stopwatch();
+    public final Stopwatch stopwatch = new Stopwatch() {};
 
     private static void testKeepBeforeAfter( ParallelComputerBuilder builder, Class<?>... classes )
     {
@@ -118,7 +120,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 0 ) );
@@ -153,7 +155,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 1 ) );
@@ -179,7 +181,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 1 ) );
@@ -211,7 +213,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 0 ) );
@@ -235,7 +237,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 0 ) );
@@ -262,7 +264,7 @@ public class ParallelComputerBuilderTest
         // Each group takes 0.5s.
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 1 ) );
@@ -286,7 +288,7 @@ public class ParallelComputerBuilderTest
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
 
         assertThat( computer.suites.size(), is( 1 ) );
         assertThat( computer.classes.size(), is( 1 ) );
@@ -303,7 +305,7 @@ public class ParallelComputerBuilderTest
     public void shutdown()
     {
         Result result = new ShutdownTest().run( false );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         assertTrue( result.wasSuccessful() );
         assertTrue( beforeShutdown );
         assertThat( timeSpent, between( 450, 1250 ) );
@@ -313,7 +315,7 @@ public class ParallelComputerBuilderTest
     public void shutdownWithInterrupt()
     {
         new ShutdownTest().run( true );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         assertTrue( beforeShutdown );
         assertThat( timeSpent, between( 450, 1250 ) );
     }
@@ -536,7 +538,7 @@ public class ParallelComputerBuilderTest
         Thread.enumerate( t );
         ArrayList<Thread> appThreads = new ArrayList<Thread>( t.length );
         Collections.addAll( appThreads, t );
-        appThreads.removeAll( Collections.singleton( null ) );
+        appThreads.removeAll( Collections.singleton( (Thread) null ) );
         Collections.sort( appThreads, new Comparator<Thread>()
         {
             public int compare( Thread t1, Thread t2 )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6d28e29a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
index 458c12a..4b0ef2e 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
@@ -31,6 +31,7 @@ import org.junit.experimental.theories.DataPoint;
 import org.junit.experimental.theories.Theories;
 import org.junit.experimental.theories.Theory;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.Stopwatch;
 import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
 import org.junit.runner.RunWith;
@@ -42,6 +43,7 @@ import static org.apache.maven.surefire.junitcore.pc.ParallelComputerUtil.*;
 import static org.apache.maven.surefire.junitcore.JUnitCoreParameters.*;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.*;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 /**
  * Testing an algorithm in {@link ParallelComputerUtil} which configures
@@ -64,7 +66,7 @@ public final class ParallelComputerUtilTest
     public final ExpectedException exception = ExpectedException.none();
 
     @Rule
-    public final Stopwatch runtime = new Stopwatch();
+    public final Stopwatch stopwatch = new Stopwatch() {};
 
     @BeforeClass
     public static void beforeClass()
@@ -969,7 +971,7 @@ public final class ParallelComputerUtilTest
         ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
         ParallelComputer pc = pcBuilder.buildComputer();
         Result result = new JUnitCore().run( pc, TestClass.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         long deltaTime = 500L;
 
         assertTrue( result.wasSuccessful() );
@@ -993,7 +995,7 @@ public final class ParallelComputerUtilTest
         ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
         ParallelComputer pc = pcBuilder.buildComputer();
         new JUnitCore().run( pc, TestClass.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         long deltaTime = 500L;
 
         assertEquals( 5000L, timeSpent, deltaTime );
@@ -1016,7 +1018,7 @@ public final class ParallelComputerUtilTest
         ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
         ParallelComputer pc = pcBuilder.buildComputer();
         new JUnitCore().run( pc, TestClass.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         long deltaTime = 500L;
 
         assertEquals( 2500L, timeSpent, deltaTime );
@@ -1042,7 +1044,7 @@ public final class ParallelComputerUtilTest
         ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
         ParallelComputer pc = pcBuilder.buildComputer();
         new JUnitCore().run( pc, TestClass.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         long deltaTime = 500L;
 
         assertEquals( 3500L, timeSpent, deltaTime );
@@ -1066,7 +1068,7 @@ public final class ParallelComputerUtilTest
         ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
         ParallelComputer pc = pcBuilder.buildComputer();
         new JUnitCore().run( pc, TestClass.class );
-        long timeSpent = runtime.stop();
+        long timeSpent = stopwatch.runtime( MILLISECONDS );
         long deltaTime = 500L;
 
         assertEquals( 3500L, timeSpent, deltaTime );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6d28e29a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
deleted file mode 100644
index 739f5ba..0000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.maven.surefire.junitcore.pc;
-
-/*
- * 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.junit.rules.TestWatchman;
-import org.junit.runners.model.FrameworkMethod;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public final class Stopwatch
-    extends TestWatchman
-{
-    private long startNanos;
-
-    public long stop()
-    {
-        return TimeUnit.MILLISECONDS.convert( System.nanoTime() - startNanos, TimeUnit.NANOSECONDS );
-    }
-
-    @Override
-    public void starting( FrameworkMethod method )
-    {
-        startNanos = System.nanoTime();
-    }
-}