1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * 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 libcore.java.lang.annotation;
18
19import java.io.ByteArrayOutputStream;
20import java.io.NotSerializableException;
21import java.io.ObjectOutputStream;
22import java.lang.annotation.AnnotationTypeMismatchException;
23import java.lang.reflect.Method;
24
25public class AnnotationTypeMismatchExceptionTest extends junit.framework.TestCase {
26    public void testGetters() throws Exception {
27        Method m = String.class.getMethod("length");
28        AnnotationTypeMismatchException ex = new AnnotationTypeMismatchException(m, "poop");
29        assertSame(m, ex.element());
30        assertEquals("poop", ex.foundType());
31    }
32
33    public void testSerialization() throws Exception {
34        Method m = String.class.getMethod("length");
35        AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
36
37        ByteArrayOutputStream out = new ByteArrayOutputStream();
38        try {
39            // AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
40            // non-serializable field of type Method.
41            new ObjectOutputStream(out).writeObject(original);
42            fail();
43        } catch (NotSerializableException expected) {
44        }
45    }
46}
47