You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2014/10/07 22:15:11 UTC

git commit: Add unit test

Repository: qpid-jms
Updated Branches:
  refs/heads/master 6973cb51d -> 6ed98ed91


Add unit test

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6ed98ed9
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6ed98ed9
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6ed98ed9

Branch: refs/heads/master
Commit: 6ed98ed91055cc6c67a3dddb88257f1b7d7b153f
Parents: 6973cb5
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Oct 7 16:15:06 2014 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Oct 7 16:15:06 2014 -0400

----------------------------------------------------------------------
 .../org/apache/qpid/jms/util/StopWatchTest.java | 73 ++++++++++++++++++++
 1 file changed, 73 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6ed98ed9/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/StopWatchTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/StopWatchTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/StopWatchTest.java
new file mode 100644
index 0000000..09e51fa
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/StopWatchTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+package org.apache.qpid.jms.util;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class StopWatchTest extends TestCase {
+
+    public void testStopWatch() throws Exception {
+        StopWatch watch = new StopWatch();
+        Thread.sleep(200);
+        long taken = watch.stop();
+
+        assertEquals(taken, watch.taken());
+        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
+    }
+
+    public void testStopWatchNotStarted() throws Exception {
+        StopWatch watch = new StopWatch(false);
+        long taken = watch.stop();
+        assertEquals(0, taken);
+
+        watch.restart();
+        Thread.sleep(200);
+        taken = watch.stop();
+
+        assertEquals(taken, watch.taken());
+        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
+    }
+
+    public void testStopWatchRestart() throws Exception {
+        StopWatch watch = new StopWatch();
+        Thread.sleep(200);
+        long taken = watch.stop();
+
+        assertEquals(taken, watch.taken());
+        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
+
+        watch.restart();
+        Thread.sleep(100);
+        taken = watch.stop();
+
+        assertEquals(taken, watch.taken());
+        assertTrue("Should take approx 100 millis, was: " + taken, taken > 50);
+    }
+
+    public void testStopWatchTaken() throws Exception {
+        StopWatch watch = new StopWatch();
+        Thread.sleep(100);
+        long taken = watch.taken();
+        Thread.sleep(100);
+        long taken2 = watch.taken();
+        assertNotSame(taken, taken2);
+        assertTrue(taken2 > taken);
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org