Author: julien(a)jboss.com
Date: 2007-10-15 18:09:35 -0400 (Mon, 15 Oct 2007)
New Revision: 8667
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.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/TestIdTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java 2007-10-15
22:04:06 UTC (rev 8666)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/TestIdTests.java 2007-10-15
22:09:35 UTC (rev 8667)
@@ -45,18 +45,40 @@
testCtor();
testCtorThrowsIAE();
testRange();
+ testRangeThrowsIAE();
+ testGetNameThrowsIAE();
}
- private static void testRange()
+ private static void testGetNameThrowsIAE()
{
- 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().getName(-1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new TestId("abc").getName(-1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new TestId("abc").getName(1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
- //
+ private static void testRangeThrowsIAE()
+ {
try
{
new TestId().range(-1);
@@ -91,6 +113,16 @@
}
}
+ 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");
+ }
+
private static void testEquals()
{
assertEquals(new TestId(), new TestId());
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 22:04:06 UTC
(rev 8666)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/TestId.java 2007-10-15 22:09:35 UTC
(rev 8667)
@@ -149,6 +149,11 @@
this.names = tmp;
}
+ /**
+ * Returns an iterator over the names composing this id.
+ *
+ * @return the name iterator
+ */
public Iterator<String> iterator()
{
return new Iterator<String>()
@@ -182,19 +187,38 @@
*
* @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>
+ * @throws IllegalArgumentException if the index is lower than zero or greater than
the value returned by <code>getLength()</code>
*/
- public String getName(int index) throws ArrayIndexOutOfBoundsException
+ public String getName(int index) throws IllegalArgumentException
{
+ if (index < 0)
+ {
+ throw new IllegalArgumentException("Index cannot be negative");
+ }
+ if (index >= names.length)
+ {
+ throw new IllegalArgumentException("Index cannot be greater than the length
" + names.length);
+ }
return names[index];
}
+ /**
+ * Return the number of names composing this id.
+ *
+ * @return the length
+ */
public int getLength()
{
return names.length;
}
- public TestId range(int from)
+ /**
+ * Create a new id by using the names from the specified index up to the last one.
+ * @param from the specified index
+ * @return a new id
+ * throws IllegalArgumentException if the specified index is negative or greater than
the length
+ */
+ public TestId range(int from) throws IllegalArgumentException
{
if (from < 0)
{
Show replies by date