1 /* 2 * Copyright (C) 2008 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 17 package android.core; 18 19 import junit.framework.TestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 /** 23 * Tests basic behavior of enums. 24 */ 25 public class EnumTest extends TestCase { 26 enum MyEnum { isFour()27 ZERO, ONE, TWO, THREE, FOUR {boolean isFour() { 28 return true; 29 }}; 30 isFour()31 boolean isFour() { 32 return false; 33 } 34 } 35 36 enum MyEnumTwo { 37 FIVE, SIX 38 } 39 40 @SmallTest testEnum()41 public void testEnum() throws Exception { 42 assertTrue(MyEnum.ZERO.compareTo(MyEnum.ONE) < 0); 43 assertEquals(MyEnum.ZERO, MyEnum.ZERO); 44 assertTrue(MyEnum.TWO.compareTo(MyEnum.ONE) > 0); 45 assertTrue(MyEnum.FOUR.compareTo(MyEnum.ONE) > 0); 46 47 assertEquals("ONE", MyEnum.ONE.name()); 48 assertSame(MyEnum.ONE.getDeclaringClass(), MyEnum.class); 49 assertSame(MyEnum.FOUR.getDeclaringClass(), MyEnum.class); 50 51 assertTrue(MyEnum.FOUR.isFour()); 52 53 MyEnum e; 54 55 e = MyEnum.ZERO; 56 57 switch (e) { 58 case ZERO: 59 break; 60 default: 61 fail("wrong switch"); 62 } 63 } 64 } 65