TestActionNameMappublic class TestActionNameMap extends ExtendedTestCase Tests for creation of ActionNameMaps. |
Fields Summary |
---|
static final String | localeValid locale. | static final String[] | zeroStringsEmpty string arrays. | static final String[] | oneStringLength 1 string array. | static final String[] | oneNameStringLength 1 name string array. | static final String[] | fiveStringsLength 5 string array. | static final String[] | fiveNameStringsLength 5 names string array. | static final String[] | nullStringString array containing a null. | static final String[] | emptyStringString array containing an empty string. | static final String[] | dupStringString array containing a duplicate string. |
Methods Summary |
---|
void | assertIllegal(java.lang.String message, java.lang.String[] actions, java.lang.String[] actionnames, java.lang.String locale, java.lang.Exception expected)Create an actionNameMap from the args and verify that
ane xception is thrown.
ActionNameMap map;
try {
map = new ActionNameMap(actions, actionnames, locale);
// Always report an error
assertEquals("MUST throw an exception", null, map);
} catch (IllegalArgumentException ill) {
assertEquals(message, expected.getClass().getName(),
ill.getClass().getName());
} catch (NullPointerException npe) {
assertEquals(message, expected.getClass().getName(),
npe.getClass().getName());
}
| void | assertLegal(java.lang.String message, java.lang.String[] actions, java.lang.String[] actionnames, java.lang.String locale)Create an actionNameMap from the args and verify it was created
correctly. Each of the method of the resulting map is
checked with the test case asserts. Exceptions are not handled.
ActionNameMap map;
map = new ActionNameMap(actions, actionnames, locale);
int size = map.size();
assertEquals(message, actions.length, size);
assertEquals(message, actionnames.length, size);
assertEquals(message, locale, map.getLocale());
for (int i = 0; i < size; i++) {
assertEquals(message, actions[i], map.getAction(i));
}
for (int i = 0; i < size; i++) {
assertEquals(message, actionnames[i], map.getActionName(i));
}
for (int i = 0; i < size; i++) {
assertEquals(message, actionnames[i],
map.getActionName(actions[i]));
}
for (int i = 0; i < size; i++) {
assertEquals(message, actions[i], map.getAction(actionnames[i]));
}
| public void | runTests()Run the tests of the Listener.
test001();
test002();
test003();
| private void | test001()Test that the listener is notified when a new Invocation
is queued.
declare("Create Valid maps");
assertLegal("one action/name pair",
oneString, oneNameString, locale);
assertLegal("five action/name pairs",
fiveStrings, fiveNameStrings, locale);
| private void | test002()Test for all the IllegalArgument combinations.
declare("Create Illegal cases");
assertIllegal("empty arrays",
zeroStrings, zeroStrings, locale,
new IllegalArgumentException());
assertIllegal("null actions", null, oneNameString, locale,
new NullPointerException());
assertIllegal("null actionname", oneString, null, locale,
new NullPointerException());
assertIllegal("unequal action/name pairs", oneString, fiveNameStrings,
locale, new IllegalArgumentException());
assertIllegal("null locale", oneString, oneNameString, null,
new NullPointerException());
assertIllegal("empty locale", oneString, oneNameString,
"", new IllegalArgumentException());
assertIllegal("null action string", nullString, fiveNameStrings,
locale, new NullPointerException());
assertIllegal("empty action string", emptyString, fiveNameStrings,
locale, new IllegalArgumentException());
assertIllegal("null action name string", fiveStrings, nullString,
locale, new NullPointerException());
assertIllegal("empty action name string", fiveStrings, emptyString,
locale, new IllegalArgumentException());
assertIllegal("duplicate action string", dupString, fiveNameStrings,
locale, new IllegalArgumentException());
| void | test003()Test NullPointerException cases.
ActionNameMap map;
map = new ActionNameMap(oneString, oneNameString, locale);
try {
String a = map.getActionName(null);
fail("getActionName(null) must throw npe");
} catch (NullPointerException npe) {
assertNotNull("verify exception occurred", npe);
}
try {
String a = map.getAction(null);
fail("getActionName(null) must throw npe");
} catch (NullPointerException npe) {
assertNotNull("verify exception occurred", npe);
}
|
|