Merge branch 'master' of ../controller
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / SynchronizedDurationStatsTrackerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12
13 import org.junit.Test;
14
15 public class SynchronizedDurationStatsTrackerTest {
16
17     @Test
18     public void testAllMethodsOfSynchronizedDurationStatsTracker() {
19         final SynchronizedDurationStatsTracker statsTracker = new SynchronizedDurationStatsTracker();
20         statsTracker.addDuration(1000);
21         statsTracker.addDuration(2000);
22         statsTracker.addDuration(3000);
23
24         assertEquals("Shortest recorded duration should be '1000'.", 1000, statsTracker.getShortest().getDuration());
25         assertEquals("Average recorded duration should be '2000'.", 2000, statsTracker.getAverageDuration(), 0.0001);
26         assertEquals("Longest recorded duration should be '3000'.", 3000, statsTracker.getLongest().getDuration());
27         assertEquals("Total recorded duration count should be '3'.", 3, statsTracker.getTotalDurations());
28
29         statsTracker.reset();
30
31         assertNull("Shortest recorded duration should be 'null'.", statsTracker.getShortest());
32         assertEquals("Average recorded duration should be '0'.", 0, statsTracker.getAverageDuration(), 0.0001);
33         assertNull("Longest recorded duration should be '0'.", statsTracker.getLongest());
34         assertEquals("Total recorded duration should be '0'.", 0, statsTracker.getTotalDurations());
35     }
36 }