public void testPreloadedCharsets() { Charsets.preloadAllCharsets(); try { Charsets.lookupCharset("NON-EXISTED-CHARSET"); } catch (UnsupportedCharsetException e) { StackTraceElement[] elements = e.getStackTrace(); assertEquals("Exception is not thrown from Charsets class", elements[0].getClassName(), Charsets.class.getName()); } Charsets.drainAllCharsets(); try { Charsets.lookupCharset("NON-EXISTED-CHARSET"); } catch (UnsupportedCharsetException e) { StackTraceElement[] elements = e.getStackTrace(); assertFalse("Exception is unexpectedly thrown from Charsets class", elements[0].getClassName().equals(Charsets.class.getName())); } } }