@Test public void testIncrTotal_multiple_calls() { // Arrange RateMetric rateMetric = new RateMetric(totalCountKey, partialCountKey, percentKey); // Act rateMetric.incrTotal(); rateMetric.incrTotal(); rateMetric.incrTotal(); // Assert int totalCount = rateMetric.metricValues.get(totalCountKey); Assert.assertEquals(3, totalCount); }
@Test public void testGetValueAndReset() { // Arrange RateMetric rateMetric = new RateMetric(totalCountKey, partialCountKey, percentKey); // Act rateMetric.incrTotal(); rateMetric.incrTotal(); rateMetric.incrTotal(); rateMetric.incrPartial(); Map<String, Integer> metricValues = (Map<String, Integer>) rateMetric.getValueAndReset(); int totalCount = metricValues.get(totalCountKey); int partialCount = metricValues.get(partialCountKey); int percentage = metricValues.get(percentKey); // Assert Assert.assertEquals(3, totalCount); Assert.assertEquals(1, partialCount); Assert.assertEquals(33, percentage); }