View Javadoc

1   /*
2    *  jDTAUS Banking Charset Providers
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.banking.charsets.spi.test;
22  
23  import junit.framework.Assert;
24  import junit.framework.TestCase;
25  import org.jdtaus.core.nio.util.Charsets;
26  
27  /**
28   * Tests the {@code Charsets} implementation.
29   *
30   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31   * @version $JDTAUS: CharsetsTest.java 8661 2012-09-27 11:29:58Z schulte $
32   */
33  public class CharsetsTest extends TestCase
34  {
35      //--Tests-------------------------------------------------------------------
36  
37      private static final String ASCII = "@[\\]{|}~";
38  
39      private static final String ISO646DE = "§ÄÖÜäöüß";
40  
41      public void testISO646DE() throws Exception
42      {
43          byte[] encoded = Charsets.encode( ISO646DE, "ISO646-DE" );
44          String decoded = Charsets.decode( encoded, "ISO646-DE" );
45          Assert.assertEquals( ISO646DE, decoded );
46  
47          encoded = Charsets.encode( ASCII, "ISO646-DE" );
48          decoded = Charsets.decode( encoded, "ISO646-DE" );
49          Assert.assertEquals( "????????", decoded );
50  
51          encoded = ISO646DE.getBytes( "ISO646-DE" );
52          decoded = new String( encoded, "ISO646-DE" );
53          Assert.assertEquals( ISO646DE, decoded );
54  
55          encoded = ASCII.getBytes( "ISO646-DE" );
56          decoded = new String( encoded, "ISO646-DE" );
57          Assert.assertEquals( "????????", decoded );
58      }
59  
60      public void testIBM273() throws Exception
61      {
62          byte[] encoded = Charsets.encode( ISO646DE, "IBM273" );
63          String decoded = Charsets.decode( encoded, "IBM273" );
64          Assert.assertEquals( ISO646DE, decoded );
65  
66          encoded = Charsets.encode( ASCII, "IBM273" );
67          decoded = Charsets.decode( encoded, "IBM273" );
68          Assert.assertEquals( ASCII, decoded );
69  
70          encoded = ISO646DE.getBytes( "IBM273" );
71          decoded = new String( encoded, "IBM273" );
72          Assert.assertEquals( ISO646DE, decoded );
73  
74          encoded = ASCII.getBytes( "IBM273" );
75          decoded = new String( encoded, "IBM273" );
76          Assert.assertEquals( ASCII, decoded );
77      }
78  
79      //-------------------------------------------------------------------Tests--
80  }