From f29bf1e85c84f7a7c91ff9521b41b32532f737ee Mon Sep 17 00:00:00 2001 From: wilderrodrigues Date: Mon, 22 Jun 2015 16:05:15 +0200 Subject: [PATCH] Add unit tests to cover negative cases - Cover when the profile is not started/stopped Signed-off-by: wilderrodrigues This closes #509 --- utils/test/com/cloud/utils/TestProfiler.java | 32 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/utils/test/com/cloud/utils/TestProfiler.java b/utils/test/com/cloud/utils/TestProfiler.java index 2690a262e76..4323f1d3c71 100644 --- a/utils/test/com/cloud/utils/TestProfiler.java +++ b/utils/test/com/cloud/utils/TestProfiler.java @@ -32,11 +32,11 @@ public class TestProfiler extends Log4jEnabledTestCase { public void testProfiler() { s_logger.info("testProfiler() started"); - Profiler pf = new Profiler(); + final Profiler pf = new Profiler(); pf.start(); try { Thread.sleep(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } pf.stop(); @@ -46,4 +46,30 @@ public class TestProfiler extends Log4jEnabledTestCase { s_logger.info("testProfiler() stopped"); } -} + + @Test + public void testProfilerNoStart() { + final Profiler pf = new Profiler(); + try { + Thread.sleep(20); + } catch (final InterruptedException e) { + } + pf.stop(); + + Assert.assertTrue(pf.getDuration() == -1); + Assert.assertFalse(pf.isStarted()); + } + + @Test + public void testProfilerNoStop() { + final Profiler pf = new Profiler(); + pf.start(); + try { + Thread.sleep(20); + } catch (final InterruptedException e) { + } + + Assert.assertTrue(pf.getDuration() == -1); + Assert.assertFalse(pf.isStopped()); + } +} \ No newline at end of file