*
* @throws Exception
*/
public void testOptionalIterator() throws Exception {
OptionalParameterDefinitionIterator iter;
Command cmd;
ParameterDefinition[] defs;
iter = new OptionalParameterDefinitionIterator((Collection<ParameterDefinition>) null);
assertFalse(iter.hasNext());
try {
iter.next();
fail("Should have thrown NoSuchElementException");
} catch (NoSuchElementException nsee) {
}
defs = null;
iter = new OptionalParameterDefinitionIterator(defs);
assertFalse(iter.hasNext());
try {
iter.next();
fail("Should have thrown NoSuchElementException");
} catch (NoSuchElementException nsee) {
}
// there are four definitions but only 3 are optional
cmd = new ParamsTestCommand();
defs = cmd.getParameterDefinitions();
iter = new OptionalParameterDefinitionIterator(defs);
for (int i = 0; i < 3; i++) {
assertNotNull(iter.next());
if ((i + 1) < 3) {
assertTrue(iter.hasNext());
}
}
assertFalse(iter.hasNext());
// there are no definitions
cmd = new NoParamTestCommand();
defs = cmd.getParameterDefinitions();
iter = new OptionalParameterDefinitionIterator(defs);
assertFalse(iter.hasNext());
}