This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 969cd66 Sort methods.
969cd66 is described below
commit 969cd66e3fcc51fbb14b268ee31b8ffe856a9d6d
Author: Gary Gregory <[email protected]>
AuthorDate: Tue May 21 08:37:13 2019 -0400
Sort methods.
---
.../apache/commons/lang3/time/StopWatchTest.java | 350 ++++++++++-----------
1 file changed, 175 insertions(+), 175 deletions(-)
diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
index 48926aa..18d9e97 100644
--- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
@@ -31,146 +31,35 @@ import org.junit.jupiter.api.Test;
*/
public class StopWatchTest {
- //-----------------------------------------------------------------------
- @Test
- public void testStopWatchSimple() {
- final StopWatch watch = new StopWatch();
- watch.start();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.stop();
- final long time = watch.getTime();
- assertEquals(time, watch.getTime());
-
- assertTrue(time >= 500);
- assertTrue(time < 700);
-
- watch.reset();
- assertEquals(0, watch.getTime());
- }
-
- @Test
- public void testStopWatchStatic() {
+ /**
+ * <p>
+ * Creates a suspended StopWatch object which appears to have elapsed
+ * for the requested amount of time in nanoseconds.
+ * <p>
+ * <p>
+ * <pre>
+ * // Create a mock StopWatch with a time of 2:59:01.999
+ * final long nanos = TimeUnit.HOURS.toNanos(2)
+ * + TimeUnit.MINUTES.toNanos(59)
+ * + TimeUnit.SECONDS.toNanos(1)
+ * + TimeUnit.MILLISECONDS.toNanos(999);
+ * final StopWatch watch = createMockStopWatch(nanos);
+ * </pre>
+ *
+ * @param nanos Time in nanoseconds to have elapsed on the stop watch
+ * @return StopWatch in a suspended state with the elapsed time
+ */
+ private StopWatch createMockStopWatch(final long nanos) {
final StopWatch watch = StopWatch.createStarted();
- assertTrue(watch.isStarted());
- }
-
- @Test
- public void testStopWatchSimpleGet() {
- final StopWatch watch = new StopWatch();
- assertEquals(0, watch.getTime());
- assertEquals("00:00:00.000", watch.toString());
-
- watch.start();
- try {
- Thread.sleep(500);
- } catch (final InterruptedException ex) {
- // ignore
- }
- assertTrue(watch.getTime() < 2000);
- }
-
- @Test
- public void testStopWatchGetWithTimeUnit() {
- // Create a mock StopWatch with a time of 2:59:01.999
- final StopWatch watch = createMockStopWatch(
- TimeUnit.HOURS.toNanos(2)
- + TimeUnit.MINUTES.toNanos(59)
- + TimeUnit.SECONDS.toNanos(1)
- + TimeUnit.MILLISECONDS.toNanos(999));
-
- assertEquals(2L, watch.getTime(TimeUnit.HOURS));
- assertEquals(179L, watch.getTime(TimeUnit.MINUTES));
- assertEquals(10741L, watch.getTime(TimeUnit.SECONDS));
- assertEquals(10741999L, watch.getTime(TimeUnit.MILLISECONDS));
- }
-
- @Test
- public void testStopWatchSplit() {
- final StopWatch watch = new StopWatch();
- watch.start();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.split();
- final long splitTime = watch.getSplitTime();
- final String splitStr = watch.toSplitString();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.unsplit();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.stop();
- final long totalTime = watch.getTime();
-
- assertEquals(splitStr.length(), 12, "Formatted split string not the
correct length");
- assertTrue(splitTime >= 500);
- assertTrue(splitTime < 700);
- assertTrue(totalTime >= 1500);
- assertTrue(totalTime < 1900);
- }
-
- @Test
- public void testStopWatchSuspend() {
- final StopWatch watch = new StopWatch();
- watch.start();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
watch.suspend();
- final long suspendTime = watch.getTime();
- try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.resume();
try {
- Thread.sleep(550);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.stop();
- final long totalTime = watch.getTime();
-
- assertTrue(suspendTime >= 500);
- assertTrue(suspendTime < 700);
- assertTrue(totalTime >= 1000);
- assertTrue(totalTime < 1300);
- }
-
- @Test
- public void testLang315() {
- final StopWatch watch = new StopWatch();
- watch.start();
- try {
- Thread.sleep(200);
- } catch (final InterruptedException ex) {
- // ignore
- }
- watch.suspend();
- final long suspendTime = watch.getTime();
- try {
- Thread.sleep(200);
- } catch (final InterruptedException ex) {
- // ignore
+ final long currentNanos = System.nanoTime();
+ FieldUtils.writeField(watch, "startTime", currentNanos - nanos,
true);
+ FieldUtils.writeField(watch, "stopTime", currentNanos, true);
+ } catch (final IllegalAccessException e) {
+ return null;
}
- watch.stop();
- final long totalTime = watch.getTime();
- assertEquals(suspendTime, totalTime);
+ return watch;
}
// test bad states
@@ -233,6 +122,29 @@ public class StopWatchTest {
}
@Test
+ public void testBooleanStates() {
+ final StopWatch watch = new StopWatch();
+ assertFalse(watch.isStarted());
+ assertFalse(watch.isSuspended());
+ assertTrue(watch.isStopped());
+
+ watch.start();
+ assertTrue(watch.isStarted());
+ assertFalse(watch.isSuspended());
+ assertFalse(watch.isStopped());
+
+ watch.suspend();
+ assertTrue(watch.isStarted());
+ assertTrue(watch.isSuspended());
+ assertFalse(watch.isStopped());
+
+ watch.stop();
+ assertFalse(watch.isStarted());
+ assertFalse(watch.isSuspended());
+ assertTrue(watch.isStopped());
+ }
+
+ @Test
public void testGetStartTime() {
final long beforeStopWatch = System.currentTimeMillis();
final StopWatch watch = new StopWatch();
@@ -253,56 +165,144 @@ public class StopWatchTest {
}
@Test
- public void testBooleanStates() {
+ public void testLang315() {
final StopWatch watch = new StopWatch();
- assertFalse(watch.isStarted());
- assertFalse(watch.isSuspended());
- assertTrue(watch.isStopped());
+ watch.start();
+ try {
+ Thread.sleep(200);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.suspend();
+ final long suspendTime = watch.getTime();
+ try {
+ Thread.sleep(200);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.stop();
+ final long totalTime = watch.getTime();
+ assertEquals(suspendTime, totalTime);
+ }
+
+ @Test
+ public void testStopWatchGetWithTimeUnit() {
+ // Create a mock StopWatch with a time of 2:59:01.999
+ final StopWatch watch = createMockStopWatch(
+ TimeUnit.HOURS.toNanos(2)
+ + TimeUnit.MINUTES.toNanos(59)
+ + TimeUnit.SECONDS.toNanos(1)
+ + TimeUnit.MILLISECONDS.toNanos(999));
+
+ assertEquals(2L, watch.getTime(TimeUnit.HOURS));
+ assertEquals(179L, watch.getTime(TimeUnit.MINUTES));
+ assertEquals(10741L, watch.getTime(TimeUnit.SECONDS));
+ assertEquals(10741999L, watch.getTime(TimeUnit.MILLISECONDS));
+ }
+ //-----------------------------------------------------------------------
+ @Test
+ public void testStopWatchSimple() {
+ final StopWatch watch = new StopWatch();
watch.start();
- assertTrue(watch.isStarted());
- assertFalse(watch.isSuspended());
- assertFalse(watch.isStopped());
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.stop();
+ final long time = watch.getTime();
+ assertEquals(time, watch.getTime());
- watch.suspend();
- assertTrue(watch.isStarted());
- assertTrue(watch.isSuspended());
- assertFalse(watch.isStopped());
+ assertTrue(time >= 500);
+ assertTrue(time < 700);
+
+ watch.reset();
+ assertEquals(0, watch.getTime());
+ }
+
+ @Test
+ public void testStopWatchSimpleGet() {
+ final StopWatch watch = new StopWatch();
+ assertEquals(0, watch.getTime());
+ assertEquals("00:00:00.000", watch.toString());
+ watch.start();
+ try {
+ Thread.sleep(500);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ assertTrue(watch.getTime() < 2000);
+ }
+
+ @Test
+ public void testStopWatchSplit() {
+ final StopWatch watch = new StopWatch();
+ watch.start();
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.split();
+ final long splitTime = watch.getSplitTime();
+ final String splitStr = watch.toSplitString();
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.unsplit();
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
watch.stop();
- assertFalse(watch.isStarted());
- assertFalse(watch.isSuspended());
- assertTrue(watch.isStopped());
+ final long totalTime = watch.getTime();
+
+ assertEquals(splitStr.length(), 12, "Formatted split string not the
correct length");
+ assertTrue(splitTime >= 500);
+ assertTrue(splitTime < 700);
+ assertTrue(totalTime >= 1500);
+ assertTrue(totalTime < 1900);
}
- /**
- * <p>
- * Creates a suspended StopWatch object which appears to have elapsed
- * for the requested amount of time in nanoseconds.
- * <p>
- * <p>
- * <pre>
- * // Create a mock StopWatch with a time of 2:59:01.999
- * final long nanos = TimeUnit.HOURS.toNanos(2)
- * + TimeUnit.MINUTES.toNanos(59)
- * + TimeUnit.SECONDS.toNanos(1)
- * + TimeUnit.MILLISECONDS.toNanos(999);
- * final StopWatch watch = createMockStopWatch(nanos);
- * </pre>
- *
- * @param nanos Time in nanoseconds to have elapsed on the stop watch
- * @return StopWatch in a suspended state with the elapsed time
- */
- private StopWatch createMockStopWatch(final long nanos) {
+ @Test
+ public void testStopWatchStatic() {
final StopWatch watch = StopWatch.createStarted();
+ assertTrue(watch.isStarted());
+ }
+
+ @Test
+ public void testStopWatchSuspend() {
+ final StopWatch watch = new StopWatch();
+ watch.start();
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
watch.suspend();
+ final long suspendTime = watch.getTime();
try {
- final long currentNanos = System.nanoTime();
- FieldUtils.writeField(watch, "startTime", currentNanos - nanos,
true);
- FieldUtils.writeField(watch, "stopTime", currentNanos, true);
- } catch (final IllegalAccessException e) {
- return null;
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
}
- return watch;
+ watch.resume();
+ try {
+ Thread.sleep(550);
+ } catch (final InterruptedException ex) {
+ // ignore
+ }
+ watch.stop();
+ final long totalTime = watch.getTime();
+
+ assertTrue(suspendTime >= 500);
+ assertTrue(suspendTime < 700);
+ assertTrue(totalTime >= 1000);
+ assertTrue(totalTime < 1300);
}
}