diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-30 15:12:24 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-30 15:12:24 +0200 |
commit | b2ce89c7d12d0b77d7aaf273c8f4c0516ded7bd5 (patch) | |
tree | f37f50633caa356d64ddb7b7e2cc6571661e2394 /statistics | |
parent | 2b18385e21151985edb7a9d0a85daa2332daa4a5 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'statistics')
5 files changed, 63 insertions, 20 deletions
diff --git a/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java b/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java index 91a19605286..b452c6eb204 100644 --- a/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java @@ -8,13 +8,18 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Test set for groups of counters. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class CounterGroupTestCase extends junit.framework.TestCase { +public class CounterGroupTestCase { + private volatile boolean gotRecord = false; private class CounterGroupHandler extends Handler { @@ -40,6 +45,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { } } + @Test public void testBasic() { Logger logger = Logger.getLogger(CounterGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -64,6 +70,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testObjectContracts() { CounterGroup c = new CounterGroup("test", Statistics.nullImplementation, false); CounterGroup c2 = new CounterGroup("test", Statistics.nullImplementation, false); @@ -77,6 +84,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { c.equals(c2)); } + @Test public void testConfigStuff() { Logger logger = Logger.getLogger(CounterGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); diff --git a/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java b/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java index 56258f60fc7..b33586a6428 100644 --- a/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java @@ -1,20 +1,24 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.statistics; - import java.util.Arrays; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Check counters work. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class CounterTestCase extends junit.framework.TestCase { +public class CounterTestCase { + @Test public void testBasic() { Counter c = new Counter("test", Statistics.nullImplementation, false); c.increment(); @@ -32,6 +36,7 @@ public class CounterTestCase extends junit.framework.TestCase { assertEquals(0, c.get()); } + @Test public void testObjectContracts() { final String counterName = "test"; Counter c = new Counter(counterName, Statistics.nullImplementation, false); @@ -51,6 +56,7 @@ public class CounterTestCase extends junit.framework.TestCase { assertEquals(prefix, image.substring(0, prefix.length())); } + @Test public void testConfigStuff() { Logger logger = Logger.getLogger(Counter.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); diff --git a/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java b/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java index 3d1edf8616b..6b970220b74 100644 --- a/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java @@ -2,20 +2,20 @@ package com.yahoo.statistics; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * Some low level checking of the histograms. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class HistogramTestCase extends junit.framework.TestCase { - - public HistogramTestCase(String name) { - super(name); - } +public class HistogramTestCase { + @Test public void testFindBucket() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -32,6 +32,7 @@ public class HistogramTestCase extends junit.framework.TestCase { } + @Test public void testMerge() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -46,6 +47,7 @@ public class HistogramTestCase extends junit.framework.TestCase { assertEquals("(0) < 0.5 (3) < 1.0 (0) < 5.0 (0)", h2.toString()); } + @Test public void testMultiDimensionalMerge() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -63,6 +65,7 @@ public class HistogramTestCase extends junit.framework.TestCase { h.toString()); } + @Test public void testEmptyHistogram() { try { new Histogram(new Limits()); diff --git a/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java b/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java index eabfb61acd3..b92182c3534 100644 --- a/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java @@ -7,13 +7,19 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Test set for groups of values. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class ValueGroupTestCase extends junit.framework.TestCase { +public class ValueGroupTestCase { + private volatile boolean gotRecord = false; private class ValueGroupHandler extends Handler { @@ -39,6 +45,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { } } + @Test public void testBasic() { Logger logger = Logger.getLogger(ValueGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -64,6 +71,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testOverlappingSubnames() { final MockStatistics manager = new MockStatistics(); ValueGroup v = new ValueGroup("jappe", manager); @@ -76,6 +84,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { assertEquals(2, manager.registerCount); } + @Test public void testObjectContracts() { ValueGroup v = new ValueGroup("test", new MockStatistics()); ValueGroup v2 = new ValueGroup("test", new MockStatistics()); diff --git a/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java b/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java index 2804442a982..5650d8125b6 100644 --- a/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java @@ -9,14 +9,22 @@ import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; import static com.yahoo.container.StatisticsConfig.Values.Operations; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import com.yahoo.statistics.Value.Parameters; +import org.junit.Test; /** * Check correct statistics are generated for basic values. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class ValueTestCase extends junit.framework.TestCase { +public class ValueTestCase { + + private static final double delta = 0.0000000001; private static final String NALLE = "nalle"; private static final double SECOND = 43.0d; @@ -36,6 +44,7 @@ public class ValueTestCase extends junit.framework.TestCase { } + @Test public void testMean() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMean(true)); v.put(1.0); @@ -48,6 +57,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Value should have been reset.", 0.0d == v.getMean()); } + @Test public void testMin() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMin(true)); v.put(2.0); @@ -59,6 +69,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Min should be -1.0", -1.0 == v.getMin()); } + @Test public void testMax() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMax(true)); v.put(-1.0); @@ -71,6 +82,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Max should be 4.0", 4.0 == v.getMax()); } + @Test public void testHistogram() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters() .setLogHistogram(true).setHistogramId(HistogramType.REGULAR) @@ -84,6 +96,7 @@ public class ValueTestCase extends junit.framework.TestCase { " thingie (1) < 0.0 (1) < 1.0 (1) < 2.0 (2)")); } + @Test public void testCallback() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -91,14 +104,15 @@ public class ValueTestCase extends junit.framework.TestCase { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters() .setLogRaw(true).setCallback(new TrivialCallback())); v.run(); - assertEquals(FIRST, v.get()); + assertEquals(FIRST, v.get(), delta); v.run(); - assertEquals(SECOND, v.get()); + assertEquals(SECOND, v.get(), delta); v.run(); - assertEquals(SECOND, v.get()); + assertEquals(SECOND, v.get(), delta); logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testParameter() { Value.Parameters p = new Value.Parameters().setLogInsertions(true) .setNameExtension(true).setAppendChar('_'); @@ -148,6 +162,7 @@ public class ValueTestCase extends junit.framework.TestCase { } } + @Test public void testParameterFromConfig() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -173,13 +188,14 @@ public class ValueTestCase extends junit.framework.TestCase { Value v = Value.buildValue(NALLE, m, null); final double x = 79.0d; v.put(x); - assertEquals(x, v.getMean()); + assertEquals(x, v.getMean(), delta); v.run(); assertEquals(true, h.gotRecord); logger.removeHandler(h); logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testReverseHistogram() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -209,6 +225,7 @@ public class ValueTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testCumulativeHistogram() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -238,6 +255,7 @@ public class ValueTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testObjectContracts() { final String valueName = "test"; Value v = new Value(valueName, Statistics.nullImplementation, Value.defaultParameters()); @@ -256,7 +274,6 @@ public class ValueTestCase extends junit.framework.TestCase { assertEquals(valueName, image.substring(image.length() - valueName.length())); } - public class MockStatistics implements Statistics { public StatisticsConfig config = null; public int registerCount = 0; |