Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 15E22200C25 for ; Fri, 24 Feb 2017 15:36:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 145AD160B7A; Fri, 24 Feb 2017 14:36:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 90699160B5C for ; Fri, 24 Feb 2017 15:36:54 +0100 (CET) Received: (qmail 21977 invoked by uid 500); 24 Feb 2017 14:36:53 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 21969 invoked by uid 99); 24 Feb 2017 14:36:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2017 14:36:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6CFBFDFD9E; Fri, 24 Feb 2017 14:36:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cdutz@apache.org To: commits@flex.apache.org Date: Fri, 24 Feb 2017 14:36:53 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] flex-blazeds git commit: - Converted the testsuite to JUnit 4 archived-at: Fri, 24 Feb 2017 14:36:56 -0000 Repository: flex-blazeds Updated Branches: refs/heads/develop 11b0aa132 -> 9f2a242d3 http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java b/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java index afd2680..956dd44 100644 --- a/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java +++ b/core/src/test/java/flex/messaging/services/http/SettingsReplaceUtilTest.java @@ -20,163 +20,136 @@ package flex.messaging.services.http; import flex.messaging.MessageBroker; import flex.messaging.MessageException; import flex.messaging.util.SettingsReplaceUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.util.ArrayList; import java.util.Set; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.junit.Assert; -public class SettingsReplaceUtilTest extends TestCase -{ - public SettingsReplaceUtilTest(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(SettingsReplaceUtilTest.class); - } - - protected void setUp() throws Exception - { - super.setUp(); +public class SettingsReplaceUtilTest { + @Before + public void setUp() throws Exception { MessageBroker broker = new MessageBroker(false); broker.initThreadLocals(); } - protected void tearDown() throws Exception - { - super.tearDown(); - } - - public void testReplaceContextPathDash() - { + @Test + public void testReplaceContextPathDash() { String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context-root}/foo.mxml", "/dev"); String expected = "http://localhost:8100/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceContextPathDot() - { + @Test + public void testReplaceContextPathDot() { String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}/foo.mxml", "/dev"); String expected = "http://localhost:8100/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceContextPathBegin() - { + @Test + public void testReplaceContextPathBegin() { String actual = SettingsReplaceUtil.replaceContextPath("{context.root}/foo.mxml", "/dev"); String expected = "/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceContextPathEnd() - { + @Test + public void testReplaceContextPathEnd() { String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}", "/dev"); String expected = "http://localhost:8100/dev"; Assert.assertEquals(expected, actual); } - public void testReplaceContextPathNull() - { - try - { + @Test + public void testReplaceContextPathNull() { + try { String actual = SettingsReplaceUtil.replaceContextPath("http://localhost:8100/{context.root}", null); - fail("MessageException expected. Result was " + actual); - } - catch (MessageException me) - { + Assert.fail("MessageException expected. Result was " + actual); + } catch (MessageException me) { String error = "{context.root} token cannot"; - Assert.assertTrue(me.getMessage().indexOf(error) != -1); + Assert.assertTrue(me.getMessage().contains(error)); } } - public void testReplaceGivenServerDash() - { + @Test + public void testReplaceGivenServerDash() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server-name}:{server-port}/dev/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1:80/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceGivenServerDot() - { + @Test + public void testReplaceGivenServerDot() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/dev/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1:80/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceGivenServerNullPort() - { - try - { + @Test + public void testReplaceGivenServerNullPort() { + try { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/dev/foo.mxml", - "/dev", "10.1.1.1", null, "http"); - fail("MessageException expected. Result was " + actual); - } - catch (MessageException me) - { + "/dev", "10.1.1.1", null, "http"); + Assert.fail("MessageException expected. Result was " + actual); + } catch (MessageException me) { String error = "{server.port} token cannot"; - Assert.assertTrue(me.getMessage().indexOf(error) != -1); + Assert.assertTrue(me.getMessage().contains(error)); } } - public void testReplaceGivenServerStarPort() - { + @Test + public void testReplaceGivenServerStarPort() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:*/dev/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1:*/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceGivenServerContextRoot() - { + @Test + public void testReplaceGivenServerContextRoot() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/{context.root}/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1:80/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceGivenServerNoPort() - { + @Test + public void testReplaceGivenServerNoPort() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}/dev/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceGivenServerNull() - { - try - { + @Test + public void testReplaceGivenServerNull() { + try { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("http://{server.name}:{server.port}/{context.root}/foo.mxml", - null, null, null, "http"); - fail("MessageException expected. Result was " + actual); - } - catch (MessageException me) - { + null, null, null, "http"); + Assert.fail("MessageException expected. Result was " + actual); + } catch (MessageException me) { String error = "{context.root} token cannot"; - Assert.assertTrue(me.getMessage().indexOf(error) != -1); + Assert.assertTrue(me.getMessage().contains(error)); } } - public void testReplaceGivenServerRelative() - { + @Test + public void testReplaceGivenServerRelative() { String actual = SettingsReplaceUtil.replaceAllTokensGivenServerName("/dev/foo.mxml", - "/dev", "10.1.1.1", "80", "http"); + "/dev", "10.1.1.1", "80", "http"); String expected = "http://10.1.1.1:80/dev/foo.mxml"; Assert.assertEquals(expected, actual); } - public void testReplaceCalculateServer() - { - ArrayList urls = new ArrayList(); + @Test + public void testReplaceCalculateServer() { + ArrayList urls = new ArrayList(); urls.add("http://{server.name}:*/dev/foo.mxml"); Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev"); @@ -185,25 +158,22 @@ public class SettingsReplaceUtilTest extends TestCase Assert.assertTrue(updatedUrls.contains("http://127.0.0.1:*/dev/foo.mxml")); } - public void testReplaceCalculateServerPort() - { - try - { - ArrayList urls = new ArrayList(); + @Test + public void testReplaceCalculateServerPort() { + try { + ArrayList urls = new ArrayList(); urls.add("http://{server.name}:{server.port}/dev/foo.mxml"); Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev"); - fail("MessageException expected. Instead result was " + updatedUrls); - } - catch (MessageException me) - { + Assert.fail("MessageException expected. Instead result was " + updatedUrls); + } catch (MessageException me) { String error = "{server.port} token cannot"; - Assert.assertTrue(me.getMessage().indexOf(error) != -1); + Assert.assertTrue(me.getMessage().contains(error)); } } - public void testReplaceCalculateServerMultiple() - { - ArrayList urls = new ArrayList(); + @Test + public void testReplaceCalculateServerMultiple() { + ArrayList urls = new ArrayList(); urls.add("http://{server.name}:*/dev/foo.mxml"); Set updatedUrls = SettingsReplaceUtil.replaceAllTokensCalculateServerName(urls, "/dev"); int count = updatedUrls.size(); @@ -212,8 +182,8 @@ public class SettingsReplaceUtilTest extends TestCase Assert.assertTrue(updatedUrls.size() == count); // should result in the same list } - public void testIPv6ShortForm() - { + @Test + public void testIPv6ShortForm() { String src = "http://[fe80::20d:60ff:fef9:8757]:8400/qa-regress/basic.html"; String expected = "http://[fe80:0:0:0:20d:60ff:fef9:8757]:8400/qa-regress/basic.html"; Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src)); @@ -221,7 +191,7 @@ public class SettingsReplaceUtilTest extends TestCase src = "http://[fe80::20d:60ff:fef9:8757]:8400/*"; expected = "http://[fe80:0:0:0:20d:60ff:fef9:8757]:8400/*"; Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src)); - + src = "http://[::1]:8400/*"; expected = "http://[0:0:0:0:0:0:0:1]:8400/*"; Assert.assertEquals(expected, SettingsReplaceUtil.updateIPv6(src)); http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java b/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java index 8286345..5e96fe6 100644 --- a/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java +++ b/core/src/test/java/flex/messaging/services/messaging/SubtopicTest.java @@ -17,99 +17,86 @@ package flex.messaging.services.messaging; import org.junit.Assert; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Test; -public class SubtopicTest extends TestCase -{ +public class SubtopicTest { private static final String DEFAULT_SEPERATOR = "."; private static final String ANOTHER_SEPERATOR = "*"; - public SubtopicTest(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(SubtopicTest.class); - } - - public void testMatches1() - { + @Test + public void testMatches1() { Subtopic s1 = new Subtopic("foo", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches2() - { + @Test + public void testMatches2() { Subtopic s1 = new Subtopic("foo", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("bar", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertFalse(result); } - - public void testMatches3() - { + + @Test + public void testMatches3() { Subtopic s1 = new Subtopic("foo.bar", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo.bar", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches4() - { + @Test + public void testMatches4() { Subtopic s1 = new Subtopic("foo.bar", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo*bar", ANOTHER_SEPERATOR); boolean result = s1.matches(s2); Assert.assertFalse(result); } - public void testMatches5() - { + @Test + public void testMatches5() { Subtopic s1 = new Subtopic("*", DEFAULT_SEPERATOR); - Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); + Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches6() - { + @Test + public void testMatches6() { Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo.bar", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches7() - { + @Test + public void testMatches7() { Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches8() - { + @Test + public void testMatches8() { Subtopic s1 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); - Subtopic s2 = new Subtopic("foo.*", DEFAULT_SEPERATOR); + Subtopic s2 = new Subtopic("foo.*", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches9() - { + @Test + public void testMatches9() { Subtopic s1 = new Subtopic("foo.bar.*", DEFAULT_SEPERATOR); - Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); + Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); } - public void testMatches10() - { + @Test + public void testMatches10() { Subtopic s1 = new Subtopic("foo.*", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/Basae64Test.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/util/Basae64Test.java b/core/src/test/java/flex/messaging/util/Basae64Test.java index 284163b..5d90fa3 100644 --- a/core/src/test/java/flex/messaging/util/Basae64Test.java +++ b/core/src/test/java/flex/messaging/util/Basae64Test.java @@ -17,38 +17,25 @@ package flex.messaging.util; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class Basae64Test extends TestCase -{ - public Basae64Test(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(Basae64Test.class); - } +import org.junit.Test; +public class Basae64Test { /** * Try encoding and decoding 10,000 random combinations of bytes. */ - public void testEncodingAndDecoding() - { + @Test + public void testEncodingAndDecoding() { int randomLimit = 500; boolean success = true; - byte raw [] = new byte[(int)(Math.random() * randomLimit)]; + byte raw[] = new byte[(int) (Math.random() * randomLimit)]; - for (int i = 0; i < raw.length; ++i) - { + for (int i = 0; i < raw.length; ++i) { if ((i % 1024) < 256) - raw[i] = (byte)(i % 1024); + raw[i] = (byte) (i % 1024); else - raw[i] = (byte)((int)(Math.random() * 255) - 128); + raw[i] = (byte) ((int) (Math.random() * 255) - 128); } Base64.Encoder encoder = new Base64.Encoder(100); encoder.encode(raw); @@ -59,22 +46,17 @@ public class Basae64Test extends TestCase decoder.decode(encoded); byte check[] = decoder.flush(); - if (check.length != raw.length) - { + if (check.length != raw.length) { success = false; - } - else - { - for (int i = 0; i < check.length; ++i) - { - if (check[i] != raw[i]) - { + } else { + for (int i = 0; i < check.length; ++i) { + if (check[i] != raw[i]) { success = false; break; } } } - assertTrue(success); + org.junit.Assert.assertTrue(success); } } http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/HexTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/util/HexTest.java b/core/src/test/java/flex/messaging/util/HexTest.java index cf5a055..f22e2f5 100644 --- a/core/src/test/java/flex/messaging/util/HexTest.java +++ b/core/src/test/java/flex/messaging/util/HexTest.java @@ -17,40 +17,26 @@ package flex.messaging.util; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class HexTest extends TestCase -{ - public HexTest(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(HexTest.class); - } +import org.junit.*; +public class HexTest { /** * Try encoding and decoding 10,000 random combinations of bytes. */ - public void testEncodingAndDecoding() - { + @Test + public void testEncodingAndDecoding() { int randomLimit = 500; boolean success = true; - for (int myCount = 0; myCount < 10000; myCount++) - { - byte raw [] = new byte[(int)(Math.random() * randomLimit)]; + for (int myCount = 0; myCount < 10000; myCount++) { + byte raw[] = new byte[(int) (Math.random() * randomLimit)]; - for (int i = 0; i < raw.length; ++i) - { - if ((i % 1024) < 256) - raw[i] = (byte)(i % 1024); - else - raw[i] = (byte)((int)(Math.random() * 255) - 128); + for (int i = 0; i < raw.length; ++i) { + if ((i % 1024) < 256) { + raw[i] = (byte) (i % 1024); + } else { + raw[i] = (byte) ((int) (Math.random() * 255) - 128); + } } Hex.Encoder encoder = new Hex.Encoder(100); encoder.encode(raw); @@ -61,28 +47,22 @@ public class HexTest extends TestCase decoder.decode(encoded); byte check[] = decoder.flush(); - if (check.length != raw.length) - { + if (check.length != raw.length) { success = false; - } - else - { - for (int i = 0; i < check.length; ++i) - { - if (check[i] != raw[i]) - { + } else { + for (int i = 0; i < check.length; ++i) { + if (check[i] != raw[i]) { success = false; break; } } } - if (!success) - { + if (!success) { break; } } - assertTrue(success); + org.junit.Assert.assertTrue(success); } } http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/UUIDUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/util/UUIDUtilTest.java b/core/src/test/java/flex/messaging/util/UUIDUtilTest.java index 2f8b93d..4cb3a82 100644 --- a/core/src/test/java/flex/messaging/util/UUIDUtilTest.java +++ b/core/src/test/java/flex/messaging/util/UUIDUtilTest.java @@ -17,146 +17,137 @@ package flex.messaging.util; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.*; -public class UUIDUtilTest extends TestCase +public class UUIDUtilTest { - public UUIDUtilTest(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(UUIDUtilTest.class); - } - + @Test public void testIsUID() { // Randomly generated String uid = UUIDUtils.createUUID(); boolean result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // Pre-determined normal UID uid = "8653177A-930D-F5DC-6FAA-E1E6F557504E"; result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // All numbers uid = "06531779-9303-5532-6123-617685575043"; result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // All letters uid = "FEABCDEE-FFCC-FCED-DAAB-BCDEFFABCDAE"; result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // All Fs uid = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"; result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // All 0s uid = "00000000-0000-0000-0000-000000000000"; result = UUIDUtils.isUID(uid); - assertEquals(true, result); + org.junit.Assert.assertEquals(true, result); // Invalid: Too long uid = "8653177A-930D-F5DC-6FAA-E1E6F557504EA"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: Too short uid = "8653177A-930D-F5DC-6FAA-E1E6F557504"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: all hyphens uid = "------------------------------------"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: No hyphens uid = "8653177A0930D0F5DC06FAA0E1E6F557504E"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: non-hex char at end uid = "8653177A-930D-F5DC-6FAA-E1E6F557504Z"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: non-hex char at start uid = "G653177A-930D-F5DC-6FAA-E1E6F557504E"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: null-char uid = "8653177A-930D-F5DC-6FAA-E1E6F557504\u0000"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: random word uid = "Cacophony"; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: empty string uid = ""; result = UUIDUtils.isUID(uid); - assertEquals(false, result); + org.junit.Assert.assertEquals(false, result); // Invalid: null - uid = null; - result = UUIDUtils.isUID(uid); - assertEquals(false, result); + result = UUIDUtils.isUID(null); + org.junit.Assert.assertEquals(false, result); } + @Test public void testUIDToByteArray() { // Randomly generated String uid = UUIDUtils.createUUID(); byte[] result = UUIDUtils.toByteArray(uid); - assertEquals(true, result.length == 16); + org.junit.Assert.assertNotNull(result); + org.junit.Assert.assertEquals(true, result.length == 16); // Pre-determined normal UID uid = "8FEB51AC-1443-CA4C-D3A7-1AC1C5DC517B"; result = UUIDUtils.toByteArray(uid); - assertEquals(true, result.length == 16); + org.junit.Assert.assertNotNull(result); + org.junit.Assert.assertEquals(true, result.length == 16); // Invalid UID uid = "8FEB51AC-1443-CA4C-D3A7-1AC1C5DC517Z"; result = UUIDUtils.toByteArray(uid); - assertEquals(null, result); + org.junit.Assert.assertNull(result); } + @Test public void testUIDFromByteArray() { // Randomly generated String uid1 = UUIDUtils.createUUID(); byte[] ba = UUIDUtils.toByteArray(uid1); String uid2 = UUIDUtils.fromByteArray(ba); - assertEquals(uid1, uid2); + org.junit.Assert.assertEquals(uid1, uid2); // Pre-determined normal UID uid1 = "86531839-0109-8B18-BB3A-CF8F546D0399"; ba = UUIDUtils.toByteArray(uid1); uid2 = UUIDUtils.fromByteArray(ba); - assertEquals(uid1, uid2); + org.junit.Assert.assertEquals(uid1, uid2); // Invalid: ByteArray too short ba = new byte[1]; ba[0] = 19; uid2 = UUIDUtils.fromByteArray(ba); - assertEquals(null, uid2); + org.junit.Assert.assertEquals(null, uid2); // Invalid: null ByteArray - ba = null; - uid2 = UUIDUtils.fromByteArray(ba); - assertEquals(null, uid2); + uid2 = UUIDUtils.fromByteArray(null); + org.junit.Assert.assertEquals(null, uid2); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/9f2a242d/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java b/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java index d3c0286..799f656 100644 --- a/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java +++ b/core/src/test/java/flex/messaging/util/concurrent/DefaultThreadPoolExecutorTest.java @@ -17,10 +17,8 @@ package flex.messaging.util.concurrent; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.junit.Assert; +import org.junit.Test; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; @@ -29,18 +27,10 @@ import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; -public class DefaultThreadPoolExecutorTest extends TestCase +public class DefaultThreadPoolExecutorTest { - public DefaultThreadPoolExecutorTest(String name) - { - super(name); - } - - public static Test suite() - { - return new TestSuite(DefaultThreadPoolExecutorTest.class); - } - + + @Test public void testSimpleExecution() { // Create a small pool with a synchronous queue (no bounding or storage). @@ -59,31 +49,32 @@ public class DefaultThreadPoolExecutorTest extends TestCase boolean success = continueSignal.await(2, TimeUnit.SECONDS); if (!success) { - fail("Test timed out waiting for execution to complete."); + Assert.fail("Test timed out waiting for execution to complete."); } } catch (InterruptedException e) { - fail("Test was interrupted: " + e); + Assert.fail("Test was interrupted: " + e); } // Shut down; because we create the thread pool in this specific impl be sure to shut it down. DefaultThreadPoolExecutor tpe = (DefaultThreadPoolExecutor)executor; tpe.shutdown(); } - + + @Test public void testFailedExecutionHandling() { // Create a small pool with a bounded queue that can only contain one queued task. final DefaultThreadPoolExecutor executor = new DefaultThreadPoolExecutor(1, 1, Integer.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue(1)); final CountDownLatch taskPauseSignal = new CountDownLatch(1); final CountDownLatch executorPauseSignal = new CountDownLatch(1); - final ArrayList failedTasks = new ArrayList(); + final ArrayList failedTasks = new ArrayList(); executor.setFailedExecutionHandler(new FailedExecutionHandler(){ public void failedExecution(Runnable command, Executor ex, Exception exception) { - assertEquals(executor, ex); - assertTrue(exception instanceof RejectedExecutionException); + Assert.assertEquals(executor, ex); + Assert.assertTrue(exception instanceof RejectedExecutionException); failedTasks.add(command); // Unpause the initial task processing. @@ -92,27 +83,27 @@ public class DefaultThreadPoolExecutorTest extends TestCase }); // This first task will pause. - executor.execute(new Task("first", this, taskPauseSignal, executorPauseSignal, executor)); + executor.execute(new Task("first", taskPauseSignal, executorPauseSignal, executor)); // Now queue two more tasks to overflow the executor's queue. - executor.execute(new Task("second", this, null, null, null)); - executor.execute(new Task("third", this, null, null, null)); + executor.execute(new Task("second", null, null, null)); + executor.execute(new Task("third", null, null, null)); // and wait. try { boolean success = executorPauseSignal.await(5 * 60, TimeUnit.SECONDS); if (!success) { - fail("Test timed out waiting for execution to complete."); + Assert.fail("Test timed out waiting for execution to complete."); } } catch (InterruptedException e) { - fail("Test was interrupted: " + e); + Assert.fail("Test was interrupted: " + e); } // Test failed execution handling - assertEquals(failedTasks.size(), 1); - assertTrue(((Task)failedTasks.get(0)).name.equals("third")); + Assert.assertEquals(failedTasks.size(), 1); + Assert.assertTrue(((Task)failedTasks.get(0)).name.equals("third")); // Shut down; because we create the thread pool in this specific impl be sure we shut it down. executor.shutdown(); @@ -120,17 +111,15 @@ public class DefaultThreadPoolExecutorTest extends TestCase static class Task implements Runnable { - public Task(String name, TestCase test, CountDownLatch taskPauseSignal, CountDownLatch executorPauseSignal, DefaultThreadPoolExecutor executor) + Task(String name, CountDownLatch taskPauseSignal, CountDownLatch executorPauseSignal, DefaultThreadPoolExecutor executor) { this.name = name; - this.test = test; this.taskPauseSignal = taskPauseSignal; this.executorPauseSignal = executorPauseSignal; this.executor = executor; } public String name; - private TestCase test; private CountDownLatch taskPauseSignal; private CountDownLatch executorPauseSignal; private DefaultThreadPoolExecutor executor; @@ -149,8 +138,8 @@ public class DefaultThreadPoolExecutorTest extends TestCase else { // At this point we should have the second task queued and the third task should have failed (overflow). - assertEquals(executor.getQueue().size(), 1); - assertTrue(((Task)executor.getQueue().peek()).name.equals("second")); + Assert.assertEquals(executor.getQueue().size(), 1); + Assert.assertTrue(((Task)executor.getQueue().peek()).name.equals("second")); // Unblock the executor test thread. executorPauseSignal.countDown();