### Question:
UnicodeEncoder { public static String encode (String string) { if (string == null) { return ""; } StringBuilder sb = null; char c; for (int i = 0; i < string.length (); ++i) { c = string.charAt(i); if (((int)c) >= 0x80) { if( sb == null ) { sb = new StringBuilder( string.length()+4 ); sb.append( string.substring(0,i) ); } sb.append("&#"); sb.append((int)c); sb.append(';'); } else if( sb != null ) { sb.append(c); } } return sb != null ? sb.toString() : string; }  static String encode(String string); static void encode(Writer writer, String string); static void encode(Writer writer, char[] cbuf, int off, int len); static void encode(Writer writer, String cbuf, int off, int len);  }### Answer:
@Test public void testUnicodeEncoder1() throws Exception { StringWriter sw = new StringWriter(40); UnicodeEncoder.encode(sw, ""+(char)0xE1); Assert.assertEquals(UnicodeEncoder.encode(""+(char)0xE1), sw.toString()); }
@Test public void testUnicodeEncoder2() throws Exception { StringWriter sw = new StringWriter(40); UnicodeEncoder.encode(sw, "h"+(char)0xE1); Assert.assertEquals(UnicodeEncoder.encode("h"+(char)0xE1), sw.toString()); }
@Test public void testUnicodeEncoder3() throws Exception { StringWriter sw = new StringWriter(40); UnicodeEncoder.encode(sw, ""+(char)0xE1+"a"); Assert.assertEquals(UnicodeEncoder.encode(""+(char)0xE1)+"a", sw.toString()); }
@Test public void testUnicodeEncoder4() throws Exception { StringWriter sw = new StringWriter(40); UnicodeEncoder.encode(sw, "hello h"+(char)0xE1+"aaa <p></p>"); Assert.assertEquals("hello h&#225;aaa <p></p>", sw.toString()); }