Duration("P1Y2MT") should throw IllegalArgumentException
public Duration(java.lang.String lexicalRepresentation)
throws java.lang.IllegalArgumentException
Constructs a new Duration object by parsing its string representation
"PnYnMnDTnHnMnS" as defined in XML Schema 1.0 section 3.2.6.1.
http://www.w3.org/TR/xmlschema-2/#duration-order
- throws java.lang.IllegalArgumentException if the given string does not conform to the aforementioned specification.
and according to the spec ,
- The designator 'T' shall be absent if all of the time items are absent in "PnYnMnDTnHnMnS"
For example, P1Y2MT is not allowed.
So , calling Duration constructor with lexicalRepresentation - "P1Y2MT" should throw java.lang.IllegalArgumentException
Test program - Test3.java
-------------------------------------------------------------------------------
import javax.xml.datatype.Duration;
public class Test3 {
Test3() {}
// main()
public static void main(String[] argv) {
Test3 test3 = new Test3();
test3.checkDuration01();
}
private void checkDuration01() {
try{
Duration duration1 = new Duration("P1Y2MT");
System.out.println(" Expected IllegalArgumentException not thrown - checkDuration01() failed ");
}catch( NullPointerException npe){
System.out.println(" NPE thrown - checkDuration01() failed ");
}catch( IllegalArgumentException iae){
System.out.println(" Expected IllegalArgumentException thrown - checkDuration01 passed ");
}catch( Exception e){
System.out.println(" Exception thrown - checkDuration01() failed ");
}
}
}
-------------------------------------------------------------------------------
---------------------------------
verified in Tiger 1.5.0-beta2-b44
###@###.### 2004-03-30
---------------------------------
public Duration(java.lang.String lexicalRepresentation)
throws java.lang.IllegalArgumentException
Constructs a new Duration object by parsing its string representation
"PnYnMnDTnHnMnS" as defined in XML Schema 1.0 section 3.2.6.1.
http://www.w3.org/TR/xmlschema-2/#duration-order
- throws java.lang.IllegalArgumentException if the given string does not conform to the aforementioned specification.
and according to the spec ,
- The designator 'T' shall be absent if all of the time items are absent in "PnYnMnDTnHnMnS"
For example, P1Y2MT is not allowed.
So , calling Duration constructor with lexicalRepresentation - "P1Y2MT" should throw java.lang.IllegalArgumentException
Test program - Test3.java
-------------------------------------------------------------------------------
import javax.xml.datatype.Duration;
public class Test3 {
Test3() {}
// main()
public static void main(String[] argv) {
Test3 test3 = new Test3();
test3.checkDuration01();
}
private void checkDuration01() {
try{
Duration duration1 = new Duration("P1Y2MT");
System.out.println(" Expected IllegalArgumentException not thrown - checkDuration01() failed ");
}catch( NullPointerException npe){
System.out.println(" NPE thrown - checkDuration01() failed ");
}catch( IllegalArgumentException iae){
System.out.println(" Expected IllegalArgumentException thrown - checkDuration01 passed ");
}catch( Exception e){
System.out.println(" Exception thrown - checkDuration01() failed ");
}
}
}
-------------------------------------------------------------------------------
---------------------------------
verified in Tiger 1.5.0-beta2-b44
###@###.### 2004-03-30
---------------------------------