EnumConstantNotPresentExceptionTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
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 17package org.apache.harmony.luni.tests.java.lang; 18 19import dalvik.annotation.TestTargets; 20import dalvik.annotation.TestLevel; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestTargetClass; 23 24import junit.framework.TestCase; 25 26@TestTargetClass(EnumConstantNotPresentException.class) 27public class EnumConstantNotPresentExceptionTest extends TestCase { 28 29 public enum Fixture { 30 ONE,TWO,THREE 31 } 32 33 /** 34 * @test java.lang.EnumConstantNotPresentException#EnumConstantNotPresentException(Class<? 35 * extends Enum>, String) 36 */ 37 @TestTargetNew( 38 level = TestLevel.COMPLETE, 39 notes = "", 40 method = "EnumConstantNotPresentException", 41 args = {java.lang.Class.class, java.lang.String.class} 42 ) 43 public void test_ConstructorLjava_lang_ClassLjava_lang_String() { 44 String tm = "Test Message"; 45 EnumConstantNotPresentException ecnpe = new 46 EnumConstantNotPresentException(Fixture.class, tm); 47 48 assertEquals("Constant name is incorrect: " + ecnpe.constantName() + 49 " instead of " + tm, tm, ecnpe.constantName()); 50 51 try { 52 new EnumConstantNotPresentException(null, ""); 53 fail("No NPE"); 54 } catch (NullPointerException e) { 55 } 56 } 57 58 /** 59 * @test java.lang.EnumConstantNotPresentException#enumType() 60 */ 61 @TestTargetNew( 62 level = TestLevel.COMPLETE, 63 notes = "", 64 method = "enumType", 65 args = {} 66 ) 67 public void test_enumType() { 68 EnumConstantNotPresentException e = new EnumConstantNotPresentException(Fixture.class, "FOUR"); 69 assertEquals(Fixture.class, e.enumType()); 70 } 71 72 /** 73 * @test java.lang.EnumConstantNotPresentException#constantName() 74 */ 75 @TestTargetNew( 76 level = TestLevel.COMPLETE, 77 notes = "", 78 method = "constantName", 79 args = {} 80 ) 81 public void test_constantName() { 82 EnumConstantNotPresentException e = new EnumConstantNotPresentException(Fixture.class, "FOUR"); 83 assertEquals("FOUR", e.constantName()); 84 } 85 86} 87