/*
 * Copyright (C) 2007 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.base;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;

import junit.framework.TestCase;

import java.nio.charset.Charset;

/**
 * Unit test for {@link Charsets}.
 *
 * @author Mike Bostock
 */
@GwtCompatible(emulated = true)
public class CharsetsTest extends TestCase {

  @GwtIncompatible("Non-UTF-8 Charset")
  public void testUsAscii() {
    assertEquals(Charset.forName("US-ASCII"), Charsets.US_ASCII);
  }

  @GwtIncompatible("Non-UTF-8 Charset")
  public void testIso88591() {
    assertEquals(Charset.forName("ISO-8859-1"), Charsets.ISO_8859_1);
  }

  public void testUtf8() {
    assertEquals(Charset.forName("UTF-8"), Charsets.UTF_8);
  }

  @GwtIncompatible("Non-UTF-8 Charset")
  public void testUtf16be() {
    assertEquals(Charset.forName("UTF-16BE"), Charsets.UTF_16BE);
  }

  @GwtIncompatible("Non-UTF-8 Charset")
  public void testUtf16le() {
    assertEquals(Charset.forName("UTF-16LE"), Charsets.UTF_16LE);
  }

  @GwtIncompatible("Non-UTF-8 Charset")
  public void testUtf16() {
    assertEquals(Charset.forName("UTF-16"), Charsets.UTF_16);
  }
}

@@ -801,16 +801,41 @@
 Charset;
+%0Aimport java.util.Arrays;
 %0A%0A/**%0A *
@@ -1770,11 +1770,581 @@
 16);%0A  %7D
+%0A%0A  @GwtIncompatible(%22Non-UTF-8 Charset%22)%0A  public void testWhyUsAsciiIsDangerous() %7B%0A    byte%5B%5D b1 = %22%E6%9C%9D%E6%97%A5%E6%96%B0%E8%81%9E%22.getBytes(Charsets.US_ASCII);%0A    byte%5B%5D b2 = %22%E8%81%9E%E6%9C%9D%E6%97%A5%E6%96%B0%22.getBytes(Charsets.US_ASCII);%0A    byte%5B%5D b3 = %22????%22.getBytes(Charsets.US_ASCII);%0A    byte%5B%5D b4 = %22%E3%83%8B%E3%83%A5%E3%83%BC%E3%82%B9%22.getBytes(Charsets.US_ASCII);%0A    byte%5B%5D b5 = %22%E3%82%B9%E3%83%A5%E3%83%BC%E3%83%BC%22.getBytes(Charsets.US_ASCII);%0A    // Assert they are all equal (using the transitive property)%0A    assertTrue(Arrays.equals(b1, b2));%0A    assertTrue(Arrays.equals(b2, b3));%0A    assertTrue(Arrays.equals(b3, b4));%0A    assertTrue(Arrays.equals(b4, b5));%0A  %7D
 %0A%7D%0A

Add a simple test that shows why US_ASCII is usually a bad choice. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=41853734