blob: 6ca0276a5a0755c2b1211b9c29a8bb688ea0db43 [file] [log] [blame]
The Android Open Source Project0eec4642012-04-01 00:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package libcore.java.text;
18
19import java.io.ByteArrayInputStream;
20import java.io.ByteArrayOutputStream;
21import java.io.IOException;
22import java.io.InvalidObjectException;
23import java.io.ObjectInputStream;
24import java.io.ObjectOutputStream;
25import java.text.NumberFormat;
26
27public class OldNumberFormatFieldTest extends junit.framework.TestCase {
28
29 public void test_ConstructorLjava_lang_String() {
30 // protected constructor
31 String name = "new number format";
32 MyNumberFormat field = new MyNumberFormat(name);
33 assertEquals("field has wrong name", name, field.getName());
34
35 field = new MyNumberFormat(null);
36 assertEquals("field has wrong name", null, field.getName());
37 }
38
39 public void test_readResolve() throws IOException, ClassNotFoundException {
40 // test for method java.lang.Object readResolve()
41
42 // see serialization stress tests:
43 // implemented in
44 // SerializationStressTest4.test_writeObject_NumberFormat_Field()
45 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
46 ObjectOutputStream out = new ObjectOutputStream(bytes);
47
48 MyNumberFormat field;
49
50 NumberFormat.Field nfield = NumberFormat.Field.CURRENCY;
51
52 field = new MyNumberFormat(null);
53
54 out.writeObject(nfield);
55 out.writeObject(field);
56
57 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
58 NumberFormat.Field nfield2 = (NumberFormat.Field) in.readObject();
59 assertSame("resolved incorrectly", nfield, nfield2);
60
61 try {
62 in.readObject();
63 fail("Expected InvalidObjectException for subclass instance with null name");
64 } catch (InvalidObjectException e) {
65 }
66
67 in.close();
68 out.close();
69 }
70
71 static class MyNumberFormat extends NumberFormat.Field {
72 static final long serialVersionUID = 1L;
73
74 static boolean flag = false;
75
76 protected MyNumberFormat(String attr) {
77 super(attr);
78 }
79
80 protected String getName() {
81 return super.getName();
82 }
83 }
84}