BATCH-191: added accessor for names in FieldSet.
This commit is contained in:
@@ -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>'.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user