001/* 002 * jDTAUS Core Utilities 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.nio.util.test; 022 023import junit.framework.Assert; 024import junit.framework.TestCase; 025import org.jdtaus.core.nio.util.Charsets; 026 027/** 028 * Testcase for {@code Charsets} utility. 029 * 030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 031 * @version $JDTAUS: CharsetsTest.java 8709 2012-10-02 21:07:40Z schulte $ 032 */ 033public class CharsetsTest extends TestCase 034{ 035 //--Tests------------------------------------------------------------------- 036 037 /** String used for testing. */ 038 private static final String TEST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 039 040 /** 041 * Tests the {@link Charsets#decode(byte[],String)} and 042 * {@link Charsets#encode(String,String)} methods to support the US-ASCII, 043 * UTF-8 and UTF-16 charsets. 044 */ 045 public void testPlatformCharsets() throws Exception 046 { 047 final byte[] ascii = Charsets.encode( TEST, "US-ASCII" ); 048 final byte[] utf8 = Charsets.encode( TEST, "UTF-8" ); 049 final byte[] utf16 = Charsets.encode( TEST, "UTF-16" ); 050 051 final String asciiDecoded = Charsets.decode( ascii, "US-ASCII" ); 052 final String utf8Decoded = Charsets.decode( utf8, "UTF-8" ); 053 final String utf16Decoded = Charsets.decode( utf16, "UTF-16" ); 054 055 Assert.assertEquals( TEST.length(), ascii.length ); 056 Assert.assertEquals( TEST.length(), utf8.length ); 057 058 Assert.assertEquals( TEST, asciiDecoded ); 059 Assert.assertEquals( TEST, utf8Decoded ); 060 Assert.assertEquals( TEST, utf16Decoded ); 061 } 062 063 //-------------------------------------------------------------------Tests-- 064}