You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by le...@apache.org on 2004/08/28 23:12:19 UTC
cvs commit: jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test BeanAttribute.java SealableTestCase.java TargetTestCase.java
leosutic 2004/08/28 14:12:19
Modified: attributes/unittest/src/test/org/apache/commons/attributes/test
BeanAttribute.java SealableTestCase.java
TargetTestCase.java
Log:
+ CircularDependencyError now expects a list of Class instances
instead of a list of any object type. The old behavior is still
supported and will remain so.
+ CircularDependencyError now shows the full circle of dependencies.
+ Added a ParameterIndexOutOfBoundsException to be thrown when
the client tries to retrieve attributes from a parameter of a
constructor or method and the parameter index is out of bounds.
+ Added a SealedAttributeException to be thrown when an attempt to
modify a sealed attribute is made. The exception is a subclass
of the IllegalStateException that used to be thrown.
Revision Changes Path
1.2 +2 -13 jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/BeanAttribute.java
Index: BeanAttribute.java
===================================================================
RCS file: /home/cvs/jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/BeanAttribute.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanAttribute.java 6 Jul 2004 20:43:36 -0000 1.1
+++ BeanAttribute.java 28 Aug 2004 21:12:19 -0000 1.2
@@ -15,32 +15,25 @@
*/
package org.apache.commons.attributes.test;
+import org.apache.commons.attributes.DefaultSealable;
import org.apache.commons.attributes.Sealable;
/**
* A sample attribute with bean-like properties. Used to test the
* named parameter syntax.
*/
-public class BeanAttribute implements Sealable {
+public class BeanAttribute extends DefaultSealable {
private final int number;
private final String string;
private String name;
private int anotherNumber;
- private boolean sealed = false;
-
public BeanAttribute (int number, String string) {
this.number = number;
this.string = string;
}
- protected void checkSealed () {
- if (sealed) {
- throw new IllegalStateException ("Attribute has been sealed and is read-only.");
- }
- }
-
public int getNumber () {
return number;
}
@@ -77,10 +70,6 @@
public int hashCode () {
return string.hashCode ();
- }
-
- public void seal () {
- sealed = true;
}
public String toString () {
1.2 +13 -0 jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/SealableTestCase.java
Index: SealableTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/SealableTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SealableTestCase.java 6 Jul 2004 20:43:41 -0000 1.1
+++ SealableTestCase.java 28 Aug 2004 21:12:19 -0000 1.2
@@ -25,6 +25,7 @@
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
+import org.apache.commons.attributes.SealedAttributeException;
import junit.framework.TestCase;
public class SealableTestCase extends TestCase {
@@ -38,6 +39,18 @@
fail ("Attribute should be sealed!");
} catch (IllegalStateException ise) {
// -- OK, attribute should be sealed.
+ }
+ }
+
+ public void testSealableExceptionType () throws Exception {
+ Method m = Sample.class.getMethod ("methodWithNamedParameters", new Class[]{ });
+ BeanAttribute attribute = (BeanAttribute) Attributes.getAttributes (m, BeanAttribute.class).iterator ().next ();
+
+ try {
+ attribute.setName ("Joe Doe");
+ fail ("Attribute should be sealed!");
+ } catch (SealedAttributeException ise) {
+ // -- OK, attribute should be sealed and throw a SealedAttributeException.
}
}
}
1.2 +4 -1 jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/TargetTestCase.java
Index: TargetTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/TargetTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TargetTestCase.java 6 Jul 2004 20:43:41 -0000 1.1
+++ TargetTestCase.java 28 Aug 2004 21:12:19 -0000 1.2
@@ -30,7 +30,10 @@
fail ();
} catch (InvalidAttributeTargetError iate) {
- System.out.println (iate.getMessage ());
+ assertEquals ("Attributes of type org.apache.commons.attributes.test.AttributeWithTarget " +
+ "can't be applied to org.apache.commons.attributes.test.ClassWithInvalidDeclarations. " +
+ "They can only be applied to: METHOD",
+ iate.getMessage ());
// OK.
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org