IllegalFormatPrecisionExceptionTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.apache.harmony.luni.tests.java.util; 17 18import java.io.Serializable; 19import java.util.IllegalFormatPrecisionException; 20 21import junit.framework.TestCase; 22 23import org.apache.harmony.testframework.serialization.SerializationTest; 24import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 25 26public class IllegalFormatPrecisionExceptionTest extends TestCase { 27 28 /** 29 * @tests java.util.IllegalFormatPrecisionException#IllegalFormatPrecisionException(int) 30 */ 31 public void test_illegalFormatPrecisionException() { 32 IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException( 33 Integer.MIN_VALUE); 34 assertEquals(Integer.MIN_VALUE, illegalFormatPrecisionException 35 .getPrecision()); 36 } 37 38 /** 39 * @tests java.util.IllegalFormatPrecisionException#getPrecision() 40 */ 41 public void test_getPrecision() { 42 int precision = 12345; 43 IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException( 44 precision); 45 assertEquals(precision, illegalFormatPrecisionException.getPrecision()); 46 } 47 48 /** 49 * @tests method for 'java.util.IllegalFormatPrecisionException#getMessage() 50 */ 51 public void test_getMessage() { 52 int precision = 12345; 53 IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException( 54 precision); 55 assertTrue(null != illegalFormatPrecisionException.getMessage()); 56 57 } 58 59 // comparator for IllegalFormatPrecisionException objects 60 private static final SerializableAssert exComparator = new SerializableAssert() { 61 public void assertDeserialized(Serializable initial, 62 Serializable deserialized) { 63 64 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 65 deserialized); 66 67 IllegalFormatPrecisionException initEx = (IllegalFormatPrecisionException) initial; 68 IllegalFormatPrecisionException desrEx = (IllegalFormatPrecisionException) deserialized; 69 70 assertEquals("Precision", initEx.getPrecision(), desrEx 71 .getPrecision()); 72 } 73 }; 74 75 /** 76 * @tests serialization/deserialization. 77 */ 78 public void testSerializationSelf() throws Exception { 79 80 SerializationTest.verifySelf( 81 new IllegalFormatPrecisionException(12345), exComparator); 82 } 83 84 /** 85 * @tests serialization/deserialization compatibility with RI. 86 */ 87 public void testSerializationCompatibility() throws Exception { 88 89 SerializationTest.verifyGolden(this, 90 new IllegalFormatPrecisionException(12345), exComparator); 91 } 92} 93