Home | History | Annotate | Download | only in util
      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 
     17 package org.apache.harmony.tests.java.util;
     18 
     19 import java.io.Serializable;
     20 import java.util.UnknownFormatFlagsException;
     21 
     22 import junit.framework.TestCase;
     23 
     24 import org.apache.harmony.testframework.serialization.SerializationTest;
     25 import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
     26 
     27 public class UnknownFormatFlagsExceptionTest extends TestCase {
     28 
     29     /**
     30      * java.util.UnknownFormatFlagsException#UnknownFormatFlagsException(String)
     31      */
     32     public void test_unknownFormatFlagsException() {
     33 
     34         try {
     35             new UnknownFormatFlagsException(null);
     36             fail("should throw NullPointerExcepiton");
     37         } catch (NullPointerException e) {
     38             // expected
     39         }
     40     }
     41 
     42     /**
     43      * java.util.UnknownFormatFlagsException#getFlags()
     44      */
     45     public void test_getFlags() {
     46         String s = "MYTESTSTRING";
     47         UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
     48                 s);
     49         assertEquals(s, UnknownFormatFlagsException.getFlags());
     50     }
     51 
     52     /**
     53      * java.util.UnknownFormatFlagsException#getMessage()
     54      */
     55     public void test_getMessage() {
     56         String s = "MYTESTSTRING";
     57         UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
     58                 s);
     59         assertNotNull(UnknownFormatFlagsException.getMessage());
     60     }
     61 
     62     // comparator for comparing UnknownFormatFlagsException objects
     63     private static final SerializableAssert exComparator = new SerializableAssert() {
     64         public void assertDeserialized(Serializable initial,
     65                 Serializable deserialized) {
     66 
     67             SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
     68                     deserialized);
     69 
     70             UnknownFormatFlagsException initEx = (UnknownFormatFlagsException) initial;
     71             UnknownFormatFlagsException desrEx = (UnknownFormatFlagsException) deserialized;
     72 
     73             assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
     74         }
     75     };
     76 
     77     /**
     78      * serialization/deserialization.
     79      */
     80     public void testSerializationSelf() throws Exception {
     81 
     82         SerializationTest.verifySelf(new UnknownFormatFlagsException(
     83                 "MYTESTSTRING"), exComparator);
     84     }
     85 
     86     /**
     87      * serialization/deserialization compatibility with RI.
     88      */
     89     public void testSerializationCompatibility() throws Exception {
     90 
     91         SerializationTest.verifyGolden(this, new UnknownFormatFlagsException(
     92                 "MYTESTSTRING"), exComparator);
     93     }
     94 }
     95