Search in sources :

Example 31 with NoSuchElementException

use of java.util.NoSuchElementException in project j2objc by google.

the class VectorTest method test_firstElement.

/**
	 * @tests java.util.Vector#firstElement()
	 */
public void test_firstElement() {
    // Test for method java.lang.Object java.util.Vector.firstElement()
    assertEquals("Returned incorrect firstElement", "Test 0", tVector.firstElement());
    tVector.insertElementAt(null, 0);
    assertNull("Returned incorrect firstElement--wanted null", tVector.firstElement());
    Vector v = new Vector();
    try {
        v.firstElement();
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Excepted
    }
}
Also used : Vector(java.util.Vector) NoSuchElementException(java.util.NoSuchElementException)

Example 32 with NoSuchElementException

use of java.util.NoSuchElementException in project j2objc by google.

the class StringTokenizerTest method test_nextElement.

/**
	 * @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;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) NoSuchElementException(java.util.NoSuchElementException)

Example 33 with NoSuchElementException

use of java.util.NoSuchElementException in project j2objc by google.

the class StringTokenizerTest method test_nextToken.

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

Example 34 with NoSuchElementException

use of java.util.NoSuchElementException in project j2objc by google.

the class VectorTest method test_lastElement.

/**
	 * @tests java.util.Vector#isEmpty()
	 */
/* TODO(tball): enable when threading is supported.
	public void test_isEmpty_subtest0() {
		final Vector v = new Vector();
		v.addElement("initial");
		Thread t1 = new Thread() {
			public void run() {
				while (!v.isEmpty())
					;
				v.addElement("final");
			}
		};
		t1.start();
		for (int i = 0; i < 10000; i++) {
			synchronized (v) {
				v.removeElementAt(0);
				v.addElement(String.valueOf(i));
			}
			int size;
			if ((size = v.size()) != 1) {
				String result = "Size is not 1: " + size + " " + v;
				// terminate the thread
				v.removeAllElements();
				fail(result);
			}
		}
		// terminate the thread
		v.removeElementAt(0);
	}
	*/
/**
	 * @tests java.util.Vector#lastElement()
	 */
public void test_lastElement() {
    // Test for method java.lang.Object java.util.Vector.lastElement()
    assertEquals("Incorrect last element returned", "Test 99", tVector.lastElement());
    tVector.addElement(null);
    assertNull("Incorrect last element returned--wanted null", tVector.lastElement());
    Vector vector = new Vector();
    try {
        vector.lastElement();
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Excepted
    }
}
Also used : Vector(java.util.Vector) NoSuchElementException(java.util.NoSuchElementException)

Example 35 with NoSuchElementException

use of java.util.NoSuchElementException in project okhttp by square.

the class RouteSelectorTest method singleRouteReturnsFailedRoute.

@Test
public void singleRouteReturnsFailedRoute() throws Exception {
    Address address = httpAddress();
    RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
    assertTrue(routeSelector.hasNext());
    dns.set(uriHost, dns.allocate(1));
    Route route = routeSelector.next();
    routeDatabase.failed(route);
    routeSelector = new RouteSelector(address, routeDatabase);
    assertRoute(routeSelector.next(), address, NO_PROXY, dns.lookup(uriHost, 0), uriPort);
    assertFalse(routeSelector.hasNext());
    try {
        routeSelector.next();
        fail();
    } catch (NoSuchElementException expected) {
    }
}
Also used : SocketAddress(java.net.SocketAddress) Address(okhttp3.Address) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) Route(okhttp3.Route) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)720 Iterator (java.util.Iterator)122 Test (org.junit.Test)61 Scanner (java.util.Scanner)59 IOException (java.io.IOException)58 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)49 InputMismatchException (java.util.InputMismatchException)46 Locale (java.util.Locale)25 HashMap (java.util.HashMap)22 Map (java.util.Map)22 File (java.io.File)21 List (java.util.List)20 NodeIterator (javax.jcr.NodeIterator)20 HashSet (java.util.HashSet)16 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)16 Collection (java.util.Collection)15 LinkedList (java.util.LinkedList)15 Set (java.util.Set)15 Enumeration (java.util.Enumeration)14