001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.codec; 019 020 import java.nio.charset.Charset; 021 022 import junit.framework.Assert; 023 024 import org.junit.Test; 025 026 /** 027 * Sanity checks for {@link Charsets}. 028 * 029 * @version $Id: CharsetsTest.html 889935 2013-12-11 05:05:13Z ggregory $ 030 */ 031 public class CharsetsTest { 032 033 @Test 034 public void testToCharset() { 035 Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null)); 036 Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null)); 037 Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset())); 038 Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8"))); 039 } 040 041 @Test 042 public void testIso8859_1() { 043 Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name()); 044 } 045 046 @Test 047 public void testUsAscii() { 048 Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name()); 049 } 050 051 @Test 052 public void testUtf16() { 053 Assert.assertEquals("UTF-16", Charsets.UTF_16.name()); 054 } 055 056 @Test 057 public void testUtf16Be() { 058 Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name()); 059 } 060 061 @Test 062 public void testUtf16Le() { 063 Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name()); 064 } 065 066 @Test 067 public void testUtf8() { 068 Assert.assertEquals("UTF-8", Charsets.UTF_8.name()); 069 } 070 071 }