Author: julien(a)jboss.com
Date: 2007-10-15 18:04:06 -0400 (Mon, 15 Oct 2007)
New Revision: 8666
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java
Log:
more meta tests
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-15 20:58:30
UTC (rev 8665)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-15 22:04:06
UTC (rev 8666)
@@ -48,6 +48,9 @@
public static void main(String[] args) throws Exception
{
AssertTests.main(args);
+ TestIdTests.main(args);
+
+ //
AbstractPOJOTests.main(args);
JUnitPOJOTests.main(args);
CompositeTestRunnerTests.main(args);
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java
(rev 0)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java 2007-10-15
22:04:06 UTC (rev 8666)
@@ -0,0 +1,185 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit;
+
+import org.jboss.unit.TestId;
+
+import static org.jboss.unit.api.Assert.*;
+import static org.jboss.unit.util.CollectionTools.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestIdTests
+{
+
+ public static void main(String[] args)
+ {
+ testEquals();
+ testCtor();
+ testCtorThrowsIAE();
+ testRange();
+ }
+
+ private static void testRange()
+ {
+ assertValue(new TestId().range(0));
+ assertValue(new TestId("abc").range(1));
+ assertValue(new TestId("abc", "def").range(1),
"def");
+ assertValue(new TestId("abc", "def").range(2));
+ assertValue(new TestId("abc", "def", "ghi").range(1),
"def", "ghi");
+ assertValue(new TestId("abc", "def", "ghi").range(2),
"ghi");
+
+ //
+ try
+ {
+ new TestId().range(-1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new TestId().range(1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new TestId("abc").range(-1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new TestId("abc").range(2);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ private static void testEquals()
+ {
+ assertEquals(new TestId(), new TestId());
+ assertNotEquals(new TestId(), new TestId("abc"));
+ assertNotEquals(new TestId(), new TestId("abc", "def"));
+ assertNotEquals(new TestId("abc"), new TestId());
+ assertEquals(new TestId("abc"), new TestId("abc"));
+ assertNotEquals(new TestId("abc"), new TestId("abc",
"def"));
+ assertNotEquals(new TestId("abc", "def"), new TestId());
+ assertNotEquals(new TestId("abc", "def"), new
TestId("abc"));
+ assertEquals(new TestId("abc", "def"), new
TestId("abc", "def"));
+ }
+
+ private static void testCtor()
+ {
+ assertValue(new TestId());
+ assertValue(new TestId("abc"), "abc");
+ assertValue(new TestId("abc", "def"), "abc",
"def");
+ assertValue(new TestId("abc", new TestId("def",
"ghi")), "abc", "def", "ghi");
+ assertValue(new TestId(new TestId("abc", "def"),
"ghi"), "abc", "def", "ghi");
+ assertValue(new TestId(list("abc", "def")), "abc",
"def");
+ }
+
+ private static void testCtorThrowsIAE()
+ {
+ try
+ {
+ new TestId((String[])null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ new TestId((String)null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ new TestId((TestId)null, "abc");
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ new TestId("abc", (TestId)null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ new TestId((Collection<String>)null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ new TestId(Collections.singletonList((String)null));
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ private static void assertValue(TestId id, String... names)
+ {
+ assertEquals(names.length, id.getLength());
+ for (int i = 0;i < id.getLength();i++)
+ {
+ String name = id.getName(i);
+ assertEquals(names[i], name);
+ }
+ ArrayList<String> tmp = new ArrayList<String>();
+ for (Iterator<String> i = id.iterator();i.hasNext();)
+ {
+ tmp.add(i.next());
+ }
+ assertEquals(names, tmp.toArray(new String[tmp.size()]));
+
+ }
+}
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java 2007-10-15 20:58:30 UTC
(rev 8665)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java 2007-10-15 22:04:06 UTC
(rev 8666)
@@ -44,7 +44,12 @@
this.names = new String[0];
}
- public TestId(TestId prefix, String name)
+ /**
+ * @param prefix the prefix
+ * @param name the name
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public TestId(TestId prefix, String name) throws IllegalArgumentException
{
if (prefix == null)
{
@@ -64,7 +69,13 @@
this.names = names;
}
- public TestId(String name, TestId suffix)
+ /**
+ *
+ * @param name the name
+ * @param suffix the suffix
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public TestId(String name, TestId suffix) throws IllegalArgumentException
{
if (suffix == null)
{
@@ -84,18 +95,11 @@
this.names = names;
}
- public TestId(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- //
- this.names = new String[]{name};
- }
-
- public TestId(String... names)
+ /**
+ * @param names if the names array is null or any composite of this name is null
+ */
+ public TestId(String... names) throws IllegalArgumentException
{
if (names == null)
{
@@ -118,7 +122,11 @@
this.names = tmp;
}
- public TestId(Collection<String> names)
+ /**
+ * @param names the collection of names
+ * @throws IllegalArgumentException if the collection argument is null or any value in
the collection is null
+ */
+ public TestId(Collection<String> names) throws IllegalArgumentException
{
if (names == null)
{
@@ -169,7 +177,14 @@
};
}
- public String getName(int index)
+ /**
+ * Return a name in the id.
+ *
+ * @param index the name index to return
+ * @return the specified name
+ * @throws ArrayIndexOutOfBoundsException if the index is lower than zero or greater
than the value returned by <code>getLength()</code>
+ */
+ public String getName(int index) throws ArrayIndexOutOfBoundsException
{
return names[index];
}