Add unit tests to cover negative cases

- Cover when the profile is not started/stopped

Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>

This closes #509
This commit is contained in:
wilderrodrigues 2015-06-22 16:05:15 +02:00
parent 78c802a539
commit f29bf1e85c

View File

@ -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());
}
}