Code example for StringTokenizer

Methods: nextElement

0
	 * @tests java.util.StringTokenizer#nextElement() 
	 */ 
	public void test_nextElement() { 
		// Test for method java.lang.Object 
		// java.util.StringTokenizer.nextElement() 
		StringTokenizer st = new StringTokenizer("This is a test String");
		assertEquals("nextElement returned incorrect value", "This", ((String) st
				.nextElement()));
		assertEquals("nextElement returned incorrect value", "is", ((String) st
				.nextElement()));
		assertEquals("nextElement returned incorrect value", "a", ((String) st
				.nextElement()));
		assertEquals("nextElement returned incorrect value", "test", ((String) st
				.nextElement()));
		assertEquals("nextElement returned incorrect value", "String", ((String) st
				.nextElement()));
		try { 
			st.nextElement();
			fail(
					"nextElement failed to throw a NoSuchElementException when it should have been out of elements"); 
		} catch (NoSuchElementException e) {
			return; 
		}