diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-27 13:35:40 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-27 13:35:40 +0200 |
commit | d12f069567a99536c84598700ad4f00048936cde (patch) | |
tree | 61f04cddb5fe535694835497620cfdeb26a82dbf /jrt | |
parent | d83814043998817d404b922e3050ce2006e8ec19 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'jrt')
23 files changed, 259 insertions, 126 deletions
diff --git a/jrt/tests/com/yahoo/jrt/AbortTest.java b/jrt/tests/com/yahoo/jrt/AbortTest.java index 785bc0ed561..e3a1685c9e2 100644 --- a/jrt/tests/com/yahoo/jrt/AbortTest.java +++ b/jrt/tests/com/yahoo/jrt/AbortTest.java @@ -1,8 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; +import org.junit.After; +import org.junit.Before; -public class AbortTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class AbortTest { Supervisor server; Acceptor acceptor; @@ -10,10 +15,7 @@ public class AbortTest extends junit.framework.TestCase { Target target; Test.Barrier barrier; - public AbortTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -23,6 +25,7 @@ public class AbortTest extends junit.framework.TestCase { barrier = new Test.Barrier(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -36,6 +39,7 @@ public class AbortTest extends junit.framework.TestCase { req.returnValues().add(new Int32Value(value)); } + @org.junit.Test public void testAbort() { Test.Waiter w = new Test.Waiter(); Request req = new Request("test"); @@ -65,6 +69,7 @@ public class AbortTest extends junit.framework.TestCase { assertEquals(0, req.returnValues().size()); } + @org.junit.Test public void testBogusAbort() { Request req = new Request("test"); req.parameters().add(new Int32Value(40)); @@ -73,4 +78,5 @@ public class AbortTest extends junit.framework.TestCase { assertTrue(false); } catch (IllegalStateException e) {} } + } diff --git a/jrt/tests/com/yahoo/jrt/BackTargetTest.java b/jrt/tests/com/yahoo/jrt/BackTargetTest.java index a130bcc5630..3524d47dc1f 100644 --- a/jrt/tests/com/yahoo/jrt/BackTargetTest.java +++ b/jrt/tests/com/yahoo/jrt/BackTargetTest.java @@ -1,8 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; +import org.junit.After; +import org.junit.Before; -public class BackTargetTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class BackTargetTest { Supervisor server; Acceptor acceptor; @@ -13,10 +18,7 @@ public class BackTargetTest extends junit.framework.TestCase { Target serverBackTarget; Target clientBackTarget; - public BackTargetTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -39,6 +41,7 @@ public class BackTargetTest extends junit.framework.TestCase { clientBackTarget = null; } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -77,6 +80,7 @@ public class BackTargetTest extends junit.framework.TestCase { assertTrue(client == (clientBackTarget != null)); } + @org.junit.Test public void testBackTarget() { checkTargets(false, false); target.invokeSync(new Request("sample_target"), 5.0); @@ -100,6 +104,7 @@ public class BackTargetTest extends junit.framework.TestCase { checkValues(3, 3); } + @org.junit.Test public void testBogusBackTarget() { Request req = new Request("inc"); try { @@ -107,4 +112,5 @@ public class BackTargetTest extends junit.framework.TestCase { assertTrue(false); } catch (IllegalStateException e) {} } + } diff --git a/jrt/tests/com/yahoo/jrt/BufferTest.java b/jrt/tests/com/yahoo/jrt/BufferTest.java index 08f86df6c7f..f837b036957 100644 --- a/jrt/tests/com/yahoo/jrt/BufferTest.java +++ b/jrt/tests/com/yahoo/jrt/BufferTest.java @@ -1,18 +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.jrt; - import java.nio.ByteBuffer; import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -public class BufferTest extends junit.framework.TestCase { - - public BufferTest(String name) { - super(name); - } - +public class BufferTest { + @org.junit.Test public void testBuffer() { int size = Buffer.MAX_IO + (Buffer.MAX_IO / 10); @@ -65,6 +63,7 @@ public class BufferTest extends junit.framework.TestCase { assertTrue(Arrays.equals(x, y)); } + @org.junit.Test public void testBufferCompact() { Buffer buf = new Buffer(10); buf.getWritable(3).put((byte)10).put((byte)20).put((byte)30); @@ -103,8 +102,8 @@ public class BufferTest extends junit.framework.TestCase { } } + @org.junit.Test public void testBufferMax() { - int size = Buffer.MAX_IO + (Buffer.MAX_IO / 10); Buffer buf = new Buffer(1024); ByteBuffer b = null; @@ -159,6 +158,7 @@ public class BufferTest extends junit.framework.TestCase { assertTrue(Arrays.equals(x, y)); } + @org.junit.Test public void testBufferShrink() { Buffer buf = new Buffer(500); ByteBuffer b = null; @@ -262,4 +262,5 @@ public class BufferTest extends junit.framework.TestCase { assertEquals(50, b.get()); } } + } diff --git a/jrt/tests/com/yahoo/jrt/ConnectTest.java b/jrt/tests/com/yahoo/jrt/ConnectTest.java index ba22fdf67cc..64ed3f5f954 100644 --- a/jrt/tests/com/yahoo/jrt/ConnectTest.java +++ b/jrt/tests/com/yahoo/jrt/ConnectTest.java @@ -1,13 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; +import static org.junit.Assert.assertTrue; -public class ConnectTest extends junit.framework.TestCase { - - public ConnectTest(String name) { - super(name); - } +public class ConnectTest { + @org.junit.Test public void testConnect() throws ListenFailedException { Test.Orb server = new Test.Orb(new Transport()); Test.Orb client = new Test.Orb(new Transport()); @@ -44,4 +42,5 @@ public class ConnectTest extends junit.framework.TestCase { client.transport().shutdown().join(); server.transport().shutdown().join(); } + } diff --git a/jrt/tests/com/yahoo/jrt/DetachTest.java b/jrt/tests/com/yahoo/jrt/DetachTest.java index 2d4f7084f48..1c1256f0689 100644 --- a/jrt/tests/com/yahoo/jrt/DetachTest.java +++ b/jrt/tests/com/yahoo/jrt/DetachTest.java @@ -1,8 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; +import org.junit.After; +import org.junit.Before; -public class DetachTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class DetachTest { Test.Orb server; Acceptor acceptor; @@ -11,10 +16,7 @@ public class DetachTest extends junit.framework.TestCase { Test.Receptor receptor; Test.Barrier barrier; - public DetachTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Test.Orb(new Transport()); client = new Test.Orb(new Transport()); @@ -31,6 +33,7 @@ public class DetachTest extends junit.framework.TestCase { barrier = new Test.Barrier(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -61,6 +64,7 @@ public class DetachTest extends junit.framework.TestCase { barrier.waitFor(); } + @org.junit.Test public void testDetach() { Test.Waiter w1 = new Test.Waiter(); Request req1 = new Request("d_inc"); @@ -103,6 +107,7 @@ public class DetachTest extends junit.framework.TestCase { assertTrue(client.readBytes == server.writeBytes); } + @org.junit.Test public void testBogusDetach() { Request req1 = new Request("inc_b"); req1.parameters().add(new Int32Value(200)); @@ -133,4 +138,5 @@ public class DetachTest extends junit.framework.TestCase { assertEquals(1, req3.returnValues().size()); assertEquals(101, req3.returnValues().get(0).asInt32()); } + } diff --git a/jrt/tests/com/yahoo/jrt/EchoTest.java b/jrt/tests/com/yahoo/jrt/EchoTest.java index 3dab2443b53..240feda8423 100644 --- a/jrt/tests/com/yahoo/jrt/EchoTest.java +++ b/jrt/tests/com/yahoo/jrt/EchoTest.java @@ -2,7 +2,12 @@ package com.yahoo.jrt; -public class EchoTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertTrue; + +public class EchoTest { Supervisor server; Acceptor acceptor; @@ -10,10 +15,7 @@ public class EchoTest extends junit.framework.TestCase { Target target; Values refValues; - public EchoTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -51,6 +53,7 @@ public class EchoTest extends junit.framework.TestCase { refValues.add(new StringArray(stringArray)); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -71,6 +74,7 @@ public class EchoTest extends junit.framework.TestCase { } } + @org.junit.Test public void testEcho() { Request req = new Request("echo"); Values p = req.parameters(); @@ -83,4 +87,5 @@ public class EchoTest extends junit.framework.TestCase { assertTrue(Test.equals(req.returnValues(), refValues)); assertTrue(Test.equals(req.parameters(), refValues)); } + } diff --git a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java index 87651dadfa1..d744fcf8f29 100644 --- a/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java +++ b/jrt/tests/com/yahoo/jrt/InvokeAsyncTest.java @@ -2,7 +2,14 @@ package com.yahoo.jrt; -public class InvokeAsyncTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class InvokeAsyncTest { Supervisor server; Acceptor acceptor; @@ -10,10 +17,7 @@ public class InvokeAsyncTest extends junit.framework.TestCase { Target target; Test.Barrier barrier; - public InvokeAsyncTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -27,6 +31,7 @@ public class InvokeAsyncTest extends junit.framework.TestCase { barrier = new Test.Barrier(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -42,8 +47,8 @@ public class InvokeAsyncTest extends junit.framework.TestCase { .get(1).asString())); } + @org.junit.Test public void testAsync() { - Request req = new Request("concat"); req.parameters().add(new StringValue("abc")); req.parameters().add(new StringValue("def")); @@ -59,4 +64,5 @@ public class InvokeAsyncTest extends junit.framework.TestCase { assertEquals(1, req.returnValues().size()); assertEquals("abcdef", req.returnValues().get(0).asString()); } + } diff --git a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java index 71e2ca9d83c..6fe92be97e5 100644 --- a/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java +++ b/jrt/tests/com/yahoo/jrt/InvokeErrorTest.java @@ -2,7 +2,14 @@ package com.yahoo.jrt; -public class InvokeErrorTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class InvokeErrorTest { + final double timeout=60.0; Supervisor server; Acceptor acceptor; @@ -10,10 +17,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { Target target; Test.Barrier barrier; - public InvokeErrorTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -25,6 +29,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { barrier = new Test.Barrier(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -51,6 +56,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { barrier.waitFor(); } + @org.junit.Test public void testNoError() { Request req1 = new Request("test"); req1.parameters().add(new Int32Value(42)); @@ -62,6 +68,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(42, req1.returnValues().get(0).asInt32()); } + @org.junit.Test public void testNoSuchMethod() { Request req1 = new Request("bogus"); target.invokeSync(req1, timeout); @@ -70,6 +77,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(ErrorCode.NO_SUCH_METHOD, req1.errorCode()); } + @org.junit.Test public void testWrongParameters() { Request req1 = new Request("test"); req1.parameters().add(new Int32Value(42)); @@ -99,6 +107,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(ErrorCode.WRONG_PARAMS, req3.errorCode()); } + @org.junit.Test public void testWrongReturnValues() { Request req1 = new Request("test"); req1.parameters().add(new Int32Value(42)); @@ -110,6 +119,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(ErrorCode.WRONG_RETURN, req1.errorCode()); } + @org.junit.Test public void testMethodFailed() { Request req1 = new Request("test"); req1.parameters().add(new Int32Value(42)); @@ -130,6 +140,7 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(75000, req2.errorCode()); } + @org.junit.Test public void testConnectionError() { Test.Waiter w = new Test.Waiter(); Request req1 = new Request("test_barrier"); @@ -146,4 +157,5 @@ public class InvokeErrorTest extends junit.framework.TestCase { assertEquals(0, req1.returnValues().size()); assertEquals(ErrorCode.CONNECTION, req1.errorCode()); } + } diff --git a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java index c3a27368264..37856c0db81 100644 --- a/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java +++ b/jrt/tests/com/yahoo/jrt/InvokeSyncTest.java @@ -8,19 +8,21 @@ import java.io.IOException; import java.io.PrintStream; import com.yahoo.jrt.tool.RpcInvoker; +import org.junit.After; +import org.junit.Before; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class InvokeSyncTest extends junit.framework.TestCase { + +public class InvokeSyncTest { Supervisor server; Acceptor acceptor; Supervisor client; Target target; - public InvokeSyncTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -35,6 +37,7 @@ public class InvokeSyncTest extends junit.framework.TestCase { .methodDesc("Method taking all types of params")); } + @After public void tearDown() { System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); target.close(); @@ -54,6 +57,7 @@ public class InvokeSyncTest extends junit.framework.TestCase { req.returnValues().add(new StringValue("This was alltypes. The string param was: "+req.parameters().get(6).asString())); } + @org.junit.Test public void testSync() { Request req = new Request("concat"); req.parameters().add(new StringValue("abc")); @@ -65,7 +69,8 @@ public class InvokeSyncTest extends junit.framework.TestCase { assertEquals(1, req.returnValues().size()); assertEquals("abcdef", req.returnValues().get(0).asString()); } - + + @org.junit.Test public void testRpcInvoker() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); diff --git a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java index f357e6e61b1..d0c0d9c728e 100644 --- a/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java +++ b/jrt/tests/com/yahoo/jrt/InvokeVoidTest.java @@ -2,17 +2,20 @@ package com.yahoo.jrt; -public class InvokeVoidTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class InvokeVoidTest { Test.Orb server; Acceptor acceptor; Test.Orb client; Target target; - public InvokeVoidTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Test.Orb(new Transport()); client = new Test.Orb(new Transport()); @@ -29,6 +32,7 @@ public class InvokeVoidTest extends junit.framework.TestCase { .returnDesc(0, "value", "the stored value")); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -48,8 +52,8 @@ public class InvokeVoidTest extends junit.framework.TestCase { req.returnValues().add(new Int32Value(value)); } + @org.junit.Test public void testInvokeVoid() { - Request req = new Request("set"); req.parameters().add(new Int32Value(40)); target.invokeSync(req, 5.0); @@ -71,4 +75,5 @@ public class InvokeVoidTest extends junit.framework.TestCase { assertTrue(server.readBytes == client.writeBytes); assertTrue(client.readBytes == server.writeBytes); } + } diff --git a/jrt/tests/com/yahoo/jrt/ListenTest.java b/jrt/tests/com/yahoo/jrt/ListenTest.java index 945c76469c8..88fd6f22f24 100644 --- a/jrt/tests/com/yahoo/jrt/ListenTest.java +++ b/jrt/tests/com/yahoo/jrt/ListenTest.java @@ -1,23 +1,27 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; +import org.junit.After; +import org.junit.Before; -public class ListenTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; - Supervisor server; +public class ListenTest { - public ListenTest(String name) { - super(name); - } + Supervisor server; + @Before public void setUp() { server = new Supervisor(new Transport()); } + @After public void tearDown() { server.transport().shutdown().join(); } + @org.junit.Test public void testListen() { try { Acceptor a = server.listen(new Spec(Test.PORT)); @@ -61,6 +65,7 @@ public class ListenTest extends junit.framework.TestCase { } } + @org.junit.Test public void testBogusListen() { try { Acceptor a = server.listen(new Spec("bogus")); @@ -81,6 +86,7 @@ public class ListenTest extends junit.framework.TestCase { } } + @org.junit.Test public void testListenAnyPort() { try { Acceptor a = server.listen(new Spec("tcp/0")); @@ -95,4 +101,5 @@ public class ListenTest extends junit.framework.TestCase { assertTrue(false); } } + } diff --git a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java index 8ef983eab55..c61cae18c09 100644 --- a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java +++ b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java @@ -2,20 +2,24 @@ package com.yahoo.jrt; +import org.junit.After; +import org.junit.Before; + import java.util.HashSet; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + -public class MandatoryMethodsTest extends junit.framework.TestCase { +public class MandatoryMethodsTest { Supervisor server; Acceptor acceptor; Supervisor client; Target target; - public MandatoryMethodsTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -23,6 +27,7 @@ public class MandatoryMethodsTest extends junit.framework.TestCase { target = client.connect(new Spec("localhost", Test.PORT)); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -30,8 +35,8 @@ public class MandatoryMethodsTest extends junit.framework.TestCase { server.transport().shutdown().join(); } + @org.junit.Test public void testPing() { - Request req = new Request("frt.rpc.ping"); target.invokeSync(req, 5.0); @@ -39,8 +44,8 @@ public class MandatoryMethodsTest extends junit.framework.TestCase { assertEquals(0, req.returnValues().size()); } + @org.junit.Test public void testGetMethodList() { - Request req = new Request("frt.rpc.getMethodList"); target.invokeSync(req, 5.0); @@ -72,6 +77,7 @@ public class MandatoryMethodsTest extends junit.framework.TestCase { assertTrue(foundSet.contains("frt.rpc.getMethodInfo")); } + @org.junit.Test public void testGetMethodInfo() { Request req = new Request("frt.rpc.getMethodInfo"); req.parameters().add(new StringValue("frt.rpc.getMethodInfo")); @@ -94,4 +100,5 @@ public class MandatoryMethodsTest extends junit.framework.TestCase { assertEquals(7, retName.length); assertTrue(retName.length == retDesc.length); } + } diff --git a/jrt/tests/com/yahoo/jrt/PacketTest.java b/jrt/tests/com/yahoo/jrt/PacketTest.java index 158b80b3ff2..8658cc8d61b 100644 --- a/jrt/tests/com/yahoo/jrt/PacketTest.java +++ b/jrt/tests/com/yahoo/jrt/PacketTest.java @@ -1,17 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; - import java.nio.ByteBuffer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class PacketTest extends junit.framework.TestCase { - - public PacketTest(String name) { - super(name); - } - +public class PacketTest { + @org.junit.Test public void testRequestPacket() { Values params = new Values(); @@ -53,9 +50,8 @@ public class PacketTest extends junit.framework.TestCase { assertEquals(params2.get(0).asInt32(), 123); } - + @org.junit.Test public void testReplyPacket() { - Values ret = new Values(); ret.add(new Int32Value(123)); @@ -90,9 +86,8 @@ public class PacketTest extends junit.framework.TestCase { assertEquals(ret2.get(0).asInt32(), 123); } - + @org.junit.Test public void testErrorPacket() { - String errStr = "NSM"; Packet packet = new ErrorPacket(0, 42, ErrorCode.NO_SUCH_METHOD, errStr); @@ -126,4 +121,5 @@ public class PacketTest extends junit.framework.TestCase { ((ErrorPacket)packet2).errorCode()); assertEquals(errStr, ((ErrorPacket)packet2).errorMessage()); } + } diff --git a/jrt/tests/com/yahoo/jrt/QueueTest.java b/jrt/tests/com/yahoo/jrt/QueueTest.java index 28fcf5c4b53..c3bac34db69 100644 --- a/jrt/tests/com/yahoo/jrt/QueueTest.java +++ b/jrt/tests/com/yahoo/jrt/QueueTest.java @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; -public class QueueTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; - public QueueTest(String name) { - super(name); - } +public class QueueTest { + @org.junit.Test public void testEmpty() { Queue queue = new Queue(); @@ -19,6 +20,7 @@ public class QueueTest extends junit.framework.TestCase { assertFalse(queue.dequeue() == null); } + @org.junit.Test public void testEnqueueDequeue() { Queue queue = new Queue(); Integer int1 = new Integer(1); @@ -69,6 +71,7 @@ public class QueueTest extends junit.framework.TestCase { assertEquals(queue.size(), 0); } + @org.junit.Test public void testFlush() { Queue src = new Queue(); Queue dst = new Queue(); @@ -94,4 +97,5 @@ public class QueueTest extends junit.framework.TestCase { assertTrue(dst.dequeue() == int2); assertTrue(dst.dequeue() == int3); } + } diff --git a/jrt/tests/com/yahoo/jrt/SchedulerTest.java b/jrt/tests/com/yahoo/jrt/SchedulerTest.java index 362552754e9..1429dd5e779 100644 --- a/jrt/tests/com/yahoo/jrt/SchedulerTest.java +++ b/jrt/tests/com/yahoo/jrt/SchedulerTest.java @@ -1,9 +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.jrt; +import org.junit.After; +import org.junit.Before; + import java.util.Random; -public class SchedulerTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SchedulerTest { long now; // fake time Scheduler scheduler; @@ -88,19 +95,18 @@ public class SchedulerTest extends junit.framework.TestCase { } } - public SchedulerTest(String name) { - super(name); - } - + @Before public void setUp() { now = 0; scheduler = new Scheduler(now); } + @After public void tearDown() { scheduler = null; } + @org.junit.Test public void testTimeliness() { Random rand = new Random(73201242); @@ -130,6 +136,7 @@ public class SchedulerTest extends junit.framework.TestCase { } } + @org.junit.Test public void testUnschedule() { MyTask t1 = new MyTask(1000); MyTask t2 = new MyTask(1000); @@ -204,6 +211,7 @@ public class SchedulerTest extends junit.framework.TestCase { assertEquals(cnt, rt5.cnt()); } + @org.junit.Test public void testSlowEventLoop() { scheduler.checkTasks(now); now += 10000; @@ -235,4 +243,5 @@ public class SchedulerTest extends junit.framework.TestCase { } assertTrue(cnt2 > 10 && cnt2 < 30); } + } diff --git a/jrt/tests/com/yahoo/jrt/SessionTest.java b/jrt/tests/com/yahoo/jrt/SessionTest.java index 65e80ae1464..afe14bfb908 100644 --- a/jrt/tests/com/yahoo/jrt/SessionTest.java +++ b/jrt/tests/com/yahoo/jrt/SessionTest.java @@ -2,8 +2,14 @@ package com.yahoo.jrt; -public class SessionTest extends junit.framework.TestCase - implements SessionHandler { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SessionTest implements SessionHandler { private static class Session { private static int cnt = 0; @@ -102,10 +108,7 @@ public class SessionTest extends junit.framework.TestCase Target target; Test.Receptor receptor; - public SessionTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { Session.reset(); server = new Test.Orb(new Transport()); @@ -127,6 +130,7 @@ public class SessionTest extends junit.framework.TestCase receptor = new Test.Receptor(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -238,6 +242,7 @@ public class SessionTest extends junit.framework.TestCase client.transport().sync().sync(); } + @org.junit.Test public void testConnDownLast() { waitState(2, 1, 1, 0, 0, 1, 1, 0, 0); assertEquals(2, Session.cnt()); @@ -287,6 +292,7 @@ public class SessionTest extends junit.framework.TestCase assertFalse(Session.getError()); } + @org.junit.Test public void testReqDoneLast() { waitState(2, 1, 1, 0, 0, 1, 1, 0, 0); assertEquals(2, Session.cnt()); @@ -353,6 +359,7 @@ public class SessionTest extends junit.framework.TestCase assertFalse(Session.getError()); } + @org.junit.Test public void testNeverLive() { waitState(2, 1, 1, 0, 0, 1, 1, 0, 0); assertEquals(2, Session.cnt()); @@ -392,6 +399,7 @@ public class SessionTest extends junit.framework.TestCase assertFalse(Session.getError()); } + @org.junit.Test public void testTransportDown() { waitState(2, 1, 1, 0, 0, 1, 1, 0, 0); assertEquals(2, Session.cnt()); @@ -448,4 +456,5 @@ public class SessionTest extends junit.framework.TestCase assertEquals(3, client.finiCount); assertFalse(Session.getError()); } + } diff --git a/jrt/tests/com/yahoo/jrt/SlobrokTest.java b/jrt/tests/com/yahoo/jrt/SlobrokTest.java index dad9614336d..ee15c7cd1de 100644 --- a/jrt/tests/com/yahoo/jrt/SlobrokTest.java +++ b/jrt/tests/com/yahoo/jrt/SlobrokTest.java @@ -11,9 +11,14 @@ import com.yahoo.jrt.slobrok.api.Mirror; import com.yahoo.jrt.slobrok.api.Register; import com.yahoo.jrt.slobrok.api.Mirror.Entry; import com.yahoo.jrt.slobrok.server.Slobrok; +import org.junit.After; +import org.junit.Before; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -public class SlobrokTest extends junit.framework.TestCase { + +public class SlobrokTest { private static class SpecList extends ArrayList<Mirror.Entry> { public SpecList add(String name, String spec) { @@ -32,10 +37,7 @@ public class SlobrokTest extends junit.framework.TestCase { String mySpec = null; Slobrok slobrok; - public SlobrokTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { slobrok = new Slobrok(); slobroks = new String[1]; @@ -49,6 +51,7 @@ public class SlobrokTest extends junit.framework.TestCase { mySpec = new Spec("localhost", acceptor.port()).toString(); } + @After public void tearDown() { register.shutdown(); mirror.shutdown(); @@ -99,6 +102,7 @@ public class SlobrokTest extends junit.framework.TestCase { } } + @org.junit.Test public void testSlobrok() { String wantName = "A/x/w"; register.registerName(wantName); @@ -232,4 +236,5 @@ public class SlobrokTest extends junit.framework.TestCase { public static void err(String msg) { System.err.println(msg); } + } diff --git a/jrt/tests/com/yahoo/jrt/SpecTest.java b/jrt/tests/com/yahoo/jrt/SpecTest.java index 010c17c7cf8..bfbab884d74 100644 --- a/jrt/tests/com/yahoo/jrt/SpecTest.java +++ b/jrt/tests/com/yahoo/jrt/SpecTest.java @@ -3,12 +3,14 @@ package com.yahoo.jrt; import java.net.InetSocketAddress; -public class SpecTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; - public SpecTest(String name) { - super(name); - } +public class SpecTest { + @org.junit.Test public void testPort() { Spec spec = new Spec(457); InetSocketAddress addr = new InetSocketAddress(457); @@ -20,6 +22,7 @@ public class SpecTest extends junit.framework.TestCase { assertTrue(addr.equals(spec.address())); } + @org.junit.Test public void testHostPort() { String host = "localhost"; Spec spec = new Spec(host, 457); @@ -32,6 +35,7 @@ public class SpecTest extends junit.framework.TestCase { assertTrue(addr.equals(spec.address())); } + @org.junit.Test public void testBogusHostPort() { String host = "bogus.host.name"; Spec spec = new Spec(host, 457); @@ -44,6 +48,7 @@ public class SpecTest extends junit.framework.TestCase { assertTrue(addr.equals(spec.address())); } + @org.junit.Test public void testSpec1() { Spec spec = new Spec("tcp/localhost:8080"); InetSocketAddress addr = new InetSocketAddress("localhost", 8080); @@ -55,6 +60,7 @@ public class SpecTest extends junit.framework.TestCase { assertTrue(addr.equals(spec.address())); } + @org.junit.Test public void testSpec2() { Spec spec = new Spec("tcp/8080"); InetSocketAddress addr = new InetSocketAddress(8080); @@ -66,6 +72,7 @@ public class SpecTest extends junit.framework.TestCase { assertTrue(addr.equals(spec.address())); } + @org.junit.Test public void testBogusSpec1() { Spec spec = new Spec("localhost:8080"); @@ -76,6 +83,7 @@ public class SpecTest extends junit.framework.TestCase { assertNull(spec.address()); } + @org.junit.Test public void testBogusSpec2() { Spec spec = new Spec("tcp/localhost:xyz"); @@ -86,6 +94,7 @@ public class SpecTest extends junit.framework.TestCase { assertNull(spec.address()); } + @org.junit.Test public void testBogusSpec3() { Spec spec = new Spec("tcp/localhost:"); @@ -95,4 +104,5 @@ public class SpecTest extends junit.framework.TestCase { assertNull(spec.host()); assertNull(spec.address()); } + } diff --git a/jrt/tests/com/yahoo/jrt/Test.java b/jrt/tests/com/yahoo/jrt/Test.java index 9b039899125..b538d5729e5 100644 --- a/jrt/tests/com/yahoo/jrt/Test.java +++ b/jrt/tests/com/yahoo/jrt/Test.java @@ -1,13 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; - import java.util.Arrays; +public class Test { -public class Test extends junit.framework.TestCase { - - public Test(String name) { super(name); } + @org.junit.Test public void testNothing() {} // www.random.org [2000, 9999] @@ -233,4 +231,5 @@ public class Test extends junit.framework.TestCase { } return true; } + } diff --git a/jrt/tests/com/yahoo/jrt/TimeoutTest.java b/jrt/tests/com/yahoo/jrt/TimeoutTest.java index ce9bb954d74..d1eb2a9895a 100644 --- a/jrt/tests/com/yahoo/jrt/TimeoutTest.java +++ b/jrt/tests/com/yahoo/jrt/TimeoutTest.java @@ -2,7 +2,13 @@ package com.yahoo.jrt; -public class TimeoutTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class TimeoutTest { Supervisor server; Acceptor acceptor; @@ -10,10 +16,7 @@ public class TimeoutTest extends junit.framework.TestCase { Target target; Test.Barrier barrier; - public TimeoutTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -27,6 +30,7 @@ public class TimeoutTest extends junit.framework.TestCase { barrier = new Test.Barrier(); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -42,6 +46,7 @@ public class TimeoutTest extends junit.framework.TestCase { .get(1).asString())); } + @org.junit.Test public void testTimeout() { Request req = new Request("concat"); req.parameters().add(new StringValue("abc")); @@ -60,6 +65,7 @@ public class TimeoutTest extends junit.framework.TestCase { assertEquals(0, req.returnValues().size()); } + @org.junit.Test public void testNotTimeout() { Request req = new Request("concat"); req.parameters().add(new StringValue("abc")); @@ -75,4 +81,5 @@ public class TimeoutTest extends junit.framework.TestCase { assertEquals(1, req.returnValues().size()); assertEquals("abcdef", req.returnValues().get(0).asString()); } + } diff --git a/jrt/tests/com/yahoo/jrt/ValuesTest.java b/jrt/tests/com/yahoo/jrt/ValuesTest.java index a7058234170..f70af0d7898 100644 --- a/jrt/tests/com/yahoo/jrt/ValuesTest.java +++ b/jrt/tests/com/yahoo/jrt/ValuesTest.java @@ -4,12 +4,12 @@ package com.yahoo.jrt; import java.nio.ByteBuffer; import java.util.Arrays; -public class ValuesTest extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; - public ValuesTest(String name) { - super(name); - } +public class ValuesTest { + @org.junit.Test public void testEmpty() { Values src = new Values(); assertEquals(src.bytes(), 4); @@ -30,6 +30,7 @@ public class ValuesTest extends junit.framework.TestCase { assertEquals(v.bytes(), bytes); } + @org.junit.Test public void testInt8() { int byteSize = 4 + 1 + 1; Values src = new Values(); @@ -47,6 +48,7 @@ public class ValuesTest extends junit.framework.TestCase { assertEquals(dst.get(0).asInt8(), (byte)1); } + @org.junit.Test public void testInt8Array() { int byteSize = 4 + 1 + 4 + 4; Values src = new Values(); @@ -65,6 +67,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asInt8Array(), val)); } + @org.junit.Test public void testInt16() { int byteSize = 4 + 1 + 2; Values src = new Values(); @@ -82,6 +85,7 @@ public class ValuesTest extends junit.framework.TestCase { assertEquals(dst.get(0).asInt16(), (short)2); } + @org.junit.Test public void testInt16Array() { int byteSize = 4 + 1 + 4 + 4 * 2; Values src = new Values(); @@ -100,6 +104,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asInt16Array(), val)); } + @org.junit.Test public void testInt32() { int byteSize = 4 + 1 + 4; Values src = new Values(); @@ -117,6 +122,7 @@ public class ValuesTest extends junit.framework.TestCase { assertEquals(dst.get(0).asInt32(), 4); } + @org.junit.Test public void testInt32Array() { int byteSize = 4 + 1 + 4 + 4 * 4; Values src = new Values(); @@ -135,6 +141,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asInt32Array(), val)); } + @org.junit.Test public void testInt64() { int byteSize = 4 + 1 + 8; Values src = new Values(); @@ -152,6 +159,7 @@ public class ValuesTest extends junit.framework.TestCase { assertEquals(dst.get(0).asInt64(), 8); } + @org.junit.Test public void testInt64Array() { int byteSize = 4 + 1 + 4 + 4 * 8; Values src = new Values(); @@ -170,6 +178,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asInt64Array(), val)); } + @org.junit.Test public void testFloat() { int byteSize = 4 + 1 + 4; Values src = new Values(); @@ -187,6 +196,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(0).asFloat() == (float)2.5); } + @org.junit.Test public void testFloatArray() { int byteSize = 4 + 1 + 4 + 4 * 4; Values src = new Values(); @@ -205,6 +215,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asFloatArray(), val)); } + @org.junit.Test public void testDouble() { int byteSize = 4 + 1 + 8; Values src = new Values(); @@ -222,6 +233,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(0).asDouble() == 3.75); } + @org.junit.Test public void testDoubleArray() { int byteSize = 4 + 1 + 4 + 4 * 8; Values src = new Values(); @@ -240,6 +252,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asDoubleArray(), val)); } + @org.junit.Test public void testData() { int byteSize = 4 + 1 + 4 + 4; Values src = new Values(); @@ -258,6 +271,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asData(), val)); } + @org.junit.Test public void testDataArray() { int byteSize = 4 + 1 + 4 + 4 * (4 + 4); Values src = new Values(); @@ -282,6 +296,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(Arrays.equals(dst.get(0).asDataArray()[3], val[3])); } + @org.junit.Test public void testString1() { int byteSize = 4 + 1 + 4 + 4; Values src = new Values(); @@ -300,6 +315,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(0).asString().equals("test")); } + @org.junit.Test public void testString2() { int byteSize = 4 + 1 + 4 + 7; Values src = new Values(); @@ -328,6 +344,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(0).asString().equals("H\u00E5vard")); } + @org.junit.Test public void testStringArray() { int byteSize = 4 + 1 + 4 + 4 * 4 + 3 + 3 + 5 + 4; Values src = new Values(); @@ -349,6 +366,7 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(0).asStringArray()[3].equals("four")); } + @org.junit.Test public void testAllValues() { int byteSize = 4 + 16 // typestring @@ -432,4 +450,5 @@ public class ValuesTest extends junit.framework.TestCase { assertTrue(dst.get(15).asStringArray()[2].equals("three")); assertTrue(dst.get(15).asStringArray()[3].equals("four")); } + } diff --git a/jrt/tests/com/yahoo/jrt/WatcherTest.java b/jrt/tests/com/yahoo/jrt/WatcherTest.java index 679f87b04d9..591a55662f0 100644 --- a/jrt/tests/com/yahoo/jrt/WatcherTest.java +++ b/jrt/tests/com/yahoo/jrt/WatcherTest.java @@ -2,7 +2,14 @@ package com.yahoo.jrt; -public class WatcherTest extends junit.framework.TestCase { +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class WatcherTest { private static class Watcher implements TargetWatcher { private int notifyCnt = 0; @@ -25,10 +32,7 @@ public class WatcherTest extends junit.framework.TestCase { Supervisor client; Target target; - public WatcherTest(String name) { - super(name); - } - + @Before public void setUp() throws ListenFailedException { server = new Supervisor(new Transport()); client = new Supervisor(new Transport()); @@ -36,6 +40,7 @@ public class WatcherTest extends junit.framework.TestCase { target = client.connect(new Spec("localhost", Test.PORT)); } + @After public void tearDown() { target.close(); acceptor.shutdown().join(); @@ -43,6 +48,7 @@ public class WatcherTest extends junit.framework.TestCase { server.transport().shutdown().join(); } + @org.junit.Test public void testNotify() { Watcher w1 = new Watcher(); Watcher w2 = new Watcher(); @@ -95,4 +101,5 @@ public class WatcherTest extends junit.framework.TestCase { assertEquals(0, w4.cnt()); assertEquals(0, w5.cnt()); } + } diff --git a/jrt/tests/com/yahoo/jrt/tool/RpcInvokerTest.java b/jrt/tests/com/yahoo/jrt/tool/RpcInvokerTest.java index 7b1d37b1ba4..6e2d02d548b 100644 --- a/jrt/tests/com/yahoo/jrt/tool/RpcInvokerTest.java +++ b/jrt/tests/com/yahoo/jrt/tool/RpcInvokerTest.java @@ -2,33 +2,36 @@ package com.yahoo.jrt.tool; import com.yahoo.jrt.Request; +import org.junit.Test; import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class RpcInvokerTest extends junit.framework.TestCase { - - public RpcInvokerTest(String name) { - super(name); - } +public class RpcInvokerTest { + @Test public void test0Args() { assertCorrectArguments(""); } + @Test public void test1StringShorthanArgs() { assertCorrectArguments("foo"); } + @Test public void test2StringArgs() { assertCorrectArguments("s:foo s:bar"); } + @Test public void test2StringShorthandArgs() { assertCorrectArguments("foo bar"); } |