### Question:
UsesResourceBundle { public String getResourceString(String key) { if (isNull(bundle)) { Locale locale = getLocale(); if (isNotNull(locale)) { this.bundle = ResourceBundle.getBundle("SomeBundleName", locale); } else { handleError(); } } return bundle.getString(key); }  String getResourceString(String key);  }### Answer:
@Test public final void testGetResourceStringAndSucceed() { mockStatic(ResourceBundle.class); expect(ResourceBundle.getBundle("SomeBundleName", Locale.ENGLISH)).andReturn(bundle); final String key = "DUMMY"; final String message = "This is a Message"; expect(bundle.getString(key)).andReturn(message); replayAll(); String result = instance.getResourceString(key); verifyAll(); assertEquals(message, result); }
@Test(expected = MissingResourceException.class) public final void testGetResourceStringWithStringMissing() { mockStatic(ResourceBundle.class); expect(ResourceBundle.getBundle("SomeBundleName", Locale.ENGLISH)).andReturn(bundle); final String key = "DUMMY"; Exception e = new MissingResourceException(key, key, key); expect(bundle.getString(key)).andThrow(e); replayAll(); instance.getResourceString(key); }
@Test(expected = MissingResourceException.class) public final void testGetResourceStringWithBundleMissing() { mockStatic(ResourceBundle.class); final String key = "DUMMY"; Exception e = new MissingResourceException(key, key, key); expect(ResourceBundle.getBundle("SomeBundleName", Locale.ENGLISH)).andThrow(e); replayAll(); instance.getResourceString(key); }