JUnit Test case?

R

Rhino

I'm trying to figure out how to write a test case for this code. The code
is pretty simple but I can't think of a way to test it with JUnit3.

Here's the code:
--------------------------------------------------------------------

public ResourceBundle getResources(Locale currentLocale, String
listBase) {

final String METHOD_NAME = "getResources()"; //$NON-NLS-1$

ResourceBundle locList = null;

/* Get the list resource bundle for the current locale. */
try {
locList = ResourceBundle.getBundle(listBase, currentLocale);
} catch (MissingResourceException mr_excp) {
Object[] msgArgs = {CLASS_NAME, METHOD_NAME, listBase,
currentLocale.toString(), mr_excp};
msgFmt.applyPattern(locMsg.getString("msg011")); //$NON-
NLS-1$
throw new IllegalArgumentException(msgFmt.format(msgArgs));
}

return (locList);
}
----------------------------------------------------------------------

If the method returned a null ResourceBundle, that would be relatively easy
to test for. But if it doesn't find the "listBase" value, it will simply
find the next best fit, assuming there is a reasonable alternative and
therefore not return null.

Any suggestions?
 
T

Tom Anderson

I'm trying to figure out how to write a test case for this code. The code
is pretty simple but I can't think of a way to test it with JUnit3.

Here's the code:
--------------------------------------------------------------------

public ResourceBundle getResources(Locale currentLocale, String
listBase) {

final String METHOD_NAME = "getResources()"; //$NON-NLS-1$

ResourceBundle locList = null;

/* Get the list resource bundle for the current locale. */
try {
locList = ResourceBundle.getBundle(listBase, currentLocale);
} catch (MissingResourceException mr_excp) {
Object[] msgArgs = {CLASS_NAME, METHOD_NAME, listBase,
currentLocale.toString(), mr_excp};
msgFmt.applyPattern(locMsg.getString("msg011")); //$NON-
NLS-1$
throw new IllegalArgumentException(msgFmt.format(msgArgs));
}

return (locList);
}
----------------------------------------------------------------------

If the method returned a null ResourceBundle, that would be relatively easy
to test for. But if it doesn't find the "listBase" value, it will simply
find the next best fit, assuming there is a reasonable alternative and
therefore not return null.

Any suggestions?

Think about what you want the method to do - what success really means -
then write code to test those criteria. I don't really understand what
this method is trying to do, but maybe you could look at the returned
bundle and check that it has the right values in?

tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top