1/* 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 */ 17 18package tests.api.java.util; 19 20import dalvik.annotation.TestTargetNew; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetClass; 24 25import java.util.NoSuchElementException; 26import java.util.Vector; 27 28@TestTargetClass(NoSuchElementException.class) 29public class NoSuchElementExceptionTest extends junit.framework.TestCase { 30 31 /** 32 * @tests java.util.NoSuchElementException#NoSuchElementException() 33 */ 34 @TestTargetNew( 35 level = TestLevel.COMPLETE, 36 notes = "", 37 method = "NoSuchElementException", 38 args = {} 39 ) 40 public void test_Constructor() { 41 // Test for method java.util.NoSuchElementException() 42 43 assertNotNull(new NoSuchElementException()); 44 45 try { 46 Vector v = new Vector(); 47 v.elements().nextElement(); 48 fail("NoSuchElementException expected"); 49 } catch (NoSuchElementException e) { 50 //expected 51 } 52 } 53 54 /** 55 * @tests java.util.NoSuchElementException#NoSuchElementException(java.lang.String) 56 */ 57 @TestTargetNew( 58 level = TestLevel.COMPLETE, 59 notes = "", 60 method = "NoSuchElementException", 61 args = {java.lang.String.class} 62 ) 63 public void test_ConstructorLjava_lang_String() { 64 // Test for method java.util.NoSuchElementException(java.lang.String) 65 66 assertNotNull(new NoSuchElementException("String")); 67 assertNotNull(new NoSuchElementException(null)); 68 69 try { 70 Vector v = new Vector(); 71 v.firstElement(); 72 fail("NoSuchElementException expected"); 73 } catch (NoSuchElementException e) { 74 //expected 75 } 76 } 77 78 /** 79 * Sets up the fixture, for example, open a network connection. This method 80 * is called before a test is executed. 81 */ 82 protected void setUp() { 83 } 84 85 /** 86 * Tears down the fixture, for example, close a network connection. This 87 * method is called after a test is executed. 88 */ 89 protected void tearDown() { 90 } 91} 92