@Test public void testEncodeNull() throws Exception { final StringEncoder encoder = this.getStringEncoder(); try { encoder.encode(null); } catch (final EncoderException ee) { // An exception should be thrown } }
public void checkEncoding(final String expected, final String source) throws EncoderException { Assert.assertEquals("Source: " + source, expected, this.getStringEncoder().encode(source)); }
@Test public void testEncodeWithInvalidObject() throws Exception { boolean exceptionThrown = false; try { final StringEncoder encoder = this.getStringEncoder(); encoder.encode(new Float(3.4)); } catch (final Exception e) { exceptionThrown = true; } Assert.assertTrue("An exception was not thrown when we tried to encode " + "a Float object", exceptionThrown); }
@Test public void testLocaleIndependence() throws Exception { final StringEncoder encoder = this.getStringEncoder(); final String[] data = {"I", "i",}; final Locale orig = Locale.getDefault(); final Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()}; try { for (final String element : data) { String ref = null; for (int j = 0; j < locales.length; j++) { Locale.setDefault(locales[j]); if (j <= 0) { ref = encoder.encode(element); } else { String cur = null; try { cur = encoder.encode(element); } catch (final Exception e) { Assert.fail(Locale.getDefault().toString() + ": " + e.getMessage()); } Assert.assertEquals(Locale.getDefault().toString() + ": ", ref, cur); } } } } finally { Locale.setDefault(orig); } }
@Test public void testEncodeEmpty() throws Exception { final Encoder encoder = this.getStringEncoder(); encoder.encode(""); encoder.encode(" "); encoder.encode("\t"); }