summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-05-04 14:26:29 +0200
committerJon Bratseth <bratseth@oath.com>2018-05-04 14:26:29 +0200
commit8fba29168e99e86d0a8072adcaafb84337a16eb6 (patch)
tree801101c3c410fc85e4fee445fa897eef1f411fb8
parent8d41cf849b2e56bde07585bcf7ef1c1416b7b49c (diff)
Use new junit API
-rwxr-xr-xmessagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java7
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java20
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java13
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/DiskStateTestCase.java18
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java16
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java14
-rw-r--r--vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java9
-rw-r--r--vespaclient-java/src/test/java/com/yahoo/vespafeeder/ProgressPrinterTest.java9
-rw-r--r--vespajlib/src/test/java/com/yahoo/binaryprefix/BinaryScaledAmountTestCase.java10
-rw-r--r--vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java14
-rw-r--r--vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java12
-rw-r--r--vespajlib/src/test/java/com/yahoo/concurrent/EventBarrierTestCase.java15
-rw-r--r--vespajlib/src/test/java/com/yahoo/geo/BoundingBoxParserTestCase.java35
-rw-r--r--vespajlib/src/test/java/com/yahoo/geo/DegreesParserTestCase.java149
-rw-r--r--vespajlib/src/test/java/com/yahoo/geo/ZCurveTestCase.java33
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java15
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java55
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java4
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/GrowableBufferOutputStreamTestCase.java21
-rw-r--r--vespalog/src/test/java/com/yahoo/log/event/EventTestCase.java50
-rw-r--r--yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java11
-rw-r--r--yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java11
22 files changed, 321 insertions, 220 deletions
diff --git a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java
index 527896e2b44..9c980ad0d51 100755
--- a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java
+++ b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java
@@ -18,10 +18,15 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
/**
* @author Simon Thoresen
*/
-public class RoutingContextTestCase extends junit.framework.TestCase {
+public class RoutingContextTestCase {
public static final int TIMEOUT_SECS = 120;
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
index 0b97950ae1e..7a6fb13bcd4 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
@@ -8,14 +8,18 @@ import com.yahoo.vdslib.state.Node;
import com.yahoo.vdslib.state.NodeState;
import com.yahoo.vdslib.state.NodeType;
import com.yahoo.vespa.config.content.StorDistributionConfig;
-import junit.framework.TestCase;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
public class DistributionTestFactory extends CrossPlatformTestFactory {
+
private static final String testDirectory = "src/tests/distribution/testdata";
private int redundancy;
private int nodeCount;
@@ -82,22 +86,22 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
for (int i=0; i<nodes.size(); ++i) {
if (nodes.get(i) == node) return disks.get(i);
}
- TestCase.fail("Node " + node + " is not in use: " + toString());
+ fail("Node " + node + " is not in use: " + toString());
throw new IllegalStateException("Control should not reach here");
}
public Test assertFailure(Failure f) {
- TestCase.assertEquals(f, failure);
+ assertEquals(f, failure);
return this;
}
public Test assertNodeCount(int count) {
- if (count > 0) TestCase.assertEquals(toString(), Failure.NONE, failure);
- TestCase.assertEquals(toString(), count, nodes.size());
+ if (count > 0) assertEquals(toString(), Failure.NONE, failure);
+ assertEquals(toString(), count, nodes.size());
return this;
}
public Test assertNodeUsed(int node) {
- TestCase.assertEquals(toString(), Failure.NONE, failure);
- TestCase.assertTrue(toString(), nodes.contains(node));
+ assertEquals(toString(), Failure.NONE, failure);
+ assertTrue(toString(), nodes.contains(node));
return this;
}
}
@@ -158,7 +162,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
}
void verifySame(Test javaTest, Test other) {
- TestCase.assertEquals("Reference test " + testsRecorded + " differ.", other, javaTest);
+ assertEquals("Reference test " + testsRecorded + " differ.", other, javaTest);
++testsVerified;
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
index e8aac633fd5..c71216b192d 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
@@ -1,13 +1,18 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.distribution;
+import org.junit.Test;
+
import java.text.ParseException;
import java.util.*;
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
-public class GroupTestCase extends junit.framework.TestCase {
+public class GroupTestCase {
private void assertDistribution(String spec, int redundancy, String expectedResult) throws ParseException {
Group.Distribution distribution = new Group.Distribution(spec, redundancy);
@@ -30,6 +35,7 @@ public class GroupTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testStarConversion() throws ParseException {
assertDistribution("1|*|*", 5, "2,2,1");
assertDistribution("1|*|*", 6, "3,2,1");
@@ -116,6 +122,7 @@ public class GroupTestCase extends junit.framework.TestCase {
return root;
}
+ @Test
public void testNormalusage() throws ParseException {
Group root = new Group(2, "myroot", new Group.Distribution("*", 2));
assertFalse(root.isLeafGroup());
@@ -147,11 +154,13 @@ public class GroupTestCase extends junit.framework.TestCase {
return new Group.Distribution("*", 1);
}
+ @Test
public void testRootGroupDoesNotIncludeGroupNameWhenNoChildren() {
Group g = new Group(0, "donkeykong");
assertThat(g.getUnixStylePath(), is("/"));
}
+ @Test
public void testChildNamesDoNotIncludeRootGroupName() throws Exception {
Group g = new Group(0, "donkeykong", dummyDistribution());
Group child = new Group(1, "mario");
@@ -159,6 +168,7 @@ public class GroupTestCase extends junit.framework.TestCase {
assertThat(child.getUnixStylePath(), is("/mario"));
}
+ @Test
public void testNestedGroupsAreSlashSeparated() throws Exception {
Group g = new Group(0, "donkeykong", dummyDistribution());
Group mario = new Group(1, "mario", dummyDistribution());
@@ -169,6 +179,7 @@ public class GroupTestCase extends junit.framework.TestCase {
assertThat(toad.getUnixStylePath(), is("/mario/toad"));
}
+ @Test
public void testMultipleLeafGroupsAreEnumerated() throws Exception {
Group g = new Group(0, "donkeykong", dummyDistribution());
Group mario = new Group(1, "mario", dummyDistribution());
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/DiskStateTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/state/DiskStateTestCase.java
index 6357213d7f3..bdc3be3dc70 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/DiskStateTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/DiskStateTestCase.java
@@ -1,10 +1,19 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.state;
+import org.junit.Test;
+
import java.text.ParseException;
-public class DiskStateTestCase extends junit.framework.TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class DiskStateTestCase {
+
+ private static final double delta = 0.0000000001;
+ @Test
public void testEquals() {
DiskState d1 = new DiskState(State.UP, "", 1);
DiskState d2 = new DiskState(State.UP, "", 2);
@@ -39,13 +48,14 @@ public class DiskStateTestCase extends junit.framework.TestCase {
assertFalse(d1.equals("class not instance of Node"));
}
+ @Test
public void testSerialization() throws ParseException {
DiskState d = new DiskState();
DiskState other = new DiskState(d.serialize("", true));
assertEquals(d, other);
assertEquals(d.toString(), other.toString());
assertEquals(State.UP, other.getState());
- assertEquals(1.0, other.getCapacity());
+ assertEquals(1.0, other.getCapacity(), delta);
assertEquals("", other.getDescription());
assertEquals("s:u", d.serialize("", false));
assertEquals("s:u", d.serialize("", true));
@@ -59,7 +69,7 @@ public class DiskStateTestCase extends junit.framework.TestCase {
assertEquals(d, other);
assertEquals(d.toString(), other.toString());
assertEquals(State.UP, other.getState());
- assertEquals(1.0, other.getCapacity());
+ assertEquals(1.0, other.getCapacity(), delta);
assertEquals("Slow disk", other.getDescription());
assertEquals("s:u", d.serialize("", false));
assertEquals("s:u m:Slow\\x20disk", d.serialize("", true));
@@ -71,7 +81,7 @@ public class DiskStateTestCase extends junit.framework.TestCase {
assertEquals(d, other);
assertEquals(d.toString(), other.toString());
assertEquals(State.DOWN, other.getState());
- assertEquals(2.0, other.getCapacity());
+ assertEquals(2.0, other.getCapacity(), delta);
assertEquals("Failed disk", other.getDescription());
assertEquals("s:d c:2.0", d.serialize("", false));
assertEquals("s:d c:2.0 m:Failed\\x20disk", d.serialize("", true));
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
index 8f5d8bdbbe2..bbd9f8b6d56 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
@@ -1,11 +1,18 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.state;
+import org.junit.Test;
+
import java.text.ParseException;
import java.util.List;
-public class NodeStateTestCase extends junit.framework.TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class NodeStateTestCase {
+ @Test
public void testOrdinals() {
NodeType nt = NodeType.STORAGE;
@@ -34,6 +41,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
assertTrue(new NodeState(nt, State.UP).above(new NodeState(nt, State.RETIRED)));
}
+ @Test
public void testTrivialitiesToIncreaseCoverage() throws ParseException {
NodeState ns = new NodeState(NodeType.STORAGE, State.UP);
assertEquals(1, ns.getReliability());
@@ -47,6 +55,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
assertEquals(ns, NodeState.deserialize(NodeType.STORAGE, "s:u d:1 d.0:d"));
}
+ @Test
public void testDiskState() throws ParseException {
NodeState ns = NodeState.deserialize(NodeType.STORAGE, "s:m");
assertEquals(new DiskState(State.UP, "", 1), ns.getDiskState(0));
@@ -82,6 +91,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
} catch (Exception e) {}
}
+ @Test
public void testSerialization() throws ParseException {
NodeState ns = new NodeState(NodeType.STORAGE, State.MAINTENANCE);
assertEquals("s:m", ns.serialize(false));
@@ -155,6 +165,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
assertEquals(ns.serialize(true), copy2.serialize(true));
}
+ @Test
public void testSimilarTo() {
{
NodeState ns1 = new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0);
@@ -203,6 +214,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testReadableOutput() {
// toString() and getDiff() is mostly there just to make good error reports when unit tests fails. Make sure toString() is actually run with no test failures
// to make sure coverage doesn't complain when no test is failing.
@@ -219,6 +231,7 @@ public class NodeStateTestCase extends junit.framework.TestCase {
assertEquals(expected, ns1.getTextualDifference(new NodeState(NodeType.STORAGE, State.UP)).substring(0, expected.length()));
}
+ @Test
public void testValidInClusterState() {
try{
new NodeState(NodeType.DISTRIBUTOR, State.UNKNOWN).verifyValidInSystemState(NodeType.DISTRIBUTOR);
@@ -237,4 +250,5 @@ public class NodeStateTestCase extends junit.framework.TestCase {
assertTrue("Should not be valid", false);
} catch (Exception e) {}
}
+
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
index edd28b318ff..ce0af6254cb 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
@@ -1,11 +1,15 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.state;
-/**
- *
- */
-public class NodeTest extends junit.framework.TestCase {
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class NodeTest {
+
+ @Test
public void testEquals() {
Node n1 = new Node(NodeType.STORAGE, 6);
Node n2 = new Node(NodeType.STORAGE, 7);
@@ -44,6 +48,7 @@ public class NodeTest extends junit.framework.TestCase {
assertFalse(n1.equals("class not instance of Node"));
}
+ @Test
public void testSerialization() {
Node n = new Node(NodeType.STORAGE, 6);
Node other = new Node(n.toString());
@@ -75,6 +80,7 @@ public class NodeTest extends junit.framework.TestCase {
}
}
+ @Test
public void testMaySetWantedState() {
assertTrue(State.UP.maySetWantedStateForThisNodeState(State.DOWN));
assertTrue(State.UP.maySetWantedStateForThisNodeState(State.MAINTENANCE));
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
index b02d012f5bb..69372e5b1f7 100644
--- a/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
+++ b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
@@ -6,14 +6,14 @@ import com.yahoo.concurrent.Timer;
import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage;
import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage;
import com.yahoo.messagebus.EmptyReply;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
-/**
- */
-public class BenchmarkProgressPrinterTest extends TestCase {
+import static org.junit.Assert.assertTrue;
+
+public class BenchmarkProgressPrinterTest {
class DummyTimer implements Timer {
long ms;
@@ -21,6 +21,7 @@ public class BenchmarkProgressPrinterTest extends TestCase {
public long milliTime() { return ms; }
}
+ @Test
public void testSimple() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
DummyTimer timer = new DummyTimer();
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespafeeder/ProgressPrinterTest.java b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/ProgressPrinterTest.java
index 26d2ff77a0f..29154b0892a 100644
--- a/vespaclient-java/src/test/java/com/yahoo/vespafeeder/ProgressPrinterTest.java
+++ b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/ProgressPrinterTest.java
@@ -7,14 +7,14 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply;
import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage;
import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage;
import com.yahoo.messagebus.EmptyReply;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
-/**
- */
-public class ProgressPrinterTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+
+public class ProgressPrinterTest {
class DummyTimer implements Timer {
long ms;
@@ -22,6 +22,7 @@ public class ProgressPrinterTest extends TestCase {
public long milliTime() { return ms; }
}
+ @Test
public void testSimple() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
DummyTimer timer = new DummyTimer();
diff --git a/vespajlib/src/test/java/com/yahoo/binaryprefix/BinaryScaledAmountTestCase.java b/vespajlib/src/test/java/com/yahoo/binaryprefix/BinaryScaledAmountTestCase.java
index bd5d176095e..4bfb0441668 100644
--- a/vespajlib/src/test/java/com/yahoo/binaryprefix/BinaryScaledAmountTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/binaryprefix/BinaryScaledAmountTestCase.java
@@ -1,12 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.binaryprefix;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author tonytv
*/
-public class BinaryScaledAmountTestCase extends TestCase {
+public class BinaryScaledAmountTestCase {
+
+ @Test
public void testConversion() {
BinaryScaledAmount oneMeg = new BinaryScaledAmount(1024, BinaryPrefix.kilo);
@@ -21,6 +25,7 @@ public class BinaryScaledAmountTestCase extends TestCase {
assertEquals(true, oneMeg.equals(v));
}
+ @Test
public void testSymbols() {
BinaryScaledAmount oneMeg = new BinaryScaledAmount(1024, BinaryPrefix.kilo);
@@ -35,4 +40,5 @@ public class BinaryScaledAmountTestCase extends TestCase {
}
assertEquals(true, ex);
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java
index e1c7a01164e..f1835119d7e 100644
--- a/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java
@@ -1,21 +1,18 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;
+import org.junit.Test;
-import com.yahoo.collections.BobHash;
-
+import static org.junit.Assert.assertEquals;
/**
* Basic consistency check of BobHash implementation
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-public class BobHashTestCase extends junit.framework.TestCase {
-
- public BobHashTestCase(String name) {
- super(name);
- }
+public class BobHashTestCase {
+ @Test
public void testit() {
// Teststring: minprice
// Basic ASCII string
@@ -42,4 +39,5 @@ public class BobHashTestCase extends junit.framework.TestCase {
assertEquals(BobHash.hash(lastnamefirstinitial, 0), 0xF36B4BD3);
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java b/vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java
index 86166a1e874..3be483106f2 100644
--- a/vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java
@@ -1,10 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
- * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
+ * @author Einar M R Rosenvinge
*/
-public class MD5TestCase extends junit.framework.TestCase {
+public class MD5TestCase {
+
+ @Test
public void testMD5() {
MD5 md5 = new MD5();
int a = md5.hash("foobar");
@@ -30,4 +37,5 @@ public class MD5TestCase extends junit.framework.TestCase {
assertTrue((c & 0x0000FF00) != 0);
assertTrue((c & 0x000000FF) != 0);
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/concurrent/EventBarrierTestCase.java b/vespajlib/src/test/java/com/yahoo/concurrent/EventBarrierTestCase.java
index 6a91c502571..7946e8ebc56 100644
--- a/vespajlib/src/test/java/com/yahoo/concurrent/EventBarrierTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/concurrent/EventBarrierTestCase.java
@@ -1,13 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.concurrent;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @author Simon Thoresen
*/
-public class EventBarrierTestCase extends TestCase {
+public class EventBarrierTestCase {
+ @Test
public void testEmpty() {
// waiting for an empty set of events
Barrier b = new Barrier();
@@ -27,6 +31,7 @@ public class EventBarrierTestCase extends TestCase {
assertEquals(eb.getNumBarriers(), 0);
}
+ @Test
public void testSimple() {
// a single barrier waiting for a single event
Barrier b = new Barrier();
@@ -49,6 +54,7 @@ public class EventBarrierTestCase extends TestCase {
assertEquals(eb.getNumBarriers(), 0);
}
+ @Test
public void testBarrierChain() {
// more than one barrier waiting for the same set of events
Barrier b1 = new Barrier();
@@ -80,6 +86,7 @@ public class EventBarrierTestCase extends TestCase {
assertEquals(eb.getNumBarriers(), 0);
}
+ @Test
public void testEventAfter() {
// new events starting after the start of a barrier
Barrier b = new Barrier();
@@ -111,6 +118,7 @@ public class EventBarrierTestCase extends TestCase {
assertEquals(eb.getNumBarriers(), 0);
}
+ @Test
public void testReorder() {
// events completing in a different order than they started
Barrier b1 = new Barrier();
@@ -165,4 +173,5 @@ public class EventBarrierTestCase extends TestCase {
done = true;
}
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/geo/BoundingBoxParserTestCase.java b/vespajlib/src/test/java/com/yahoo/geo/BoundingBoxParserTestCase.java
index 54b0bc49294..9602bdb8d94 100644
--- a/vespajlib/src/test/java/com/yahoo/geo/BoundingBoxParserTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/geo/BoundingBoxParserTestCase.java
@@ -1,36 +1,39 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.geo;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
/**
* Tests for the BoundingBoxParser class.
*
* @author arnej27959
*/
-public class BoundingBoxParserTestCase extends junit.framework.TestCase {
+public class BoundingBoxParserTestCase {
- private BoundingBoxParser parser;
+ private static final double delta = 0.000000000001;
- public BoundingBoxParserTestCase(String name) {
- super(name);
- }
+ private BoundingBoxParser parser;
private void allZero(BoundingBoxParser data) {
- assertEquals(0d, data.n);
- assertEquals(0d, data.s);
- assertEquals(0d, data.e);
- assertEquals(0d, data.w);
+ assertEquals(0d, data.n, delta);
+ assertEquals(0d, data.s, delta);
+ assertEquals(0d, data.e, delta);
+ assertEquals(0d, data.w, delta);
}
private void all1234(BoundingBoxParser data) {
- assertEquals(1d, data.n);
- assertEquals(2d, data.s);
- assertEquals(3d, data.e);
- assertEquals(4d, data.w);
+ assertEquals(1d, data.n, delta);
+ assertEquals(2d, data.s, delta);
+ assertEquals(3d, data.e, delta);
+ assertEquals(4d, data.w, delta);
}
/**
* Tests different inputs that should all produce 0
*/
+ @Test
public void testZero() {
parser = new BoundingBoxParser("n=0,s=0,e=0,w=0");
allZero(parser);
@@ -48,6 +51,7 @@ public class BoundingBoxParserTestCase extends junit.framework.TestCase {
allZero(parser);
}
+ @Test
public void testOneTwoThreeFour() {
parser = new BoundingBoxParser("n=1,s=2,e=3,w=4");
all1234(parser);
@@ -68,12 +72,14 @@ public class BoundingBoxParserTestCase extends junit.framework.TestCase {
/**
* Tests various legal inputs and print the output
*/
+ @Test
public void testPrint() {
String here = "n=63.418417 E=10.433033 S=37.7 W=-122.02";
parser = new BoundingBoxParser(here);
System.out.println(here+" -> "+parser);
}
+ @Test
public void testGeoPlanetExample() {
/* example XML:
<boundingBox>
@@ -98,6 +104,7 @@ public class BoundingBoxParserTestCase extends junit.framework.TestCase {
assertEquals(-74.728798d, parser.e, 0.0000001);
}
+ @Test
public void testGwsExample() {
/* example XML:
<boundingbox>
@@ -115,6 +122,7 @@ public class BoundingBoxParserTestCase extends junit.framework.TestCase {
/**
* Tests various inputs that contain syntax errors.
*/
+ @Test
public void testInputErrors() {
String message = "";
try {
@@ -159,4 +167,5 @@ public class BoundingBoxParserTestCase extends junit.framework.TestCase {
}
assertEquals("multiple limits for 'w' boundary", message);
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/geo/DegreesParserTestCase.java b/vespajlib/src/test/java/com/yahoo/geo/DegreesParserTestCase.java
index 79ce71071d5..2f12305cbb8 100644
--- a/vespajlib/src/test/java/com/yahoo/geo/DegreesParserTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/geo/DegreesParserTestCase.java
@@ -1,154 +1,127 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.geo;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
/**
* Tests for the DegreesParser class.
*
- * @author <a href="mailto:gunnarga@yahoo-inc.com">Gunnar Gauslaa Bergem</a>
+ * @author Gunnar Gauslaa Bergem
*/
-public class DegreesParserTestCase extends junit.framework.TestCase {
+public class DegreesParserTestCase {
- private DegreesParser parser;
+ private static final double delta = 0.000000000001;
- public DegreesParserTestCase(String name) {
- super(name);
- }
+ private DegreesParser parser;
/**
* Tests different inputs that should all produce 0 or -0.
*/
+ @Test
public void testZero() {
parser = new DegreesParser("N0;E0");
- assertEquals(0d, parser.latitude);
- assertEquals(0d, parser.longitude);
+ assertEquals(0d, parser.latitude, delta);
+ assertEquals(0d, parser.longitude, delta);
parser = new DegreesParser("S0;W0");
- assertEquals(-0d, parser.latitude);
- assertEquals(-0d, parser.longitude);
+ assertEquals(-0d, parser.latitude, delta);
+ assertEquals(-0d, parser.longitude, delta);
parser = new DegreesParser("N0.0;E0.0");
- assertEquals(0d, parser.latitude);
- assertEquals(0d, parser.longitude);
+ assertEquals(0d, parser.latitude, delta);
+ assertEquals(0d, parser.longitude, delta);
parser = new DegreesParser("S0.0;W0.0");
- assertEquals(-0d, parser.latitude);
- assertEquals(-0d, parser.longitude);
+ assertEquals(-0d, parser.latitude, delta);
+ assertEquals(-0d, parser.longitude, delta);
parser = new DegreesParser("N0\u00B00'0;E0\u00B00'0");
- assertEquals(0d, parser.latitude);
- assertEquals(0d, parser.longitude);
+ assertEquals(0d, parser.latitude, delta);
+ assertEquals(0d, parser.longitude, delta);
parser = new DegreesParser("S0\u00B00'0;W0\u00B00'0");
- assertEquals(-0d, parser.latitude);
- assertEquals(-0d, parser.longitude);
+ assertEquals(-0d, parser.latitude, delta);
+ assertEquals(-0d, parser.longitude, delta);
parser = new DegreesParser("S0o0'0;W0o0'0");
- assertEquals(-0d, parser.latitude);
- assertEquals(-0d, parser.longitude);
- }
-
- /**
- * Tests various legal inputs and print the output
- */
- public void testPrint() {
- String here = "63N025.105;010E25.982";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "N63.418417 E10.433033";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "N63o025.105;E010o25.982";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "N63.418417;E10.433033";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "63.418417N;10.433033E";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "N37.417075;W122.025358";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
-
- here = "N37\u00B024.983;W122\u00B001.481";
- parser = new DegreesParser(here);
- System.out.println(here+" -> "+parser.latitude+"/"+parser.longitude+" (lat/long)");
+ assertEquals(-0d, parser.latitude, delta);
+ assertEquals(-0d, parser.longitude, delta);
}
/**
* Tests inputs that are close to 0.
*/
+ @Test
public void testNearZero() {
parser = new DegreesParser("N0.0001;E0.0001");
- assertEquals(0.0001, parser.latitude);
- assertEquals(0.0001, parser.longitude);
+ assertEquals(0.0001, parser.latitude, delta);
+ assertEquals(0.0001, parser.longitude, delta);
parser = new DegreesParser("S0.0001;W0.0001");
- assertEquals(-0.0001, parser.latitude);
- assertEquals(-0.0001, parser.longitude);
+ assertEquals(-0.0001, parser.latitude, delta);
+ assertEquals(-0.0001, parser.longitude, delta);
parser = new DegreesParser("N0.000001;E0.000001");
- assertEquals(0.000001, parser.latitude);
- assertEquals(0.000001, parser.longitude);
+ assertEquals(0.000001, parser.latitude, delta);
+ assertEquals(0.000001, parser.longitude, delta);
parser = new DegreesParser("S0.000001;W0.000001");
- assertEquals(-0.000001, parser.latitude);
- assertEquals(-0.000001, parser.longitude);
+ assertEquals(-0.000001, parser.latitude, delta);
+ assertEquals(-0.000001, parser.longitude, delta);
parser = new DegreesParser("N0\u00B00'1;E0\u00B00'1");
- assertEquals(1/3600d, parser.latitude);
- assertEquals(1/3600d, parser.longitude);
+ assertEquals(1/3600d, parser.latitude, delta);
+ assertEquals(1/3600d, parser.longitude, delta);
parser = new DegreesParser("S0\u00B00'1;W0\u00B00'1");
- assertEquals(-1/3600d, parser.latitude);
- assertEquals(-1/3600d, parser.longitude);
+ assertEquals(-1/3600d, parser.latitude, delta);
+ assertEquals(-1/3600d, parser.longitude, delta);
}
/**
* Tests inputs that are close to latitude 90/-90 degrees and longitude 180/-180 degrees.
*/
+ @Test
public void testNearBoundary() {
-
parser = new DegreesParser("N89.9999;E179.9999");
- assertEquals(89.9999, parser.latitude);
- assertEquals(179.9999, parser.longitude);
+ assertEquals(89.9999, parser.latitude, delta);
+ assertEquals(179.9999, parser.longitude, delta);
parser = new DegreesParser("S89.9999;W179.9999");
- assertEquals(-89.9999, parser.latitude);
- assertEquals(-179.9999, parser.longitude);
+ assertEquals(-89.9999, parser.latitude, delta);
+ assertEquals(-179.9999, parser.longitude, delta);
parser = new DegreesParser("N89.999999;E179.999999");
- assertEquals(89.999999, parser.latitude);
- assertEquals(179.999999, parser.longitude);
+ assertEquals(89.999999, parser.latitude, delta);
+ assertEquals(179.999999, parser.longitude, delta);
parser = new DegreesParser("S89.999999;W179.999999");
- assertEquals(-89.999999, parser.latitude);
- assertEquals(-179.999999, parser.longitude);
+ assertEquals(-89.999999, parser.latitude, delta);
+ assertEquals(-179.999999, parser.longitude, delta);
parser = new DegreesParser("N89\u00B059'59;E179\u00B059'59");
- assertEquals(89+59/60d+59/3600d, parser.latitude);
- assertEquals(179+59/60d+59/3600d, parser.longitude);
+ assertEquals(89+59/60d+59/3600d, parser.latitude, delta);
+ assertEquals(179+59/60d+59/3600d, parser.longitude, delta);
parser = new DegreesParser("S89\u00B059'59;W179\u00B059'59");
- assertEquals(-(89+59/60d+59/3600d), parser.latitude);
- assertEquals(-(179+59/60d+59/3600d), parser.longitude);
+ assertEquals(-(89+59/60d+59/3600d), parser.latitude, delta);
+ assertEquals(-(179+59/60d+59/3600d), parser.longitude, delta);
}
/**
* Tests inputs that are on latitude 90/-90 degrees and longitude 180/-180 degrees.
*/
+ @Test
public void testOnBoundary() {
parser = new DegreesParser("N90;E180");
- assertEquals(90d, parser.latitude);
- assertEquals(180d, parser.longitude);
+ assertEquals(90d, parser.latitude, delta);
+ assertEquals(180d, parser.longitude, delta);
parser = new DegreesParser("S90;W180");
- assertEquals(-90d, parser.latitude);
- assertEquals(-180d, parser.longitude);
+ assertEquals(-90d, parser.latitude, delta);
+ assertEquals(-180d, parser.longitude, delta);
parser = new DegreesParser("N90\u00B00'0;E180\u00B00'0");
- assertEquals(90d, parser.latitude);
- assertEquals(180d, parser.longitude);
+ assertEquals(90d, parser.latitude, delta);
+ assertEquals(180d, parser.longitude, delta);
parser = new DegreesParser("S90\u00B00'0;W180\u00B00'0");
- assertEquals(-90d, parser.latitude);
- assertEquals(-180d, parser.longitude);
+ assertEquals(-90d, parser.latitude, delta);
+ assertEquals(-180d, parser.longitude, delta);
}
/**
* Tests inputs that are above latitude 90/-90 degrees and longitude 180/-180 degrees.
- */
+ */
+ @Test
public void testAboveBoundary() {
String message = "";
try {
@@ -204,6 +177,7 @@ public class DegreesParserTestCase extends junit.framework.TestCase {
/**
* Tests various inputs that contain syntax errors.
*/
+ @Test
public void testInputErrors() {
String message = "";
try {
@@ -279,4 +253,5 @@ public class DegreesParserTestCase extends junit.framework.TestCase {
}
assertEquals("invalid character: O", message);
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/geo/ZCurveTestCase.java b/vespajlib/src/test/java/com/yahoo/geo/ZCurveTestCase.java
index 2abbfa2f68a..b1a6149f956 100644
--- a/vespajlib/src/test/java/com/yahoo/geo/ZCurveTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/geo/ZCurveTestCase.java
@@ -1,21 +1,22 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.geo;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
/**
* Tests for the ZCurve class.
*
* @author gjoranv
*/
-public class ZCurveTestCase extends junit.framework.TestCase {
-
- public ZCurveTestCase(String name) {
- super(name);
- }
+public class ZCurveTestCase {
/**
- * Verify that encoded values return the expected bit pattern
- */
- public void testEncoding() {
+ * Verify that encoded values return the expected bit pattern
+ */
+ @Test
+ public void testEncoding() {
int x = 0;
int y = 0;
long z = ZCurve.encode(x, y);
@@ -45,11 +46,12 @@ public class ZCurveTestCase extends junit.framework.TestCase {
y = Integer.MIN_VALUE / 2;
z = ZCurve.encode(x, y);
assertEquals(0xa555555555555555L, z);
- }
+ }
/**
* Verify that decoded values are equal to inputs in different cases
*/
+ @Test
public void testDecoding() {
int x = 0;
int y = 0;
@@ -94,11 +96,10 @@ public class ZCurveTestCase extends junit.framework.TestCase {
assertEquals(y, xy[1]);
}
-
-
/**
* Verify that encoded values return the expected bit pattern
*/
+ @Test
public void testEncoding_slow() {
int x = 0;
int y = 0;
@@ -134,6 +135,7 @@ public class ZCurveTestCase extends junit.framework.TestCase {
/**
* Verify that decoded values are equal to inputs in different cases
*/
+ @Test
public void testDecoding_slow() {
int x = 0;
int y = 0;
@@ -178,6 +180,7 @@ public class ZCurveTestCase extends junit.framework.TestCase {
assertEquals(xy[1], y);
}
+ @Test
public void testBenchmarkEncoding() {
int limit = 2000000;
@@ -187,8 +190,8 @@ public class ZCurveTestCase extends junit.framework.TestCase {
z1 += ZCurve.encode(i,-i);
}
long elapsed = System.currentTimeMillis() - start;
- System.out.println("Fast method: elapsed time: " + elapsed + " ms");
- System.out.println("Per encoding: " + elapsed/(1.0*limit) * 1000000 + " ns");
+ //System.out.println("Fast method: elapsed time: " + elapsed + " ms");
+ //System.out.println("Per encoding: " + elapsed/(1.0*limit) * 1000000 + " ns");
long z2 = 0L;
start = System.currentTimeMillis();
@@ -196,8 +199,8 @@ public class ZCurveTestCase extends junit.framework.TestCase {
z2 += ZCurve.encode_slow(i,-i);
}
elapsed = System.currentTimeMillis() - start;
- System.out.println("Slow method: elapsed time: " + elapsed + " ms");
- System.out.println("Per encoding: " + elapsed/(1.0*limit) * 1000000 + " ns");
+ //System.out.println("Slow method: elapsed time: " + elapsed + " ms");
+ //System.out.println("Per encoding: " + elapsed/(1.0*limit) * 1000000 + " ns");
assertEquals(z1, z2);
}
diff --git a/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java b/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java
index 5b03c63de54..c9018224b1c 100644
--- a/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java
@@ -1,16 +1,23 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.io;
+import org.junit.Test;
+
import java.nio.ByteBuffer;
-public class BlobTestCase extends junit.framework.TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BlobTestCase {
+ @Test
public void testEmpty() {
Blob empty = new Blob();
assertTrue(empty.get() != null);
assertEquals(0, empty.get().length);
}
+ @Test
public void testCopyArray() {
byte[] d = { 1, 2, 3 };
Blob b = new Blob(d);
@@ -23,6 +30,7 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(3, b.get()[2]);
}
+ @Test
public void testCopyArraySubset() {
byte[] d = { 1, 2, 3 };
Blob b = new Blob(d, 1, 1);
@@ -33,6 +41,7 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(2, b.get()[0]);
}
+ @Test
public void testCopyBlob() {
byte[] d = { 1, 2, 3 };
Blob b = new Blob(d);
@@ -45,6 +54,7 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(3, x.get()[2]);
}
+ @Test
public void testReadBuffer() {
ByteBuffer buf = ByteBuffer.allocate(100);
buf.put((byte)1);
@@ -60,6 +70,7 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(3, b.get()[2]);
}
+ @Test
public void testReadPartialBuffer() {
ByteBuffer buf = ByteBuffer.allocate(100);
buf.put((byte)1);
@@ -80,6 +91,7 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(0, buf.remaining());
}
+ @Test
public void testWriteBuffer() {
byte[] d = { 1, 2, 3 };
Blob b = new Blob(d);
@@ -92,4 +104,5 @@ public class BlobTestCase extends junit.framework.TestCase {
assertEquals(3, buf.get());
assertEquals(0, buf.remaining());
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java b/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java
index b34a0e4a2f9..c6278133d4c 100644
--- a/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java
@@ -2,6 +2,9 @@
package com.yahoo.io;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -14,25 +17,18 @@ import java.util.IdentityHashMap;
import com.yahoo.text.Utf8;
import com.yahoo.text.Utf8Array;
+import org.junit.Test;
/**
* Test the ByteWriter class. ByteWriter is also implicitly tested in
* com.yahoo.prelude.templates.test.TemplateTestCase.
*
- * @author <a href="mailt:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-public class ByteWriterTestCase extends junit.framework.TestCase {
- private CharsetEncoder encoder;
- private ByteArrayOutputStream stream;
+public class ByteWriterTestCase {
- // TODO split BufferChain tests from ByteWriter tests
- public ByteWriterTestCase (String name) {
- super(name);
- Charset cs = Charset.forName("UTF-8");
- encoder = cs.newEncoder();
- stream = new ByteArrayOutputStream();
-
- }
+ private final CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
+ private final ByteArrayOutputStream stream = new ByteArrayOutputStream();
/**
* A stream which does nothing, but complains if it is called and asked to
@@ -43,18 +39,17 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
static final String ZERO_LENGTH_WRITE = "Was asked to do zero length write.";
@Override
- public void write(int b) throws IOException {
+ public void write(int b) {
// NOP
-
}
@Override
- public void close() throws IOException {
+ public void close() {
// NOP
}
@Override
- public void flush() throws IOException {
+ public void flush() {
// NOP
}
@@ -74,6 +69,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
}
+ @Test
public void testMuchData() throws java.io.IOException {
final int SINGLE_BUFFER = 500;
final int APPENDS = 500;
@@ -96,6 +92,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue("ByteWriter seems to have introduced data errors.", Arrays.equals(completeData, res));
}
+ @Test
public void testLongString() throws IOException {
final int length = BufferChain.BUFFERSIZE * BufferChain.MAXBUFFERS * 3;
StringBuilder b = new StringBuilder(length);
@@ -112,6 +109,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertEquals(s, res);
}
+ @Test
public void testNoSpuriousWrite() throws IOException {
OutputStream grumpy = new CurmudgeonlyStream();
ByteWriter bw = new ByteWriter(grumpy, encoder);
@@ -145,6 +143,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testDoubleFlush() throws IOException {
stream.reset();
byte[] c = new byte[] { 97, 98, 99 };
@@ -157,6 +156,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99 }, res));
}
+ @Test
public void testCharArrays() throws java.io.IOException {
stream.reset();
char[] c = new char[] { 'a', 'b', 'c', '\u00F8' };
@@ -167,6 +167,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99, (byte) 0xc3, (byte) 0xb8 }, res));
}
+ @Test
public void testByteBuffers() throws java.io.IOException {
stream.reset();
ByteBuffer b = ByteBuffer.allocate(16);
@@ -181,6 +182,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99 }, res));
}
+ @Test
public void testByteArrays() throws java.io.IOException {
stream.reset();
byte[] c = new byte[] { 97, 98, 99 };
@@ -191,6 +193,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99 }, res));
}
+ @Test
public void testByteArrayWithOffset() throws java.io.IOException {
final int length = BufferChain.BUFFERSIZE * 3 / 2;
final int offset = 1;
@@ -210,6 +213,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertEquals(valid, res[0]);
}
+ @Test
public void testStrings() throws java.io.IOException {
stream.reset();
String c = "abc\u00F8";
@@ -220,6 +224,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99, (byte) 0xc3, (byte) 0xb8 }, res));
}
+ @Test
public void testStringsAndByteArrays() throws java.io.IOException {
stream.reset();
String c = "abc\u00F8";
@@ -232,6 +237,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99, (byte) 0xc3, (byte) 0xb8, 97, 98, 99 }, res));
}
+ @Test
public void testByteBuffersAndByteArrays() throws java.io.IOException {
stream.reset();
ByteBuffer b = ByteBuffer.allocate(16);
@@ -248,6 +254,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(Arrays.equals(new byte[] { 97, 98, 99, 100, 101, 102 }, res));
}
+ @Test
public void testOverFlow() throws java.io.IOException {
stream.reset();
byte[] b = new byte[] { 97, 98, 99 };
@@ -271,6 +278,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testUnMappableCharacter() throws java.io.IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ByteWriter writer = new ByteWriter(stream, Charset.forName("ascii").newEncoder());
@@ -280,6 +288,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertTrue(stream.toString("ascii").contains("bahoo"));
}
+ @Test
public void testNoRecycling() throws IOException {
final int SINGLE_BUFFER = 500;
final int APPENDS = 500;
@@ -307,6 +316,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testGetEncoding() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -314,6 +324,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
b.close();
}
+ @Test
public void testWriteLong() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -322,6 +333,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("1000000000000"), stream.toByteArray());
}
+ @Test
public void testWriteInt() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -330,6 +342,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("z"), stream.toByteArray());
}
+ @Test
public void testSurrogatePairs() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -339,6 +352,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("\uD800\uDFD0"), stream.toByteArray());
}
+ @Test
public void testSurrogatePairsMixedWithSingleCharacters() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -354,7 +368,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("\u00F8\uD800\uDFD0\u00F8ab"), stream.toByteArray());
}
-
+ @Test
public void testWriteDouble() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -363,6 +377,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("12.0"), stream.toByteArray());
}
+ @Test
public void testWriteFloat() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -371,6 +386,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("12.0"), stream.toByteArray());
}
+ @Test
public void testWriteShort() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -379,6 +395,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("12"), stream.toByteArray());
}
+ @Test
public void testWriteBoolean() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -387,6 +404,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(Utf8.toBytes("true"), stream.toByteArray());
}
+ @Test
public void testAppendSingleByte() throws java.io.IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -395,6 +413,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertArrayEquals(new byte[] { (byte) 'a' }, stream.toByteArray());
}
+ @Test
public void testAppended() throws IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -406,6 +425,7 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
assertEquals(bytes.length, b.appended());
}
+ @Test
public void testWriteUtf8Array() throws IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
@@ -441,4 +461,5 @@ public class ByteWriterTestCase extends junit.framework.TestCase {
datastore.flush();
}
}
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java b/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java
index f03944ff6f8..1acd225b18a 100644
--- a/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java
@@ -8,8 +8,10 @@ import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-public class FileReadTestCase extends junit.framework.TestCase {
+public class FileReadTestCase {
@Test
public void testReadByteArray() throws IOException {
diff --git a/vespajlib/src/test/java/com/yahoo/io/GrowableBufferOutputStreamTestCase.java b/vespajlib/src/test/java/com/yahoo/io/GrowableBufferOutputStreamTestCase.java
index 70e21cef62a..001023f62a4 100644
--- a/vespajlib/src/test/java/com/yahoo/io/GrowableBufferOutputStreamTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/io/GrowableBufferOutputStreamTestCase.java
@@ -5,14 +5,20 @@ import java.nio.channels.WritableByteChannel;
import java.nio.ByteBuffer;
import java.io.IOException;
import com.yahoo.io.GrowableBufferOutputStream;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Tests the GrowableBufferOutputStream
*
- * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a>
+ * @author Bjorn Borud
*/
-public class GrowableBufferOutputStreamTestCase extends junit.framework.TestCase {
+public class GrowableBufferOutputStreamTestCase {
+
private byte[] testData;
static class DummyWritableByteChannel implements WritableByteChannel {
@@ -22,7 +28,7 @@ public class GrowableBufferOutputStreamTestCase extends junit.framework.TestCase
this.buffer = buffer;
}
- public int write(ByteBuffer src) throws IOException {
+ public int write(ByteBuffer src) {
int written = Math.min(src.remaining(), buffer.remaining());
if (buffer.remaining() < src.remaining()) {
@@ -40,13 +46,10 @@ public class GrowableBufferOutputStreamTestCase extends junit.framework.TestCase
return true;
}
- public void close() throws IOException {}
- }
-
- public GrowableBufferOutputStreamTestCase(String name) {
- super(name);
+ public void close() {}
}
+ @Before
public void setUp() {
testData = new byte[100];
for (int i = 0; i < 100; ++i) {
@@ -54,6 +57,7 @@ public class GrowableBufferOutputStreamTestCase extends junit.framework.TestCase
}
}
+ @Test
public void testSimple() throws IOException {
GrowableBufferOutputStream g = new GrowableBufferOutputStream(10, 5);
@@ -123,4 +127,5 @@ public class GrowableBufferOutputStreamTestCase extends junit.framework.TestCase
g.clearAll();
assertEquals(0, g.numWritableBuffers());
}
+
}
diff --git a/vespalog/src/test/java/com/yahoo/log/event/EventTestCase.java b/vespalog/src/test/java/com/yahoo/log/event/EventTestCase.java
index 2da6771de73..c644f8296fe 100644
--- a/vespalog/src/test/java/com/yahoo/log/event/EventTestCase.java
+++ b/vespalog/src/test/java/com/yahoo/log/event/EventTestCase.java
@@ -4,22 +4,17 @@ package com.yahoo.log.event;
import java.util.logging.Logger;
import com.yahoo.log.VespaFormatter;
-import com.yahoo.log.event.Collection;
-import com.yahoo.log.event.Count;
-import com.yahoo.log.event.Crash;
-import com.yahoo.log.event.Event;
-import com.yahoo.log.event.MalformedEventException;
-import com.yahoo.log.event.Progress;
-import com.yahoo.log.event.Reloaded;
-import com.yahoo.log.event.Reloading;
-import com.yahoo.log.event.Started;
-import com.yahoo.log.event.Starting;
-import com.yahoo.log.event.Stopped;
-import com.yahoo.log.event.Stopping;
-import com.yahoo.log.event.Unknown;
-import com.yahoo.log.event.Value;
-
-public class EventTestCase extends junit.framework.TestCase {
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class EventTestCase {
+
Count countEvent;
Count floatCountEvent;
Value valueEvent;
@@ -36,10 +31,7 @@ public class EventTestCase extends junit.framework.TestCase {
Collection collectionEvent;
Unknown unknownEvent;
- public EventTestCase (String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
countEvent = new Count("thecounter", 1234);
floatCountEvent= new Count("thecounter", 1234.23);
@@ -59,6 +51,7 @@ public class EventTestCase extends junit.framework.TestCase {
}
// make sure we can make the test instances okay
+ @Test
public void testExists () {
assertNotNull(countEvent);
assertNotNull(floatCountEvent);
@@ -77,6 +70,7 @@ public class EventTestCase extends junit.framework.TestCase {
assertNotNull(unknownEvent);
}
+ @Test
public void testEvents () {
assertEquals("count/1 name=thecounter value=1234",
countEvent.toString());
@@ -118,10 +112,11 @@ public class EventTestCase extends junit.framework.TestCase {
/**
* do the dirty work for testParser
*/
- private void parseEvent (Event e) throws MalformedEventException {
+ private void parseEvent(Event e) throws MalformedEventException {
assertEquals(e.toString(), Event.parse(e.toString()).toString());
}
+ @Test
public void testParser () throws MalformedEventException {
parseEvent(countEvent);
parseEvent(floatCountEvent);
@@ -136,6 +131,7 @@ public class EventTestCase extends junit.framework.TestCase {
parseEvent(stoppedEvent);
}
+ @Test
public void testUnknownEvents () throws MalformedEventException {
String s = "crappyevent/2 first=\"value one\" second=more third=4";
Event event = Event.parse(s);
@@ -150,6 +146,7 @@ public class EventTestCase extends junit.framework.TestCase {
* successfully manage to find the right name on the calling
* stack -- it should find the name of the calling class.
*/
+ @Test
public void testFindingCallingClassLogger() {
SingleHandler sh = new SingleHandler();
assertNull(sh.lastRecord());
@@ -176,6 +173,7 @@ public class EventTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testFunnyEvent () {
String funnyEvent = "collection/1 collectionId=1111111111 name=\"syncrows\" params=\"column=0 badrow=1 goodrow=0\"";
try {
@@ -186,14 +184,16 @@ public class EventTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testFullParse () {
try {
- Event event = Event.parse("count/1 name=\"data_searched_mb\" value=15115168.3940149993");
- assertTrue(event instanceof Count);
- assertEquals("data_searched_mb", event.getValue("name"));
- assertEquals("15115168", event.getValue("value"));
+ Event event = Event.parse("count/1 name=\"data_searched_mb\" value=15115168.3940149993");
+ assertTrue(event instanceof Count);
+ assertEquals("data_searched_mb", event.getValue("name"));
+ assertEquals("15115168", event.getValue("value"));
} catch (MalformedEventException e) {
fail("Malformed Event Exception on parsing");
}
}
+
}
diff --git a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
index 925371a5f91..db605609926 100644
--- a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
+++ b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
@@ -1,15 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.yolean;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
/**
* @author bratseth
*/
-public class ExceptionsTestCase extends junit.framework.TestCase {
-
- public ExceptionsTestCase(String name) {
- super(name);
- }
+public class ExceptionsTestCase {
+ @Test
public void testToMessageStrings() {
assertEquals("Blah",Exceptions.toMessageString(new Exception("Blah")));
assertEquals("Blah", Exceptions.toMessageString(new Exception(new Exception("Blah"))));
diff --git a/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java b/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java
index 64d1546a61e..056db2d3592 100644
--- a/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java
+++ b/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java
@@ -1,19 +1,18 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.yolean.system;
-import com.yahoo.yolean.system.CatchSigTerm;
+import org.junit.Test;
+
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author arnej27959
*/
-public class CatchSigTermTestCase extends junit.framework.TestCase {
-
- public CatchSigTermTestCase(String name) {
- super(name);
- }
+public class CatchSigTermTestCase {
+ @Test
public void testThatSetupCompiles() {
CatchSigTerm.setup(new AtomicBoolean(false));
}
+
}