Prev: Last Call for Papers Reminder (extended): The World Congress on Engineering WCE 2010
Next: Cheap SMET T-Shirt men's,paypal payment
From: Rhino on 17 Mar 2010 23:39 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? -- Rhino --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Tom Anderson on 18 Mar 2010 17:52
On Thu, 18 Mar 2010, Rhino wrote: > 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 -- I need a proper outlet for my tendency towards analytical thought. -- Geneva Melzack |