2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
13 import org.junit.Test;
15 public class SynchronizedDurationStatsTrackerTest {
18 public void testAllMethodsOfSynchronizedDurationStatsTracker() {
19 final SynchronizedDurationStatsTracker statsTracker = new SynchronizedDurationStatsTracker();
20 statsTracker.addDuration(1000);
21 statsTracker.addDuration(2000);
22 statsTracker.addDuration(3000);
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());
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());