BATCH-191: added accessor for names in FieldSet.

This commit is contained in:
dsyer
2007-11-07 15:15:45 +00:00
parent fd38ac3d14
commit d4c2c8954c
2 changed files with 34 additions and 1 deletions

View File

@@ -58,6 +58,21 @@ public final class FieldSet {
this.tokens = (String[]) tokens.clone();
this.names = Arrays.asList(names);
}
/**
* Public accessor for the names property.
*
* @return the names
*
* @throws IllegalStateException if the names are not defined
*/
public String[] getNames() {
if (names == null) {
throw new IllegalStateException(
"Field names are not known");
}
return (String[]) names.toArray();
}
/**
* Read the {@link String} value at index '<code>index</code>'.

View File

@@ -39,9 +39,23 @@ public class FieldSetTests extends TestCase {
"BigDecimal", "Null", "Date", "DatePattern", "BlankInput" };
fieldSet = new FieldSet(tokens, names);
assertTrue(fieldSet.getFieldCount() == 14);
assertEquals(14, fieldSet.getFieldCount());
}
public void testNames() throws Exception {
assertEquals(fieldSet.getFieldCount(), fieldSet.getNames().length);
}
public void testNamesNotKnown() throws Exception {
fieldSet = new FieldSet(new String[]{"foo"});
try {
fieldSet.getNames();
fail("Expected IllegalStateException");
} catch (IllegalStateException e) {
// expected
}
}
public void testReadString() throws ParseException {
@@ -315,6 +329,10 @@ public class FieldSetTests extends TestCase {
assertEquals(fs1, fs2);
}
public void testNullField() {
assertEquals(null, fieldSet.readString(10));
}
public void testEqualsNull() {
assertFalse(fieldSet.equals(null));
}