View Javadoc

1   /*
2    * Copyright 2011 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.myfaces.shared.renderkit.html.util;
17  
18  import java.io.StringWriter;
19  import junit.framework.Assert;
20  import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
21  import org.junit.Test;
22  
23  public class UnicodeEncoderTest extends AbstractJsfTestCase
24  {
25  
26      @Test
27      public void testUnicodeEncoder1() throws Exception
28      {
29          StringWriter sw = new StringWriter(40);
30          UnicodeEncoder.encode(sw, ""+(char)0xE1);
31          Assert.assertEquals(UnicodeEncoder.encode(""+(char)0xE1), sw.toString());
32      }
33      
34      @Test
35      public void testUnicodeEncoder2() throws Exception
36      {
37          StringWriter sw = new StringWriter(40);
38          UnicodeEncoder.encode(sw, "h"+(char)0xE1);
39          Assert.assertEquals(UnicodeEncoder.encode("h"+(char)0xE1), sw.toString());
40      }
41      
42      @Test
43      public void testUnicodeEncoder3() throws Exception
44      {
45          StringWriter sw = new StringWriter(40);
46          UnicodeEncoder.encode(sw, ""+(char)0xE1+"a");
47          Assert.assertEquals(UnicodeEncoder.encode(""+(char)0xE1)+"a", sw.toString());
48      }
49      
50      @Test
51      public void testUnicodeEncoder4() throws Exception
52      {
53          StringWriter sw = new StringWriter(40);
54          UnicodeEncoder.encode(sw, "hello h"+(char)0xE1+"aaa <p></p>");
55          Assert.assertEquals("hello h&#225;aaa <p></p>", sw.toString());
56      }
57  
58  }