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;
18
19import junit.framework.TestCase;
20import libcore.util.SerializationTester;
21
22public final class EnumTest extends TestCase {
23    public void testEnumSerialization() {
24        String s = "aced00057e7200236c6962636f72652e6a6176612e6c616e672e456e756d5465"
25                + "737424526f7368616d626f00000000000000001200007872000e6a6176612e6c6"
26                + "16e672e456e756d000000000000000012000078707400055041504552";
27        Roshambo value = Roshambo.PAPER;
28        assertTrue(value.getClass() == Roshambo.class);
29        new SerializationTester<Roshambo>(value, s).test();
30    }
31
32    public void testEnumSubclassSerialization() {
33        String s = "aced00057e7200236c6962636f72652e6a6176612e6c616e672e456e756d5465"
34                + "737424526f7368616d626f00000000000000001200007872000e6a6176612e6c6"
35                + "16e672e456e756d00000000000000001200007870740004524f434b";
36        Roshambo value = Roshambo.ROCK;
37        assertTrue(value.getClass() != Roshambo.class);
38        new SerializationTester<Roshambo>(value, s).test();
39    }
40
41    enum Roshambo {
42        ROCK {
43            @Override public String toString() {
44                return "rock!";
45            }
46        },
47        PAPER,
48        SCISSORS
49    }
50}
51