FormatFlagsConversionMismatchExceptionTest.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
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 */ 16 17package org.apache.harmony.luni.tests.java.util; 18 19import dalvik.annotation.TestTargets; 20import dalvik.annotation.TestLevel; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestTargetClass; 23 24import junit.framework.TestCase; 25 26import java.io.Serializable; 27import java.util.FormatFlagsConversionMismatchException; 28 29import org.apache.harmony.testframework.serialization.SerializationTest; 30import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 31 32@TestTargetClass(FormatFlagsConversionMismatchException.class) 33public class FormatFlagsConversionMismatchExceptionTest extends TestCase { 34 35 /** 36 * @tests java.util.FormatFlagsConversionMismatchException#FormatFlagsConversionMismatchException(String, 37 * char) 38 */ 39 @TestTargetNew( 40 level = TestLevel.COMPLETE, 41 notes = "Verifies NullPointerException.", 42 method = "FormatFlagsConversionMismatchException", 43 args = {java.lang.String.class, char.class} 44 ) 45 public void test_formatFlagsConversionMismatchException() { 46 try { 47 new FormatFlagsConversionMismatchException(null, ' '); 48 fail("should throw NullPointerException."); 49 } catch (NullPointerException e) { 50 // expected 51 } 52 53 assertNotNull(new FormatFlagsConversionMismatchException("String", ' ')); 54 } 55 56 /** 57 * @tests java.util.FormatFlagsConversionMismatchException#getFlags() 58 */ 59 @TestTargetNew( 60 level = TestLevel.COMPLETE, 61 notes = "", 62 method = "getFlags", 63 args = {} 64 ) 65 public void test_getFlags() { 66 String flags = "MYTESTFLAGS"; 67 char conversion = 'T'; 68 FormatFlagsConversionMismatchException formatFlagsConversionMismatchException = new FormatFlagsConversionMismatchException( 69 flags, conversion); 70 assertEquals(flags, formatFlagsConversionMismatchException.getFlags()); 71 } 72 73 /** 74 * @tests java.util.FormatFlagsConversionMismatchException#getConversion() 75 */ 76 @TestTargetNew( 77 level = TestLevel.COMPLETE, 78 notes = "", 79 method = "getConversion", 80 args = {} 81 ) 82 public void test_getConversion() { 83 String flags = "MYTESTFLAGS"; 84 char conversion = 'T'; 85 FormatFlagsConversionMismatchException 86 formatFlagsConversionMismatchException = 87 new FormatFlagsConversionMismatchException( 88 flags, conversion); 89 assertEquals(conversion, formatFlagsConversionMismatchException 90 .getConversion()); 91 92 } 93 94 /** 95 * @tests java.util.FormatFlagsConversionMismatchException#getMessage() 96 */ 97 @TestTargetNew( 98 level = TestLevel.COMPLETE, 99 notes = "", 100 method = "getMessage", 101 args = {} 102 ) 103 public void test_getMessage() { 104 String flags = "MYTESTFLAGS"; 105 char conversion = 'T'; 106 FormatFlagsConversionMismatchException formatFlagsConversionMismatchException = new FormatFlagsConversionMismatchException( 107 flags, conversion); 108 assertTrue(null != formatFlagsConversionMismatchException.getMessage()); 109 110 } 111 112 // comparator for FormatFlagsConversionMismatchException objects 113 private static final SerializableAssert exComparator = new SerializableAssert() { 114 public void assertDeserialized(Serializable initial, 115 Serializable deserialized) { 116 117 SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, 118 deserialized); 119 120 FormatFlagsConversionMismatchException initEx = (FormatFlagsConversionMismatchException) initial; 121 FormatFlagsConversionMismatchException desrEx = (FormatFlagsConversionMismatchException) deserialized; 122 123 assertEquals("Flags", initEx.getFlags(), desrEx.getFlags()); 124 assertEquals("Conversion", initEx.getConversion(), desrEx 125 .getConversion()); 126 } 127 }; 128 129 /** 130 * @tests serialization/deserialization. 131 */ 132 @TestTargetNew( 133 level = TestLevel.COMPLETE, 134 notes = "", 135 method = "!SerializationSelf", 136 args = {} 137 ) 138 public void testSerializationSelf() throws Exception { 139 140 SerializationTest.verifySelf( 141 new FormatFlagsConversionMismatchException("MYTESTFLAGS", 'T'), 142 exComparator); 143 } 144 145 /** 146 * @tests serialization/deserialization compatibility with RI. 147 */ 148 @TestTargetNew( 149 level = TestLevel.COMPLETE, 150 notes = "", 151 method = "!SerializationGolden", 152 args = {} 153 ) 154 public void testSerializationCompatibility() throws Exception { 155 156 SerializationTest.verifyGolden(this, 157 new FormatFlagsConversionMismatchException("MYTESTFLAGS", 'T'), 158 exComparator); 159 } 160} 161