FileDocCategorySizeDatePackage
TestActionNameMap.javaAPI DocphoneME MR2 API (J2ME)6640Wed May 02 18:00:44 BST 2007com.sun.midp.content

TestActionNameMap

public class TestActionNameMap extends ExtendedTestCase
Tests for creation of ActionNameMaps.

Fields Summary
static final String
locale
Valid locale.
static final String[]
zeroStrings
Empty string arrays.
static final String[]
oneString
Length 1 string array.
static final String[]
oneNameString
Length 1 name string array.
static final String[]
fiveStrings
Length 5 string array.
static final String[]
fiveNameStrings
Length 5 names string array.
static final String[]
nullString
String array containing a null.
static final String[]
emptyString
String array containing an empty string.
static final String[]
dupString
String array containing a duplicate string.
Constructors Summary
Methods Summary
voidassertIllegal(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.

param
message the message for the errors
param
actions the array of actions
param
actionnames the array of actionnames
param
locale the locale
param
expected the expected exception

	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());
	}
    
voidassertLegal(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.

param
message the message for the errors
param
actions the array of actions
param
actionnames the array of actionnames
param
locale the locale

	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 voidrunTests()
Run the tests of the Listener.

 

               
       
	test001();
	test002();
	test003();
    
private voidtest001()
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 voidtest002()
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());
    
voidtest003()
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);
	}