OpenRemoteException extends Exception { protected static String format(String msg, Object... params) { try { return MessageFormat.format(msg, params); } catch (Throwable t) { return msg + " [EXCEPTION MESSAGE FORMATTING ERROR: " + t.getMessage().toUpperCase() + "]"; } } OpenRemoteException(String msg);  OpenRemoteException(String msg, Object... params);  OpenRemoteException(String msg, Throwable cause);  OpenRemoteException(String msg, Throwable cause, Object... params);   }
@Test public void testFormatting() { String msg = "some string"; String formattedMsg = OpenRemoteException.format(msg); Assert.assertTrue(formattedMsg.equals(msg)); }
@Test public void testParameterizedFormatting() { String msg = "some {0}"; String formattedMsg = OpenRemoteException.format(msg, "content"); Assert.assertTrue(formattedMsg.equals("some content")); }
@Test public void testFunkyFormatting() { String msg1 = "Test {0, date}, {1, integer, currency}"; String formattedMsg1 = OpenRemoteException.format(msg1, "foo", "bar"); Assert.assertTrue(formattedMsg1.startsWith(msg1 + " [EXCEPTION MESSAGE FORMATTING ERROR:")); String msg2 = "Test {0, foo}, {1, bar}"; String formattedMsg2 = OpenRemoteException.format(msg2, null, 1); Assert.assertTrue(formattedMsg2.startsWith(msg2 + " [EXCEPTION MESSAGE FORMATTING ERROR:")); String msg3 = "Test {0, number}, {1, number, percentage}"; String formattedMsg3 = OpenRemoteException.format(msg3, "foo", "bar"); Assert.assertTrue(formattedMsg3.startsWith(msg3 + " [EXCEPTION MESSAGE FORMATTING ERROR:")); }