156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more 256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * contributor license agreements. See the NOTICE file distributed with 356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * this work for additional information regarding copyright ownership. 456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * (the "License"); you may not use this file except in compliance with 656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * the License. You may obtain a copy of the License at 756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 1056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Unless required by applicable law or agreed to in writing, software 1156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * See the License for the specific language governing permissions and 1456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * limitations under the License. 1556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 1656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 17e5fea3d504609d22337a5311d3ce0e72314bceeeNarayan Kamathpackage org.apache.harmony.tests.java.nio.charset; 1856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 1956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.io.Serializable; 2056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.charset.IllegalCharsetNameException; 2156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport junit.framework.TestCase; 2356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport org.apache.harmony.testframework.serialization.SerializationTest; 2556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 2656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/** 2856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test class IllegalCharsetNameException. 2956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughespublic class IllegalCharsetNameExceptionTest extends TestCase { 3156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 3256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testConstructor() { 3356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes IllegalCharsetNameException ex = new IllegalCharsetNameException( 3456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes "impossible"); 3556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(ex instanceof IllegalArgumentException); 3656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNull(ex.getCause()); 3756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(ex.getCharsetName(), "impossible"); 3856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(ex.getMessage().indexOf("impossible") != -1); 3956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ex = new IllegalCharsetNameException("ascii"); 4156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNull(ex.getCause()); 4256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(ex.getCharsetName(), "ascii"); 4356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(ex.getMessage().indexOf("ascii") != -1); 4456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ex = new IllegalCharsetNameException(""); 4656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNull(ex.getCause()); 4756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(ex.getCharsetName(), ""); 4856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ex.getMessage(); 4956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ex = new IllegalCharsetNameException(null); 5156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNull(ex.getCause()); 5256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNull(ex.getCharsetName()); 5356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(ex.getMessage().indexOf("null") != -1); 5456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 5656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // comparator for IllegalCharsetNameException objects 5856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes private static final SerializableAssert COMPARATOR = new SerializableAssert() { 5956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void assertDeserialized(Serializable initial, 6056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes Serializable deserialized) { 6156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 6256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // FIXME?: getMessage() returns more helpful string but 6356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // this leads to incompatible message in serial form 6456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // 6556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // do common checks for all throwable objects 6656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 6756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // deserialized); 6856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 6956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes IllegalCharsetNameException initEx = (IllegalCharsetNameException) initial; 7056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes IllegalCharsetNameException desrEx = (IllegalCharsetNameException) deserialized; 7156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 7256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals("CharsetName", initEx.getCharsetName(), desrEx 7356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .getCharsetName()); 7456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 7556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes }; 7656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 7756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 7856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @tests serialization/deserialization compatibility. 7956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 8056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testSerializationSelf() throws Exception { 8156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 8256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes SerializationTest.verifySelf(new IllegalCharsetNameException( 8356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes "charsetName"), COMPARATOR); 8456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 8556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 8656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 8756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @tests serialization/deserialization compatibility with RI. 8856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 8956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testSerializationCompatibility() throws Exception { 9056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 9156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes SerializationTest.verifyGolden(this, new IllegalCharsetNameException( 9256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes "charsetName"), COMPARATOR); 9356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 9456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes} 95