15c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more
25c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * contributor license agreements.  See the NOTICE file distributed with
35c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * this work for additional information regarding copyright ownership.
45c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0
55c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * (the "License"); you may not use this file except in compliance with
65c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * the License.  You may obtain a copy of the License at
756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes *
85c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes *     http://www.apache.org/licenses/LICENSE-2.0
956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes *
105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * Unless required by applicable law or agreed to in writing, software
115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * See the License for the specific language governing permissions and
145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes * limitations under the License.
155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes */
16ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.util;
175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.BufferedReader;
1956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.BufferedWriter;
2056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.ByteArrayInputStream;
2156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.ByteArrayOutputStream;
225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.Closeable;
235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.EOFException;
245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.File;
255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.FileInputStream;
265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.FileNotFoundException;
275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.FileOutputStream;
2860a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamathimport java.io.IOException;
295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.InputStream;
3056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.InputStreamReader;
315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.OutputStream;
3256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.io.OutputStreamWriter;
335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.PipedInputStream;
345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.PipedOutputStream;
355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.io.StringReader;
365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.math.BigDecimal;
375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.math.BigInteger;
385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.net.InetSocketAddress;
395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.net.ServerSocket;
405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.net.Socket;
415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.net.SocketAddress;
4260a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamathimport java.nio.CharBuffer;
435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.nio.channels.FileChannel;
4456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.nio.channels.IllegalBlockingModeException;
455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.nio.channels.ReadableByteChannel;
4656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughesimport java.nio.channels.ServerSocketChannel;
475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.nio.channels.SocketChannel;
485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.nio.charset.Charset;
495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.ArrayList;
505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.Arrays;
515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.InputMismatchException;
525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.List;
535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.Locale;
545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.NoSuchElementException;
5560a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamathimport java.util.Scanner;
565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.regex.MatchResult;
575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport java.util.regex.Pattern;
585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughesimport junit.framework.TestCase;
595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughespublic class ScannerTest extends TestCase {
615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private Scanner s;
635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private ServerSocket server;
655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private SocketAddress address;
675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private SocketChannel client;
695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private Socket serverSocket;
715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private OutputStream os;
735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private static class MockCloseable implements Closeable, Readable {
755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public void close() throws IOException {
775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throw new IOException();
785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public int read(CharBuffer cb) throws IOException {
815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throw new EOFException();
825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(File)
885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_io_File() throws IOException {
905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(tmpFile);
925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(tmpFile);
9856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
9956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (FileNotFoundException expected) {
1005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
1035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileOutputStream fos = new FileOutputStream(tmpFile);
1045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        fos.write("test".getBytes());
10556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        fos.close();
1065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(tmpFile);
10856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
1095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        tmpFile.delete();
1105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(File = null)
1125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((File) null);
11456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
11556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
1165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // TODO: test if the default charset is used.
1195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
1205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
1225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(File, String)
1235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
1245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_io_FileLjava_lang_String()
1255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throws IOException {
1265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
1275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(tmpFile, Charset.defaultCharset().name());
1285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
1295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
1305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
1315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(tmpFile, Charset.defaultCharset().name());
13456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
13556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (FileNotFoundException expected) {
1365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1388b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        // Bogus test : Depends on the order in which expections are thrown.
1395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(tmpFile, null);
14156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
1428b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        } catch (IllegalArgumentException expected) {
1435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
1465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(tmpFile, "invalid charset");
14856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
14956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
1505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //fail on RI. File is opened but not closed when exception is thrown on
1535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // RI.
1545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
1555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(File = null, Charset = null)
1575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((File) null, null);
15956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
16056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
1615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(File = null, Charset = UTF-8)
1645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((File) null, "UTF-8");
16656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
16756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
1685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(File = null, Charset = invalid)
1715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((File) null, "invalid");
17356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
17456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
1755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(File, Charset = null)
1785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            File f = File.createTempFile("test", ".tmp");
1805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(f, null);
18156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
18256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
1835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
1845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // TODO: test if the specified charset is used.
1865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
1875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
1895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(InputStream)
1905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
1915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_io_InputStream() {
1925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(new PipedInputStream());
1935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
1945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
1955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
1965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(InputStream)
1975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
1985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((InputStream) null);
19956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
20056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
2015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // TODO: test if the default charset is used.
2045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
2055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
2075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(InputStream, String)
2085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
2095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
2105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(new PipedInputStream(), Charset.defaultCharset().name());
2115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
2125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
2135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
2155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((PipedInputStream) null, "invalid charset");
21656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
21756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
2185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
2215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(new PipedInputStream(), null);
22256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
22356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
2245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
2275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(new PipedInputStream(), "invalid charset");
22856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
22956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
2305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // TODO: test if the specified charset is used.
2335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
2345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
2365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(Readable)
2375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
2385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_lang_Readable() {
2395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(new StringReader("test string"));
2405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
2415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
2425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(Readable)
2445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
2455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((Readable) null);
24656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
24756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
2485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
2505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
2525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(ReadableByteChannel)
2535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
2545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_nio_channels_ReadableByteChannel()
2555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throws IOException {
2565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
2575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileChannel fc = new FileOutputStream(tmpFile).getChannel();
2585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(fc);
2595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
2605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
2615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
2625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(ReadableByteChannel)
2645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
2655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((ReadableByteChannel) null);
26656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
26756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
2685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Test if the default charset is used.
2715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String sampleData = "1 2 3 4 5 6 7 8 9 10";
2725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tempFile = File.createTempFile("harmony", "test");
2735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        tempFile.deleteOnExit();
2745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileOutputStream os = new FileOutputStream(tempFile);
2755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write(sampleData.getBytes());
2765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.close();
2775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileInputStream is = new FileInputStream(tempFile);
2795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileChannel channel = is.getChannel();
2805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Scanner s = new Scanner(channel);
2825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        int count = 0;
2835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        while (s.hasNextInt()) {
2845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
2855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            count++;
2865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
2875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        channel.close();
2885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(10, count);
2895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
2905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
2915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
2925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(ReadableByteChannel, String)
2935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
2945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_nio_channels_ReadableByteChannelLjava_lang_String()
2955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throws IOException {
2965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
2975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileChannel fc = new FileOutputStream(tmpFile).getChannel();
2985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(fc, Charset.defaultCharset().name());
2995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
3005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
3015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        fc = new FileOutputStream(tmpFile).getChannel();
3035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(fc, "invalid charset");
30556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
30656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
3075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        fc.close();
3095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
3105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(ReadableByteChannel = null, Charset = null)
3125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((ReadableByteChannel) null, null);
31456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
31556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
3165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(ReadableByteChannel = null, Charset = invalid)
3195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((ReadableByteChannel) null, "invalid");
32156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
32256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
3235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(ReadableByteChannel, Charset = null)
3265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner(fc, null);
32856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
32956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
3305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // TODO: test if the specified charset is used.
3325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
3335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_Constructor_LReadableByteChannel() throws IOException {
33556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ServerSocketChannel ssc = ServerSocketChannel.open();
33656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ssc.socket().bind(null);
33756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
33856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        SocketChannel sc = SocketChannel.open();
33956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        sc.connect(ssc.socket().getLocalSocketAddress());
34056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        sc.configureBlocking(false);
34156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertFalse(sc.isBlocking());
34256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
34356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ssc.accept().close();
34456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ssc.close();
34556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertFalse(sc.isBlocking());
34656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
34756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        Scanner s = new Scanner(sc);
34856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
34956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.hasNextInt();
35056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
35156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalBlockingModeException expected) {
35256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
35356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
35456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        sc.close();
35556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    }
35656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
3575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
3585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#Scanner(String)
3595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
3605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ConstructorLjava_lang_String() {
3615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test string");
3625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s);
3635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
3645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scanner(String)
3665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner((String) null);
36856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
36956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
3705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
3725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
3745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#close()
3755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
3765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_close() throws IOException {
3775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
3785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileOutputStream fos = new FileOutputStream(tmpFile);
3795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        FileChannel fc = fos.getChannel();
3805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(fc);
3815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Write out a int before the scanner is closed, should be OK.
3835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        fos.write(12);
3845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
3865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(fc.isOpen());
3875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Write out a int after the scanner is closed, IOException should be
3895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // thrown out.
3905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
3915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            fos.write(12);
39256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
39356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IOException expected) {
3945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
3955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
3965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close(); // no exception should be thrown
3975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(tmpFile.delete());
3985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
3995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#ioException()
4025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_ioException() throws IOException {
4045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MockCloseable mc = new MockCloseable();
4055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(mc);
4065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(s.ioException()); // No operation, no exception
4075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close(); // IOException should be cached
4095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s.ioException());
4105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.ioException() instanceof IOException);
4115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#delimiter()
4155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_delimiter() {
4175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Pattern pattern = s.delimiter();
4195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("\\p{javaWhitespace}+", pattern.toString());
4205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#useDelimiter(Pattern)
4245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_useDelimiter_LPattern() {
4265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useDelimiter(Pattern.compile("\\w+"));
4285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("\\w+", s.delimiter().toString());
4295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useDelimiter((Pattern) null);
4325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(s.delimiter());
4335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#useDelimiter(String)
4375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_useDelimiter_String() {
4395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
4415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.useDelimiter((String) null);
44256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
44356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
4445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
4455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useDelimiter("\\w+");
4485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("\\w+", s.delimiter().toString());
4495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#locale()
4535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_locale() {
4555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Locale.getDefault(), s.locale());
4575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#useLocale(Locale)
4615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_useLocale_LLocale() {
4635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
4655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.useLocale(null);
46656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
46756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
4685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
4695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("test", "test"));
4715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new Locale("test", "test"), s.locale());
4725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#radix()
4765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_radix() {
4785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(10, s.radix());
4805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
4815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
4825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
4835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#useRadix()
4845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
4855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_useRadix_I() {
4865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
4875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
4885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.useRadix(Character.MIN_RADIX - 1);
48956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
49056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
4915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
4925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
4935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.useRadix(Character.MAX_RADIX + 1);
49456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
49556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
4965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
4975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(11);
4985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(11, s.radix());
4995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
5005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
5015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
5025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#remove()
5035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
5045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_remove() {
5055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aab*b*").useDelimiter("\\*");
5065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.remove();
50856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
50956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (UnsupportedOperationException expected) {
5105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
5125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
5135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
5145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#match()
5155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
5165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_match() {
5175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult result ;
5185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1 2 ");
5195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
52156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
52256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
5235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
5255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
5265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.match();
5275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, result.start());
5285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3, result.end());
5295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, result.start(0));
5305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3, result.end(0));
5315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", result.group());
5325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", result.group(0));
5335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
5345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            result.start(1);
53656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
53756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IndexOutOfBoundsException expected) {
5385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
54156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
54256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
5435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
54656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
54756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
5485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
54956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
5505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("True faLse");
5515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
55356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
55456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
5555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
5575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.match();
5585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start());
5595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end());
5605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start(0));
5615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end(0));
5625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("True", result.group());
5635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
5645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
5655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
56756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
56856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
5695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
57256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
57356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
5745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
57556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
5765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("True faLse");
5775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
5785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.match();
5795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start());
5805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end());
5815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start(0));
5825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end(0));
5835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("True", result.group());
5845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
5855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
5865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
5875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
58856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
58956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
5905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
5915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.match();
5925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start());
5935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end());
5945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start(0));
5955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end(0));
5965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("True", result.group());
5975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
59856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
5995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("True fase");
6005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
6015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
6025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
60456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
60556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
6065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
6075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
60956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
61056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
6115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
61256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("True fase");
6145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
6155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next((Pattern)null);
61756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
61856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
6195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
6205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.match();
6215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start());
6225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end());
6235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.start(0));
6245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, result.end(0));
6255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("True", result.group());
6265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, result.groupCount());
62756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
62956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
6315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
6325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#next()
6335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
6345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_next() throws IOException {
6355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // use special delimiter
6365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1**2").useDelimiter("\\*");
6375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
6385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", s.next());
6395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
6405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(" \t 1 \t 2").useDelimiter("\\s*");
6425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
6435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
6445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
64656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
64756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
64956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("a").useDelimiter("a?");
6515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
65356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
65456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
65656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aa").useDelimiter("a?");
6585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", s.next());
6595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
66156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
66256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
66456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
6655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word( )test( )").useDelimiter("\\( \\)");
6675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word", s.next());
6685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
6695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("? next  ").useDelimiter("( )");
6715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("?", s.next());
6725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("next", s.next());
6735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", s.next());
6745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 word2  ");
6765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word1", s.next());
6775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word2", s.next());
6785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
6795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
68156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
68256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
6845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // just delimiter exists in this scanner
6865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(" ");
6875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
68956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
69056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
6925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
6935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // nothing exists in this scanner
6945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
6955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
6965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
69756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
69856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
6995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // no delimiter exists in this scanner
7025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
7035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
7045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // input resourse starts with delimiter
7065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("  test");
7075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
7085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // input resource ends with delimiter
7105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("  test  ");
7115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
7125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Harmony uses 1024 as default buffer size,
7145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // What if a sentence can not be read in all in once.
7155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder longSentence = new StringBuilder(1025);
7165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 11; i++) {
7175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            longSentence.append(" ");
7185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 11; i < 1026; i++) {
7205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            longSentence.append("a");
7215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(longSentence.toString());
7235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(longSentence.toString().trim(), s.next());
7245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(" test test");
7265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
7275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
7285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // What if use a delimiter of length 0.
7305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\ntest").useDelimiter(Pattern.compile("^",
7315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Pattern.MULTILINE));
7325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test\n", s.next());
7335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
73456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
7355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("").useDelimiter(Pattern.compile("^",
7365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Pattern.MULTILINE));
7375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
7385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
73956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
74056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
7415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
74256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
7435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("").useDelimiter(Pattern.compile("^*",
7445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Pattern.MULTILINE));
7455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
7465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
74756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
74856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
7495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\ntest").useDelimiter(Pattern.compile("^*",
7525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Pattern.MULTILINE));
7535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("t", s.next());
7545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("e", s.next());
7555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\ntest\ntest").useDelimiter(Pattern.compile("$",
7575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Pattern.MULTILINE));
7585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("\ntest", s.next());
7595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("\ntest", s.next());
7605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
7625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Harmony uses 1024 as default buffer size,
7635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // what if the leading delimiter is larger than 1023
7645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 1024; i++) {
7655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            os.write(" ".getBytes());
7665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("  1 2 ".getBytes());
7685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
7695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
7705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
7715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("  1 2".getBytes());
7725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
7735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
7745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
7755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
7765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
77756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
77856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
7795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
78256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
7835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
7845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
7855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#next(Pattern)
7865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
7875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextLPattern() throws IOException {
7885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Pattern pattern;
7895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aab*2*").useDelimiter("\\*");
7905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("a*b");
7915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next(pattern));
7925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
7935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
79456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
79556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
7965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
7975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
7985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word ? ");
7995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\w+");
8005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word", s.next(pattern));
8015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
80356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
80456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
8055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 word2  ");
8085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\w+");
8095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word1", s.next(pattern));
8105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word2", s.next(pattern));
8115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
8125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
81456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
81556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
8165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
8195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("aab 2".getBytes());
8215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
8225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
8245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("a*b");
8255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next(pattern));
8265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
82856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
82956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
8305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
8325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
8345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
8355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#next(String)
8365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
8375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextLString() throws IOException {
8385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("b*a*").useDelimiter("\\*");
8395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("b", s.next("a*b"));
8405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("a*b");
84256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
84356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
8445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word ? ");
8475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word", s.next("\\w+"));
8485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("\\w+");
85056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
85156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
8525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 next  ");
8555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word1", s.next("\\w+"));
8565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("next", s.next("\\w+"));
8575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
8585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("\\w+");
86056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
86156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
8625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
8655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("aab 2".getBytes());
8665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
8675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
8695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next("a*b"));
8705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("a*b");
87256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
87356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
8745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
87656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
8775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
8785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
8795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextBoolean()
8805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
8815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextBoolean() throws IOException {
8825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // case insensitive
8835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("TRue");
8845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
8855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("tRue false");
8875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
8885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
8895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
89156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
89256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
8935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
8945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
8955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("true1");
8965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
8975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
89856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
89956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
9005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s = new Scanner("");
9045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
90556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
90656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
9075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
9105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("true false".getBytes());
9115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
9125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
9145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
9155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
9165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // ues '*' as delimiter
9185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("true**false").useDelimiter("\\*");
9195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
9205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
92256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
92356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
9245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("false( )").useDelimiter("\\( \\)");
9275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
9285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
93056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
9315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
9325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
9335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextInt(int)
9345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
9355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextIntI() throws IOException {
9365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
9375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextInt(10));
9385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextInt(10));
9395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
94156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
94256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
9435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
9465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
9475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextInt(5));
9485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(5);
95056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
95156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
9525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
9555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
9565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
95856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
95956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
9605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
9635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
9645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
9655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
9665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
9675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
9685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
97056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
97156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
9725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
9745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
9755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
9765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
9775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
9795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
9805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
9815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
9825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
9835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
98556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
98656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
9875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
9885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
9895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
9905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
9915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
9925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
9935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
9945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
9955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
9965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
9975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextInt(10));
9985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
9995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(5);
100056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
100156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
10025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextInt(10));
10045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
10065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
10075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
10085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
10095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
10105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
10115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
10125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
101356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
101456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
10155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
10175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
10185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
10195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
10205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
10225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
10235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
10245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
10255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
102656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
102756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
10285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
10315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt(10));
10325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
10345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
10355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt(10));
10365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3456");
10385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt(16));
10395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The following test case fails on RI, because RI does not support
10405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // letter as leading digit
10415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3,456");
10425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
10435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt(16));
10445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
10465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
10475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
10485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
10495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
10505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
10515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
10525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
10545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
10555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
105656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
10575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
10585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
10595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
10605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
106160a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 123-");
106260a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s.useLocale(new Locale("ar", "AE"));
106360a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        assertEquals(-123, s.nextInt());
106460a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        try {
106560a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            s.nextInt();
106660a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            fail();
106760a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        } catch (InputMismatchException expected) {
106860a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        }
10695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
107060a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 -123-");
10715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
107260a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        assertEquals(-123, s.nextInt());
10735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
107460a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            s.nextInt();
107556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
107656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
10775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123 123-");
10805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
10815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt(10));
10825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
10835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
108456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
108556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
10865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
10885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
10895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
10905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the parameter radix is illegal, the following test cases fail on
10915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // RI
10925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
10935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(Character.MIN_RADIX - 1);
109456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
109556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
10965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
10975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
10985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(Character.MAX_RADIX + 1);
109956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
110056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
11015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
11035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
11055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
11065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextInt()
11075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
11085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextInt() throws IOException {
11095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
11105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextInt());
11115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextInt());
11125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
111456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
111556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
11165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
11195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
11205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
11215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextInt());
11225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
112456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
112556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
11295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
11305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
113256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
113356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
11375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
11385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
11395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
11405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
11415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
11425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
114456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
114556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
11485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
11495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
11535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
11545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
11555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
11565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
11575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
115956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
116056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
11635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
11645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
11685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
11695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
11705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
11715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextInt());
11725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
11735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
117556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
117656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
11795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextInt());
11805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
11825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
11835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
11845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
11855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
11865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
11875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
11885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
118956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
119056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
11915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
11925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
11935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
11945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt());
11965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
11975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
11985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
11995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
12005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
120256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
120356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
12045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
12055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
12075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt());
12085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
12105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
12115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt());
12125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3456");
12145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
12155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt());
12165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The following test case fails on RI, because RI does not support
12185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // letter as leading digit
12195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3,456");
12205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
12215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
12225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt());
12235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
12255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
12265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
12275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
12285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
12295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
12305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
12315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
12335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
12345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
123556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
12365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
12375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
12385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
12395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
124060a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 123-");
12415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
12425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
124360a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        try {
124460a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            s.nextInt();
124560a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            fail();
124660a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        } catch (InputMismatchException expected) {
124760a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        }
124860a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath
124960a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 -123-");
125060a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s.useLocale(new Locale("ar", "AE"));
12515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
12525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
125456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
125556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
12565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
12575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123 123-");
12595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
12605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
12615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
126356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
126456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
12655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
12665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
12675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
12685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
126956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
12705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
12715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
12725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextByte(int)
12735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
12745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextByteI() throws IOException {
12755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
12765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextByte(10));
12775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte(10));
12785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(10);
128056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
128156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
12825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
12835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
12855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
12865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextByte(5));
12875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(5);
128956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
129056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
12915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
12925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
12935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
12945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1234");
12955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
12965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(10);
129756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
129856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
12995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
13025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
13035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
13045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 12\u0666");
13055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextByte(10));
13065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
13075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(5);
130856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
130956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
13105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte(10));
13125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("012");
13145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12, s.nextByte(10));
13155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E");
13175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(14, s.nextByte(16));
13185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
13205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
13215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
13225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
13235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("100");
13245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
13255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
13265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0966\u0966");
13285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
13295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
133056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
13315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0e50\u0e50");
13325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
13335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
13345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
13365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
13375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte(10));
133856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
13395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
13415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
13425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte(10));
13435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
13445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
13465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
13475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextByte()
13485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
13495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextByte() throws IOException {
13505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
13515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextByte());
13525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte());
13535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
13545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
135556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
135656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
13575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
13605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
13615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
13625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextByte());
13635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
13645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
136556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
136656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
13675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
13705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1234");
13715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
13725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
137356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
137456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
13755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
13785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
13795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
13805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 12\u0666");
13815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextByte());
13825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
13835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
13845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
138556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
138656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
13875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
13885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
13895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte());
13905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("012");
13925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12, s.nextByte());
13935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E");
13955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
13965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(14, s.nextByte());
13975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
13985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
13995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
14005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
14015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
14025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("100");
14035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
14045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
14055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0966\u0966");
14075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
14085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
140956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
14105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0e50\u0e50");
14115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
14125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
14135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
14155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
14165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte());
14175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
14195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
14205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte());
14215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
142256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
14235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
14245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
14255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextFloat()
14265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
14275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextFloat() throws IOException {
14285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
14295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.0, s.nextFloat());
14315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)456.0, s.nextFloat());
14325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.4, s.nextFloat());
14335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)0.123, s.nextFloat());
14345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
14355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
143656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
143756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
14385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
14395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
14415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.4, s.nextFloat());
14435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-456.7, s.nextFloat());
14445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123456.789, s.nextFloat());
14455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
14465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
144756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
144856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
14495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
14505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
14525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
14535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)1.234E12, s.nextFloat());
14555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-4.567E14, s.nextFloat());
14565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)1.23456789E-5, s.nextFloat());
14575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN Infinity -Infinity");
14595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.NaN, s.nextFloat());
14605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
14615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.NEGATIVE_INFINITY, s.nextFloat());
14625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String str=String.valueOf(Float.MAX_VALUE*2);
14645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s=new Scanner(str);
14655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.POSITIVE_INFINITY,s.nextFloat());
146656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
14675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
14685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
14695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
14705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
14715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
14725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.0, s.nextFloat());
14745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
14755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23.456, s.nextFloat());
14765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
14785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23.456, s.nextFloat());
14805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
14815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.0, s.nextFloat());
14825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7 23.456,7");
14845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
14855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.7, s.nextFloat());
14865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
14875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.7, s.nextFloat());
14885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
14895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123.4 123.4- -123.4-");
14905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
14915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // FIXME
14925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertEquals((float)-123.4, s.nextFloat());
14935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        //The following test case fails on RI
14945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertEquals((float)-123.4, s.nextFloat());
14955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
14965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
149756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
149856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
14995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123- -123");
15025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
15035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
150556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
150656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
15095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
15105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-123.0, s.nextFloat());
15115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
151356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
15145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
15155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
15165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextBigInteger(int)
15175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
15185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextBigIntegerI() throws IOException {
15195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
15205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("123"), s.nextBigInteger(10));
15215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("456"), s.nextBigInteger(10));
15225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
152456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
152556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
15265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
15295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
15305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("38"), s.nextBigInteger(5));
15315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(5);
153356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
153456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
15385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
15395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
15405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
15415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
15425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
15435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
154556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
154656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
15495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
15505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
15545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
15555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
15565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
15575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
15585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
156056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
156156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
15645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
15655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
15695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
15705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
15715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
15725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("102"), s.nextBigInteger(10));
15735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(5);
157556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
157656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("162"), s.nextBigInteger(10));
15795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
15815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
15825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
15835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
15845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
15855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
15865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
15875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
158856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
158956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
15905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
15915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
15925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
15935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
15955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
15965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
15975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
15985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
15995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
16005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
160156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
160256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
16035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
16045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
16065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
16075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
16095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
16105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
16115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
16135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3636"), s.nextBigInteger(16));
16145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
16165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
16175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
16185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
16195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
16205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
16215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
16225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
16245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
16255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
162656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
16275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
16285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
16295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
16305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
16325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
16335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
163456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
16355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
16375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
16385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
16395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
16405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
16425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
16435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextBigInteger()
16445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
16455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextBigInteger() throws IOException {
16465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
16475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("123"), s.nextBigInteger());
16485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("456"), s.nextBigInteger());
16495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
16505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
165156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
165256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
16535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
16545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
16565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
16575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
16585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("38"), s.nextBigInteger());
16595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
16605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
166156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
166256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
16635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
16645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
16665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
16675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
16685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
16695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
16705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
16715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
16725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
167356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
167456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
16755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
16765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
16775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
16785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
16795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
16805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
16825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
16835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
16845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
16855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
16865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
16875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
168856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
168956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
16905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
16915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
16925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
16935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
16945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
16955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
16965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
16975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
16985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
16995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
17005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("102"), s.nextBigInteger());
17015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
17025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
170456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
170556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
17065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
17075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
17085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("162"), s.nextBigInteger());
17095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
17115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
17125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
17135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
17145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
17155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
17165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
171856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
171956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
17205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
17215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
17225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
17235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
17245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
17255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
17275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
17285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
17295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
173156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
173256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
17335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
17345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
17365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger());
17375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
17395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
17405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger());
17415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
17435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
17445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3636"), s.nextBigInteger());
17455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
17475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
17485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
17495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
17505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
17515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
17525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
17535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
17555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
17565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
175756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
17585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
17595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
17605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
17615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
17635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
17645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger());
17655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
17675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
17685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger());
17695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
177056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
17715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
17725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
17735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextShort(int)
17745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
17755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextShortI() throws IOException {
17765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
17775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextShort(10));
17785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextShort(10));
17795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
178156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
178256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
17835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
17845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
17865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
17875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextShort(5));
17885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(5);
179056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
179156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
17925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
17935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
17945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
17955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789");
17965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
17975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
179856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
179956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
18035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
18045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
18055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
18065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
18075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
18085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
18095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
181056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
181156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
18145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
18155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
18195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
18205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
18215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
18225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
18235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
18245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
182556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
182656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
18295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
18305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
18345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
18355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
18365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
18375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextShort(10));
18385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
18395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(5);
184056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
184156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextShort(10));
18445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
18465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
18475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
18485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
18495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
18505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
18515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
18525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
185356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
185456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
18575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
18585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
18605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
18625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
18635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
18645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
18655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
186656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
186756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
18685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
18695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
18715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort(10));
18725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
18745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
18755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort(10));
18765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
18785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextShort(16));
18795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
18815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
18825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
18835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
18845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
18855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
18865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
18875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
18895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
18905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
189156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
18925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
18935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
18945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
18955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
18965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
18975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
18985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort(10));
189956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
19005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
19025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
19035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort(10));
19045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
19055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
19075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
19085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextShort()
19095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
19105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextShort() throws IOException {
19115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
19125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextShort());
19135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextShort());
19145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
191656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
191756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
19185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
19215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
19225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
19235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextShort());
19245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
192656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
192756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
19315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789");
19325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
193456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
193556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
19395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
19405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
19415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
19425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
19435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
19445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
194656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
194756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
19505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
19515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
19555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
19565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
19575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
19585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
19595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
196156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
196256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
19655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
19665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
19705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
19715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
19725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
19735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextShort());
19745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
19755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
197756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
197856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
19815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextShort());
19825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
19845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
19855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
19865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
19875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
19885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
19895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
19905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
199156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
199256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
19935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
19945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
19955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
19965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
19985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
19995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
20005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
20015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
20025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
200456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
200556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
20065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
20075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
20095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort());
20105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
20125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
20135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort());
20145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
20165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
20175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextShort());
20185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
20205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
20215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
20225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
20235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
20245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
20255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
20265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
20285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
20295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
203056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
20315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
20325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
20335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
20345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
20365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
20375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort());
20385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
20405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
20415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort());
20425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
204356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
20445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
20455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
20465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextLong(int)
20475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
20485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextLongI() throws IOException {
20495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
20505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextLong(10));
20515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextLong(10));
20525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
205456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
205556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
20565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
20575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
20595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
20605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextLong(5));
20615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(5);
206356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
206456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
20655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
20665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
20685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
20695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
207156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
207256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
20735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
20745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
20765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
20775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
20785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
20795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
20805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
20815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
208356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
208456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
20855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
20865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
20875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
20885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
20895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
20905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
20915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
20925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
20935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
20945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
20955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
20965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
20975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
209856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
209956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
21005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
21015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
21025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
21035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
21045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
21055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
21075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
21085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
21095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
21105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextLong(10));
21115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
21125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(5);
211356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
211456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
21155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
21165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextLong(10));
21175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
21195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
21205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
21215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
21225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
21235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
21245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
21255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
212656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
212756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
21285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
21295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
21305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
21315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
21325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
21335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
21355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
21365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
21375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
21385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
213956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
214056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
21415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
21425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
21445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong(10));
21455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
21475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
21485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong(10));
21495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
21515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextLong(16));
21525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
21545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
21555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
21565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
21575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
21585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
21595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
21605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
21625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
21635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
216456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
21655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
21665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
21675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
21685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
21705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
21715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong(10));
217256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
21735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
21755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
21765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong(10));
21775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
217856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
21795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
21805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
21815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextLong()
21825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
21835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextLong() throws IOException {
21845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
21855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextLong());
21865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextLong());
21875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
21885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
218956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
219056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
21915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
21925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
21935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
21945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
21955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
21965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextLong());
21975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
21985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
219956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
220056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
22045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
22055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
220756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
220856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
22125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
22135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
22145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
22155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
22165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
22175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
221956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
222056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
22235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
22245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
22285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
22295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
22305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
22315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
22325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
223456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
223556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
22385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
22395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
22435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
22445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
22455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
22465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextLong());
22475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
22485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
225056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
225156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
22545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextLong());
22555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
22575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
22585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
22595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
22605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
22615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
22625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
226456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
226556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
22685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
22695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
22715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
22735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
22745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
22755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
22765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
227756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
227856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
22795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
22805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
22825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong());
22835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
22855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
22865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong());
22875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
22895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
22905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextLong());
22915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
22925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
22935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
22945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
22955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
22965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
22975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
22985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
22995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
23015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
23025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
230356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
23045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
23055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
23065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
23075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
23095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
23105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong());
23115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
23135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
23145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong());
23155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
231656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
23175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
23185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
23195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNext()
23205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
23215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNext() throws IOException {
23225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1##2").useDelimiter("\\#");
23235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
23255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", s.next());
23265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
23275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext());
23285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
23295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
23305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNext();
233156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
233256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
23335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
23345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1( )2( )").useDelimiter("\\( \\)");
23365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
23395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
23405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1 2  ").useDelimiter("( )");
23425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
23435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
23445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", s.next());
23465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\n2  ");
23485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
23495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
23515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext());
23525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
23535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
23545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
235556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
235656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
23575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
23585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1'\n'2  ");
23605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1'", s.next());
23615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("'2", s.next());
23635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext());
23645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
23655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
23665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
236756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
236856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
23695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
23705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("  ");
23725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext());
23735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
23755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("1 2".getBytes());
23775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
23785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
23795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
23805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.next());
23815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext());
23825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", s.next());
23835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext());
23845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
23855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next();
238656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
238756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
23885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
23895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
239056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
23915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
23925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
23935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNext(Pattern)
23945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
23955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLPattern() throws IOException {
23965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Pattern pattern;
23975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aab@2@abb@").useDelimiter("\\@");
23985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("a*b");
23995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext(pattern));
24005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next(pattern));
24015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext(pattern));
24025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
240456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
240556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
24065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
24085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word ? ");
24095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\w+");
24105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext(pattern));
24115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word", s.next(pattern));
24125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext(pattern));
24135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
241556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
241656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
24175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
24195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 WorD2  ");
24205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\w+");
24215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext(pattern));
24225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word1", s.next(pattern));
24235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext(pattern));
24245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("WorD2", s.next(pattern));
24255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext(pattern));
24265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
242856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
242956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
24305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
24325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 WorD2  ");
24335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\w+");
24345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNext((Pattern) null);
243656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
243756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
24385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
24405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNext(pattern);
244256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
244356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
24445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
244556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
24465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
24475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("aab b".getBytes());
24485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
24495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
24505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
24515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("a+b");
24525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext(pattern));
24535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next(pattern));
24545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext(pattern));
24555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next(pattern);
245756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
245856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
24595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
246156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
24625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
24635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
24645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNext(String)
24655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
24665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLString() throws IOException {
24675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aab@2@abb@").useDelimiter("\\@");
24685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNext((String)null);
247056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
247156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
24725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
247356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
24745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aab*b*").useDelimiter("\\*");
24755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext("a+b"));
24765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next("a+b"));
24775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext("a+b"));
24785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("a+b");
248056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
248156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
24825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
24845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNext("a+b");
248656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
248756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
24885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
24905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("WORD ? ");
24915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext("\\w+"));
24925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("WORD", s.next("\\w+"));
24935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext("\\w+"));
24945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
24955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("\\w+");
249656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
249756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
24985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
24995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 word2  ");
25015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word1", s.next("\\w+"));
25025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("word2", s.next("\\w+"));
25035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test boundary case
25045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
25055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("\\w+");
250656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
250756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
25085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
25095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
25115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("aab 2".getBytes());
25135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
25145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
25165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNext("a*b"));
25175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aab", s.next("a*b"));
25185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNext("a*b"));
25195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
25205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.next("a*b");
252156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
252256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
25235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
25245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
252556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
25265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
25275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
25285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextBoolean()
25295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
25305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextBoolean() throws IOException {
25315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("TRue");
25335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
25355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("tRue false");
25375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
25395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
25415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
25435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBoolean());
25445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // test socket inputStream
25465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os.write("true false ".getBytes());
25485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket.close();
25495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(client);
25515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
25535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // ues '*' as delimiter
25555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("true**false").useDelimiter("\\*");
25565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.nextBoolean());
25585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBoolean());
25595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
25605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBoolean();
256156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
256256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
25635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
25645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("false( )").useDelimiter("\\( \\)");
25665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBoolean());
25675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.nextBoolean());
25685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBoolean());
25695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
257156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
25725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
25735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
25745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextByte(int)
25755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
25765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextByteI() throws IOException {
25775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
25785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
25795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextByte(10));
25805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
25815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte(10));
25825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte(10));
25835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
25845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(10);
258556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
258656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
25875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
25885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
25895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
25905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
25915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(5));
25925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextByte(5));
25935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte(5));
25945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
25955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(5);
259656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
259756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
25985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
25995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
26015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1234");
26025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte(10));
26035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
26045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(10);
260556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
260656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
26075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
26085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
26105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
26115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
26125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 12\u0666");
26135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextByte(10));
26155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte(5));
26165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
26175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte(5);
261856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
261956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
26205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
26215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte(10));
26235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("012");
26255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12, s.nextByte(10));
26275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E");
26295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(16));
26305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(14, s.nextByte(16));
26315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
26335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
26345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
26355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
26365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("100");
26375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
26385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
26405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0966\u0966");
26425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
26435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
264556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
26465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0e50\u0e50");
26475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
26485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte(10));
26505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
26525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
26535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte(10));
265556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
26565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
26585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
26595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte(10));
26605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte(10));
26615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
26625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
26638b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath    // This is a bogus test : The cached value is returned only if the radix
26648b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath    // matches.
26655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextByteI_cache() throws IOException{
26665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //regression for HARMONY-2063
266756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 45");
266856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextByte(8));
26698b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        // Note that the cached value isn't returned here.
26708b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextByte());
267156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(45, s.nextByte());
267256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
267356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 45");
267456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextByte(10));
267556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextByte(8));
26768b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath
26778b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        // The values are returned according to the supplied radix.
26788b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextByte());
267956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(45, s.nextByte());
268056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
268156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("-123 -45");
268256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextByte(8));
268356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-123, s.nextInt());
268456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-45, s.nextByte());
268556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
268656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 45");
268756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextByte());
268856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
268956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
269056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes          s.nextByte();
269156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes          fail();
269256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
269356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
26945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
269556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
26965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextByte() throws IOException {
26975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
26985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
26995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextByte());
27005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte());
27025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte());
27035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
27045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
270556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
270656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
27075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
27085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
27105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 126");
27115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
27125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextByte());
27145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte());
27155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
27165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
271756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
271856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
27195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
27205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
27225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1234");
27235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte());
27245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
27255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
272656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
272756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
27285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
27295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
27315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
27325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
27335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 12\u0666");
27345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextByte());
27365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
27375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextByte());
27385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
27395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextByte();
274056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
274156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
27425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
27435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
27445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(126, s.nextByte());
27465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("012");
27485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12, s.nextByte());
27495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E");
27515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
27525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(14, s.nextByte());
27545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
27565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
27575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
27585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
27595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("100");
27605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
27615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
27635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0966\u0966");
27655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
27665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
276856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
27695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u0e50\u0e50");
27705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
27715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(100, s.nextByte());
27735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
27755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
27765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte());
27785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
27795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
27805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
27815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextByte());
27825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextByte());
27835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
278456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
27855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
27865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
27875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextBigInteger(int)
27885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
27895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextBigIntegerI() throws IOException {
27905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
27915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
27925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("123"), s.nextBigInteger(10));
27935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
27945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("456"), s.nextBigInteger(10));
27955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(10));
27965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
27975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
279856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
279956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
28005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
28035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
28045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(5));
28055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("38"), s.nextBigInteger(5));
28065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(5));
28075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(5);
280956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
281056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
28145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
28155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
28165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
28175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
28185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
28195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(10));
28205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
282256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
282356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
28265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
28275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
28335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
28345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
28355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
28365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
28375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(10));
28385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
284056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
284156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
28445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
28455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
28515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
28525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
28535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
28545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("102"), s.nextBigInteger(10));
28565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(5));
28575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(5);
285956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
286056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("162"), s.nextBigInteger(10));
28645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
28665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
28675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
28685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
28695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
28705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
28715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(10));
28725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
287456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
287556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
28785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
28795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
28835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
28855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
28865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
28875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger(10));
28885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
28895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger(10);
289056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
289156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
28925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
28935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
28955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
28965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
28975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
28985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
28995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
29005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
29025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
29045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(16));
29055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3636"), s.nextBigInteger(16));
29065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
29085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
29095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
29105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
29115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
29125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
29135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
29155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
29175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
29185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
292056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
29215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
29225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
29235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
29255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
29275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
29285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
293056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
29315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
29335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
29345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
29355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
29365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
293756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
29385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
29395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
29405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextBigInteger(int)
29415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
29425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextBigIntegerI_cache() throws IOException {
29435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //regression for HARMONY-2063
294456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 123456789123456789");
294556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextBigInteger(16));
29468b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(new BigInteger("123"), s.nextBigInteger());
294756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(new BigInteger("123456789123456789"), s.nextBigInteger());
294856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
294956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123456789123456789 456");
295056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextBigInteger(16));
295156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextBigInteger(10));
295256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(new BigInteger("123456789123456789"), s.nextBigInteger());
295356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(new BigInteger("456"), s.nextBigInteger());
295456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
295556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("-123 -123456789123456789");
295656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextBigInteger(8));
295756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-123, s.nextShort());
295856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(new BigInteger("-123456789123456789"), s.nextBigInteger());
295956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
296056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
296156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextBigInteger());
296256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
296356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
296456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextBigInteger();
296556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
296656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
296756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
29685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
296956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
29705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
29715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
29725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextBigInteger()
29735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
29745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextBigInteger() throws IOException {
29755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
29765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
29775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("123"), s.nextBigInteger());
29785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
29795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("456"), s.nextBigInteger());
29805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
29815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
29825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
298356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
298456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
29855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
29865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
29885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
29895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
29905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
29915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("38"), s.nextBigInteger());
29925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
29935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
29945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
299556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
299656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
29975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
29985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
29995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
30005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
30015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
30025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
30035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
30045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
30055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
30065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
30075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
300856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
300956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
30105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
30115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
30125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
30135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
30195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
30205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
30215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
30225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
30235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
30245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
30255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
302656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
302756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
30285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
30295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
30305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
30315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
30375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
30385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
30395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
30405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("102"), s.nextBigInteger());
30415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
30425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
30435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
30445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
304556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
304656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
30475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
30485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
30495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("162"), s.nextBigInteger());
30515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
30535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
30545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
30555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
30565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
30575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
30585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
30595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
30605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
306156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
306256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
30635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
30645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
30655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
30665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("23456"), s.nextBigInteger());
30705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
30725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
30735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
30745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigInteger());
30755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
30765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigInteger();
307756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
307856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
30795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
30805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
30825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger());
30845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
30865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
30875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3456"), s.nextBigInteger());
30895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
30915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
30925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
30935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("3636"), s.nextBigInteger());
30945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
30955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
30965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
30975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
30985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
30995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
31005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
31015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
31025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
31035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
31055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
31065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
31075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
310856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
31095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
31105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
31115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
31125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("12300"), s.nextBigInteger());
31135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
31155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
31165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
31175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger());
31185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
31205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
31215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigInteger());
31225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigInteger("-123"), s.nextBigInteger());
31235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
312456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
31255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
31265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
31275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextInt(int)
31285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
31295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextIntI() throws IOException {
31305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
31315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextInt(10));
31325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
31335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextInt(10));
31345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
31355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
31365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
313756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
313856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
31395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
31405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
31425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
31435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(5));
31445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextInt(5));
31455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(5));
31465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
31475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(5);
314856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
314956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
31505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
31515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
31535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
31545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
31555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
31575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
31585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
31595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
31605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456");
31615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
31625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
31635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
31645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
31655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
31665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
31675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
31685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
31695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456");
31705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
31715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
31725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
31735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
31745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
31755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
31775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
31785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
31795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06662");
31805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
31815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(5));
31825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
31845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
31855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
31865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
31875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666");
31885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
31895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
31905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
31915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
319256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
319356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
31945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
31955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
31965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
31975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
31985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
31995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
32005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
32015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
32025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
32035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
320456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
320556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
32065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
32075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
32095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt(10));
32115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
32135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
32145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt(10));
32165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3456");
32185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(16));
32195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt(16));
32205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The following test case fails on RI, because RI does not support
32215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // letter as leading digit
32225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3,456");
32235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
32245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(16));
32255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt(16));
32265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If parameter radix is illegal, the following test case fails on RI
32285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
32295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNextInt(Character.MIN_RADIX - 1);
323056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
323156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
32325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
32335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
32355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
32365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
32375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
32385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
32395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
32405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
32425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
32445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
32455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
32475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
32495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
32505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt(10));
32525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
325360a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 123-");
32545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
32555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt(10));
325760a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        assertFalse(s.hasNextInt(10));
325860a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        try {
325960a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            s.nextInt(10);
326060a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            fail();
326160a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        } catch (InputMismatchException expected) {
326260a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        }
326360a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath
326460a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 -123-");
326560a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s.useLocale(new Locale("ar", "AE"));
32665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt(10));
32675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
32685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
32695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt(10);
327056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
327156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
32725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
32735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123 123-");
32755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
32765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt(10));
32775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt(10));
32785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt(10));
32795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
32805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
328156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
328256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
32835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
32845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
32855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
32865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
32875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
32885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
32895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
32905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextInt(int)
32915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
32925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextIntI_cache() throws IOException {
32935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //regression for HARMONY-2063
329456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
329556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt(16));
32968b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextInt(10));
329756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextInt());
329856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
329956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
330056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt(16));
330156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt(8));
33028b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextInt());
330356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextInt());
330456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
330556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("-123 -456 -789");
330656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt(8));
330756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-123, s.nextShort());
330856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-456, s.nextInt());
330956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(16));
331056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-789, s.nextInt());
331156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
331256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
331356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt());
331456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
331556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
331656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextInt();
331756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
331856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
331956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
33205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
33215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
33225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
33235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextInt()
33245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
33255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextInt() throws IOException {
33265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
33275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
33285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextInt());
33295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextInt());
33305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
33325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
333356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
333456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
33355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
33365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
33385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
33395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
33405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
33415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextInt());
33425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
33445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
334556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
334656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
33475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
33485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
33505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
33515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
33545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
33555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
33565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
33575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456");
33585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
33595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
33615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
33625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
33645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
33655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
33665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456");
33675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
33685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
33705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
33715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
33735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
33745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
33755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06662");
33765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
33775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
33805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
33815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
33825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
33835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666");
33845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
33855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
33875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
33885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
33905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
33915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
33925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
33935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
33945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
339556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
339656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
33975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
33985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
33995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
34005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt());
34025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
34045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
34055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextInt());
34065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3456");
34085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
34095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt());
34115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The following test case fails on RI, because RI does not support
34135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // letter as leading digit
34145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E3,456");
34155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
34165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
34175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(930902, s.nextInt());
34195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
34215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
34225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
34235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
34245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
34255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
34265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
34285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
34305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
34315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
34335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
34355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
34365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextInt());
34385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
343960a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 123-");
34405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
34415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
344360a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        assertFalse(s.hasNextInt());
344460a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        try {
344560a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            s.nextInt();
344660a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath            fail();
344760a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        } catch (InputMismatchException expected) {
344860a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        }
344960a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath
345060a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s = new Scanner("-123 -123-");
345160a27a2be820124baa3bac417ac6828ede3d1bd8Narayan Kamath        s.useLocale(new Locale("ar", "AE"));
34525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
34545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextInt());
34555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
34565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
345756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
345856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
34595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
34605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123 123-");
34625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
34635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextInt());
34645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextInt());
34655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
34665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextInt();
346756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
346856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
34695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
34705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
34715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
34725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
347356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
34745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
34755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
34765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextFloat()
34775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
34785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextFloat() throws IOException {
34795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
34805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
34815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
34825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.0, s.nextFloat());
34835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
34845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)456.0, s.nextFloat());
34855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
34865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.4, s.nextFloat());
34875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
34885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)0.123, s.nextFloat());
34895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextFloat());
34905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
34915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
349256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
349356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
34945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
34955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
34965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
34975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
34985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
34995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123.4, s.nextFloat());
35005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-456.7, s.nextFloat());
35025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)123456.789, s.nextFloat());
35045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextFloat());
35055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
35065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
350756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
350856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
35095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
35105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
35125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
35135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
35145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)1.234E12, s.nextFloat());
35165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-4.567E14, s.nextFloat());
35185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)1.23456789E-5, s.nextFloat());
35205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN Infinity -Infinity");
35225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.NaN, s.nextFloat());
35245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
35265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.NEGATIVE_INFINITY, s.nextFloat());
35285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String str=String.valueOf(Float.MAX_VALUE*2);
35305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s=new Scanner(str);
35315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Float.POSITIVE_INFINITY,s.nextFloat());
353356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
35345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
35355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
35365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
35375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
35385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
35395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
35405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.0, s.nextFloat());
35425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
35435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23.456, s.nextFloat());
35455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
35475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
35485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23.456, s.nextFloat());
35505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
35515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.0, s.nextFloat());
35535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7 23.456,7");
35555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
35565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.7, s.nextFloat());
35585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
35595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)23456.7, s.nextFloat());
35615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //FIXME
35635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        s = new Scanner("-123.4 123.4- -123.4-");
35645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        s.useLocale(new Locale("ar", "AE"));
35655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertTrue(s.hasNextFloat());
35665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertEquals((float)-123.4, s.nextFloat());
35675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        //The following test case fails on RI
35685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertTrue(s.hasNextFloat());
35695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        assertEquals((float)-123.4, s.nextFloat());
35705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        try {
35715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//            s.nextFloat();
357256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes//            fail();
357356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes//        } catch (InputMismatchException expected) {
35745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes//        }
35755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123- -123");
35775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
35785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextFloat());
35795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
35805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextFloat();
358156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
358256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
35835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
35845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Skip the un-recognizable token 123-.
35855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("123-", s.next());
35865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals((float)-123.0, s.nextFloat());
358856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
35895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7");
35905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
35915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextFloat());
35925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
35935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try{
359456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextFloat();
359556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
359656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }catch(IllegalStateException expected) {
35975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
35985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
35995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
360056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
36015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
36025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
36035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextShort(int)
36045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
36055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextShortI() throws IOException {
36065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
36075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextShort(10));
36095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextShort(10));
36115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
36125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
361456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
361556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
36165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
36195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
36205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(5));
36215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextShort(5));
36225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(5));
36235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(5);
362556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
362656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
36275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
36305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789");
36315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
36325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
363456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
363556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
36365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
36395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
36405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
36415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
36425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
36435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
36445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
36455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
364756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
364856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
36495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
36515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
36525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
36545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextInt(10));
36565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
36585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
36595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
36605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
36615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
36625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
36635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
366556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
366656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
36675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
36695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
36705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
36725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
36745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
36765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
36775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
36785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
36795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextShort(10));
36815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(5));
36825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(5);
368456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
368556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
36865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
36875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
36885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextShort(10));
36895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
36905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
36915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
36925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
36935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
36945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
36955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
36965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
36975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
36985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
369956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
370056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
37015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
37025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
37035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
37045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
37065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort(10));
37085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
37105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
37115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
37125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
37135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
37145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort(10);
371556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
371656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
37175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
37185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
37205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort(10));
37225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
37245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
37255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort(10));
37275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
37295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(16));
37305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextShort(16));
37315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
37335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
37345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
37355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
37365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
37375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
37385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
37405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
37425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
37435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
374556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
37465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
37475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
37485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort(10));
37505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
37525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
37535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort(10));
375556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
37565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
37585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
37595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort(10));
37605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort(10));
37615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
37625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
37645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
37655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextShort()
37665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
37675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextShort() throws IOException {
37685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
37695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
37705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextShort());
37715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
37725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextShort());
37735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
37745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
37755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
377656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
377756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
37785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
37795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
37815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
37825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
37835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
37845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextShort());
37855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
37865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
37875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
378856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
378956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
37905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
37915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
37925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
37935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789");
37945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
37955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
37965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
379756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
379856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
37995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
38025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
38035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
38045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
38055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
38065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
38075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
38085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
38095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
381056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
381156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
38125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
38145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
38155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
38215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
38225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
38235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
38245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
38255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
38265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
38275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
382856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
382956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
38305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
38325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
38335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
38395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
38405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
38415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
38425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextShort());
38435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
38445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
38455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
38465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
384756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
384856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
38495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
38515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextShort());
38535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
38555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
38565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
38575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
38585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
38595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
38605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
38615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
38625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
386356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
386456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
38655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
38675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
38685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextShort());
38725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
38745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
38755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
38765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort());
38775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
38785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextShort();
387956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
388056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
38815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
38825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
38845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort());
38865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
38885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
38895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextShort());
38915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
38935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
38945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
38955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextShort());
38965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
38975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
38985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
38995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
39005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
39015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
39025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
39035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
39045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
39055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
39075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
39085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
39095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
391056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
39115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
39125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
39135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
39145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextShort());
39155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
39175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
39185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
39195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort());
39205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
39225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
39235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextShort());
39245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextShort());
39255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
392656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
39275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
392856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @throws IOException
392956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @tests java.util.Scanner#hasNextShort(int)
393056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     */
393156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_hasNextShortI_cache() throws IOException {
39325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //regression for HARMONY-2063
393356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
393456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(16));
39358b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextShort());
393656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextShort());
393756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
393856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
393956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(16));
394056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(8));
39418b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextShort());
394256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextShort());
394356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
394456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("-123 -456 -789");
394556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(8));
394656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-123, s.nextInt());
394756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-456, s.nextShort());
394856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextInt(16));
394956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-789, s.nextShort());
395056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
395156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
395256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort());
395356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
395456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
395556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextShort();
395656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
395756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
395856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
395956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    }
396056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
39615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
396256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @throws IOException
396356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @tests java.util.Scanner#hasNextLong(int)
396456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     */
39655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLongI() throws IOException {
39665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
39675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
39685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextLong(10));
39695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
39705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextLong(10));
39715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(10));
39725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
39735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
397456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
397556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
39765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
39775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
39795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
39805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(5));
39815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextLong(5));
39825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(5));
39835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
39845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(5);
398556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
398656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
39875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
39885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
39905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
39915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(10));
39925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
39935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
399456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
399556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
39965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
39975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
39985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
39995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
40005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
40015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
40025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
40035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
40045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextShort(10));
40055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
40065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
400756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
400856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
40095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
40105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
40115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
40125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
40185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
40195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
40205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
40215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
40225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(10));
40235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
40245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
402556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
402656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
40275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
40285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
40295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
40305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
40365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
40375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
40385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
40395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextLong(10));
40415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(5));
40425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
40435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(5);
404456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
404556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
40465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
40475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextLong(10));
40495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
40515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
40525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
40535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
40545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
40555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
40565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(10));
40575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
40585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
405956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
406056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
40615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
40625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
40635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
40645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong(10));
40685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
40705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
40715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
40725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong(10));
40735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
40745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong(10);
407556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
407656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
40775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
40785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
40805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong(10));
40825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
40845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
40855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong(10));
40875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
40895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(16));
40905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextLong(16));
40915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
40925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
40935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
40945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
40955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
40965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
40975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
40985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
40995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
41005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
41025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
41035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
41045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
410556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
41065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
41075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
41085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
41095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong(10));
41105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
41125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
41135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
41145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong(10));
411556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
41165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
41185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
41195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong(10));
41205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong(10));
41215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
412256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
41235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
412456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @throws IOException
412556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     * @tests java.util.Scanner#hasNextLong(int)
412656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes     */
41275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLongI_cache() throws IOException {
41285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //regression for HARMONY-2063
412956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
413056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextLong(16));
41318b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextLong());
413256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextLong());
413356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
413456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
413556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextLong(16));
413656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextLong(8));
41378b2e919af0d25fc0a05f05cd9d1286fdf5b3b68cNarayan Kamath        assertEquals(123, s.nextLong());
413856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(456, s.nextLong());
413956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
414056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("-123 -456 -789");
414156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextLong(8));
414256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-123, s.nextInt());
414356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-456, s.nextLong());
414456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextShort(16));
414556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(-789, s.nextLong());
414656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
414756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner("123 456");
414856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertTrue(s.hasNextLong());
414956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s.close();
415056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        try {
415156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextLong();
415256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
415356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
415456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
41555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
41565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
41585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
41595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextLong()
41605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
41615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLong() throws IOException {
41625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
41635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
41645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, s.nextLong());
41655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
41665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456, s.nextLong());
41675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
41685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
41695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
417056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
417156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
41725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
41735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the radix is different from 10
41755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 456");
41765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
41775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
41785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(38, s.nextLong());
41795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
41805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
41815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
418256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
418356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
41845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
41855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If the number is out of range
41875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123456789123456789123456789123456789");
41885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
41895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
41905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
419156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
419256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
41935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
41945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
41955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
41965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
41975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
41985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
41995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
42005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
42015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
42025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
42035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
420456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
420556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
42065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
42075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
42085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
42095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
42155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * ''' is used in many locales as group separator.
42165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
42175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23'456 23'456");
42185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
42195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
42205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
42215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
422256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
422356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
42245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
42255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("it", "CH"));
42265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
42275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
42335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * The input string has Arabic-Indic digits.
42345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
42355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1\u06602 1\u06662");
42365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102, s.nextLong());
42375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(5);
42385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
42395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
42405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
424156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
424256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
42435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
42445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(10);
42455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(162, s.nextLong());
42475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
42495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * '.' is used in many locales as group separator. The input string
42505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * has Arabic-Indic digits .
42515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
42525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.45\u0666 23.456");
42535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
42545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
42555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
42565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
425756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
425856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
42595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
42605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
42615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If exception is thrown out, input will not be advanced.
42625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456, s.nextLong());
42665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The input string starts with zero
42685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03,456");
42695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
42705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextLong());
42715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
42725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLong();
427356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
427456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
42755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
42765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("03456");
42785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong());
42805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u06603,456");
42825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
42835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3456, s.nextLong());
42855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("E34");
42875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useRadix(16);
42885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3636, s.nextLong());
42905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
42915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
42925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
42935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * respectively, but they are not differentiated.
42945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
42955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12300");
42965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
42975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
42985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
42995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0966\u0966");
43015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
43025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
43035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
430456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
43055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123\u0e50\u0e50");
43065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.CHINESE);
43075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
43085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12300, s.nextLong());
43095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
43115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("ar", "AE"));
43125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
43135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong());
43145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123");
43165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(new Locale("mk", "MK"));
43175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLong());
43185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123, s.nextLong());
43195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
432056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
43215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
43225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
43235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextDouble()
43245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
43255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextDouble() throws IOException {
43265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
43275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
43285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.0, s.nextDouble());
43305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456.0, s.nextDouble());
43325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.4, s.nextDouble());
43345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0.123, s.nextDouble());
43365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextDouble());
43375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
43385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextDouble();
433956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
434056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
43415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
43425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
43445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
43455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.4, s.nextDouble());
43475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-456.7, s.nextDouble());
43495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123456.789, s.nextDouble());
43515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextDouble());
43525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
43535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextDouble();
435456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
435556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
43565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
43575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
43595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
43605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
43615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1.234E12, s.nextDouble());
43635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-4.567E14, s.nextDouble());
43655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1.23456789E-5, s.nextDouble());
43675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN Infinity -Infinity");
43695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.NaN, s.nextDouble());
43715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
43735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.NEGATIVE_INFINITY, s.nextDouble());
43755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String str=String.valueOf(Double.MAX_VALUE*2);
43775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s=new Scanner(str);
43785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.POSITIVE_INFINITY,s.nextDouble());
438056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
43815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
43825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
43835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
43845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
43855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
43865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
43875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.0, s.nextDouble());
43895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
43905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23.456, s.nextDouble());
43925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
43935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
43945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
43955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23.456, s.nextDouble());
43975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
43985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
43995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.0, s.nextDouble());
44005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7 23.456,7");
44025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
44045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.7, s.nextDouble());
44055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
44065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
44075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.7, s.nextDouble());
44085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123.4");
44105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
44125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123.4, s.nextDouble());
441356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
44145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7");
44155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextDouble());
44175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
44185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try{
441956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            s.nextDouble();
442056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
442156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }catch(IllegalStateException expected) {
44225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
44235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
442456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
44255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
44265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
44275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextBigDecimal()
44285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
44295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextBigDecimal() throws IOException {
44305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
44315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123"), s.nextBigDecimal());
44345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("456"), s.nextBigDecimal());
44365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
44385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("0.123"), s.nextBigDecimal());
44405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigDecimal());
44415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
44425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
444356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
444456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
44455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
44465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
44485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
44515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-456.7"), s.nextBigDecimal());
44535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123456.789"), s.nextBigDecimal());
44555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigDecimal());
44565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
44575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
445856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
445956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
44605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
44615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
44635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
44645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
44675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
44695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
44715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN");
44735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(s.hasNextBigDecimal());
44745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
44755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
447656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
447756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
44785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
44795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
44815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
44825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
44835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
44845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
44855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
44885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
44895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
44915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
44925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
44935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
44945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
44965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
44975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
44985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
44995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7");
45015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
45025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
45035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456.7"), s.nextBigDecimal());
45045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123.4");
45065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
45075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextBigDecimal());
45085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-123.4"), s.nextBigDecimal());
45095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
451056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
45115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private static class MockStringReader extends StringReader {
45125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public MockStringReader(String param) {
45145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            super(param);
45155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
45165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public int read(CharBuffer target) throws IOException {
45185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            target.append('t');
45195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            target.append('e');
45205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            target.append('s');
45215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            target.append('t');
45225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            throw new IOException();
45235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
45245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
452656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
45275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    private static class MockStringReader2Read extends StringReader {
452856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        int timesRead = 0;
45295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public MockStringReader2Read(String param) {
45315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            super(param);
45325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
45335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        public int read(CharBuffer target) throws IOException {
453556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            if (timesRead == 0) {
45365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                target.append('1');
45375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                target.append('2');
45385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                target.append('3');
45395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                timesRead++;
45405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                return 3;
454156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            } else if (timesRead == 1) {
45425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                target.append('t');
45435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                timesRead++;
45445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                return 1;
45455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            } else {
45465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                throw new IOException();
45475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            }
45485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
45495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
455156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
455256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    // https://code.google.com/p/android/issues/detail?id=40555
455356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_40555() throws Exception {
455456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      MockStringReader2Read reader = new MockStringReader2Read("MockStringReader");
455556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner(reader);
455656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      // We should get a match straight away.
455756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      String result = s.findWithinHorizon("1", 0);
455856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("1", result);
455956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      // The stream should not be consumed as there's already a match after the first read.
456056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(1, reader.timesRead);
456156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    }
456256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
45635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
45645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#findWithinHorizon(Pattern, int)
45655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
456656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_findWithinHorizon_LPatternI() {
45675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // This method searches through the input up to the specified search
45695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // horizon(exclusive).
45705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123test");
45715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String result = s.findWithinHorizon(Pattern.compile("\\p{Lower}"), 5);
45725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("t", result);
45735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult mresult = s.match();
45745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3, mresult.start());
45755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, mresult.end());
45765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("12345test1234test next");
45785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
45795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * If the pattern is found the scanner advances past the input that
45805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * matched and returns the string that matched the pattern.
45815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
45825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 2);
45835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("12", result);
45845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
45855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, mresult.start());
45865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, mresult.end());
45875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Position is now pointing at the bar. "12|345test1234test next"
45885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 6);
45905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("345", result);
45915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
45935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, mresult.start());
45945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, mresult.end());
45955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Position is now pointing at the bar. "12345|test1234test next"
45965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
45975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If no such pattern is detected then the null is returned and the
45985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // scanner's position remains unchanged.
45995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 3);
46005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
46015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
460456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
460556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
46065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("345", mresult.group());
46085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, mresult.start());
46095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, mresult.end());
46105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Position is now still pointing at the bar. "12345|test1234test next"
46115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If horizon is 0, then the horizon is ignored and this method
46135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // continues to search through the input looking for the specified
46145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // pattern without bound.
46155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 0);
46165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
46175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(9, mresult.start());
46185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(13, mresult.end());
46195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Position is now pointing at the bar. "12345test1234|test next"
46205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", s.next());
46225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
46235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(13, mresult.start());
46245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(17, mresult.end());
46255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("next", s.next());
46275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
46285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(18, mresult.start());
46295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(22, mresult.end());
46305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findWithinHorizon((Pattern) null, -1);
463356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
463456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
46355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), -1);
463956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
464056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalArgumentException expected) {
46415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
46445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findWithinHorizon((Pattern) null, -1);
464656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
464756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
46485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
46515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("\\w+"), 10);
46525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
46535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aa\n\rb");
46555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("a"), 5);
46565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("a", result);
46575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
46585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, mresult.start());
46595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, mresult.end());
46605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
466156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("^(a)$", Pattern.MULTILINE), 5);
46625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
46635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            mresult = s.match();
466656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
466756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
46685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
46715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("^"), 0);
46725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
46735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult matchResult = s.match();
46745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
46755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.end());
46765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("$"), 0);
46785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
46795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
46805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
46815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.end());
46825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1 fish 2 fish red fish blue fish");
46845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern
46855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                .compile("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"), 10);
46865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
46875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
46895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            mresult = s.match();
469056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
469156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
46925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
46935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, mresult.groupCount());
46945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
46955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern
46965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                .compile("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"), 100);
46975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1 fish 2 fish red fish blue", result);
46985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        mresult = s.match();
46995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, mresult.groupCount());
47005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", mresult.group(1));
47015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("2", mresult.group(2));
47025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("red", mresult.group(3));
47035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("blue", mresult.group(4));
47045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
47065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
47075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
47085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findWithinHorizon(Pattern.compile("test"), 1);
470956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
471056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
47115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 WorD2  ");
47145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
47155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
47165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findWithinHorizon(Pattern.compile("\\d+"), 10);
471756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
471856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
47195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("word1 WorD2 wOrd3 ");
47225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Pattern pattern = Pattern.compile("\\d+");
47235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1", s.findWithinHorizon(pattern, 10));
47245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("WorD2", s.next());
47255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("3", s.findWithinHorizon(pattern, 15));
47265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Regression test
47285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(new MockStringReader("MockStringReader"));
47295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("test");
47305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(pattern, 10);
47315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
47325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Test the situation when input length is longer than buffer size.
47345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder stringBuilder = new StringBuilder();
47355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 1026; i++) {
47365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            stringBuilder.append('a');
47375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
47395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\p{Lower}+");
47405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(pattern, 1026);
474156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals(stringBuilder.toString().length(), result.length());
47425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.toString(), result);
47435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Test the situation when input length is longer than buffer size and
47455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // set horizon to buffer size.
47465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
47475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 1026; i++) {
47485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            stringBuilder.append('a');
47495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
47515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\p{Lower}+");
47525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(pattern, 1022);
47535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1022, result.length());
47545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.subSequence(0, 1022), result);
47555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Test the situation, under which pattern is clipped by buffer.
47575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
47585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 1022; i++) {
47595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            stringBuilder.append(' ');
47605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append("bbc");
47625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1025, stringBuilder.length());
47635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
47645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("bbc");
47655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(pattern, 1025);
47665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(3, result.length());
47675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.subSequence(1022, 1025), result);
47685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
47705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 1026; i++) {
47715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            stringBuilder.append('a');
47725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
47745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pattern = Pattern.compile("\\p{Lower}+");
47755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(pattern, 0);
47765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.toString(), result);
477756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
47785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
47795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int i = 0; i < 10240; i++) {
47805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            stringBuilder.append('-');
47815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
47825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.replace(0, 2, "aa");
47835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
47845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("aa"), 0);
47855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aa", result);
478656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
47875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aaaa");
47885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findWithinHorizon(Pattern.compile("a*"), 0);
47895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("aaaa", result);
47905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
479156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
47925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
47935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#findInLine(Pattern)
47945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
47955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_findInLine_LPattern() {
47965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
47975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Scanner s = new Scanner("");
47985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
47995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findInLine((Pattern) null);
480056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
480156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
48025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
48035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String result = s.findInLine(Pattern.compile("^"));
4804a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals(null, result);
48055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("$"));
4806a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals(null, result);
48075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
48095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * When we use the operation of findInLine(Pattern), the match region
48105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * should not span the line separator.
48115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
48125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aa\nb.b");
48135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("a\nb*"));
48145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
48155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("aa\nbb.b");
48175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("\\."));
48185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
48195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("abcd1234test\n");
48215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("\\p{Lower}+"));
48225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("abcd", result);
4823a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        MatchResult matchResult = s.match();
48245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
48255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.end());
48265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("\\p{Digit}{5}"));
48285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
48295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
48305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            matchResult = s.match();
483156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
483256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
48335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
48345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
48355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.end());
48365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("\\p{Lower}+"));
48385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
48395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(8, matchResult.start());
48415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(12, matchResult.end());
48425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        char[] chars = new char[2048];
48445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
48455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder stringBuilder = new StringBuilder();
48465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
48475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append("1234");
48485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
48495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("\\p{Digit}+"));
48505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1234", result);
48515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2048, matchResult.start());
48535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2052, matchResult.end());
48545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
48565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
48575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
48585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findInLine((Pattern) null);
485956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
486056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
48615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
48625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test1234\n1234 test");
48645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("test"));
48655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
48665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
48685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.end());
48695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        int number = s.nextInt();
48715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1234, number);
48725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.start());
48745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(8, matchResult.end());
48755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.next();
48775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("1234", result);
48785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(9, matchResult.start());
48805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(13, matchResult.end());
48815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
48825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile("test"));
48835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
48845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
48855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(14, matchResult.start());
48865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(18, matchResult.end());
488756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
48885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\u0085\ntest");
48895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine("est");
48905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("est", result);
4891a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        // First consume input upto U+0085(a line separator)
4892a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertTrue(s.hasNextLine());
4893a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals("", s.nextLine());
4894a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        // Then consume input upto the "\n"
4895a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertTrue(s.hasNextLine());
4896a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals("", s.nextLine());
4897a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        // The next line will be "test", which should match.
4898a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals("est", s.findInLine("est"));
489956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
49005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\ntest");
49015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine("est");
49025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("est", result);
49035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine("est");
4904a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertNull(result);
49055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
49065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\n123\ntest");
49075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine("est");
49085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("est", result);
49095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine("est");
49105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNull(result);
4911a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        s.nextLine();
4912a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        result = s.findInLine("est");
4913a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertNull(result);
4914a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        s.nextLine();
4915a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        result = s.findInLine("est");
4916a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath        assertEquals("est", result);
4917a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath
491856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
49195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner( "   *\n");
49205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.findInLine(Pattern.compile( "^\\s*(?:\\*(?=[^/]))"));
49215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("   *", result);
49225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
49235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
492456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_findInLine_LString_NPEs() {
49255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
49265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
49275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findInLine((String) null);
492856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
492956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
49305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
49315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
49325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
49335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findInLine((String) null);
493456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
493556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
49365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
49375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
49385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.findInLine("test");
493956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
494056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
49415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
49425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
494356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
494456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void test_findInLine_LString() {
494556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      Scanner s = new Scanner("");
494656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      String result = s.findInLine("^");
4947a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      assertNull(result);
494856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
494956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("$");
4950a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      assertNull(result);
495156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
495256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      // When we use the operation of findInLine(Pattern), the match region
495356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      // should not span the line separator.
495456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("aa\nb.b");
495556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("a\nb*");
495656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertNull(result);
495756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
495856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("aa\nbb.b");
495956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("\\.");
496056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertNull(result);
496156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
496256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("abcd1234test\n");
496356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("\\p{Lower}+");
496456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("abcd", result);
4965a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      MatchResult matchResult = s.match();
496656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(0, matchResult.start());
496756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(4, matchResult.end());
496856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
496956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("\\p{Digit}{5}");
497056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertNull(result);
497156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      try {
497256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        matchResult = s.match();
497356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        fail();
497456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      } catch (IllegalStateException expected) {
497556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      }
497656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(0, matchResult.start());
497756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(4, matchResult.end());
497856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
497956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("\\p{Lower}+");
498056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("test", result);
498156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
498256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(8, matchResult.start());
498356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(12, matchResult.end());
498456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
498556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      char[] chars = new char[2048];
498656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      Arrays.fill(chars, 'a');
498756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      StringBuilder stringBuilder = new StringBuilder();
498856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      stringBuilder.append(chars);
498956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      stringBuilder.append("1234");
499056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner(stringBuilder.toString());
499156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("\\p{Digit}+");
499256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("1234", result);
499356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
499456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(2048, matchResult.start());
499556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(2052, matchResult.end());
499656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
499756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("test1234\n1234 test");
499856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("test");
499956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("test", result);
500056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
500156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(0, matchResult.start());
500256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(4, matchResult.end());
500356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
500456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      int number = s.nextInt();
500556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(1234, number);
500656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
500756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(4, matchResult.start());
500856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(8, matchResult.end());
500956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
501056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.next();
501156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("1234", result);
501256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
501356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(9, matchResult.start());
501456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(13, matchResult.end());
501556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
501656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("test");
501756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("test", result);
501856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      matchResult = s.match();
501956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(14, matchResult.start());
502056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals(18, matchResult.end());
502156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
502256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("test\u0085\ntest");
502356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
502456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("est", result);
502556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
5026a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      assertNull(result);
502756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
502856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("test\ntest");
502956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
503056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("est", result);
503156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
5032a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      assertNull(result);
503356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
503456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      s = new Scanner("test\n123\ntest");
503556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
503656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      assertEquals("est", result);
503756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes      result = s.findInLine("est");
5038a6a9deaf2fef181b3b47a1b24b023f3506ad1303Narayan Kamath      assertNull(result);
503956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    }
504056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
50415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
50425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#skip(Pattern)
50435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
50445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_skip_LPattern() {
50455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
50465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip((String) null);
504856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
504956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
50505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
505156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
50525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // If pattern does not match, NoSuchElementException will be thrown out.
50535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("1234");
50545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip(Pattern.compile("\\p{Lower}"));
505656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
505756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
50585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
50595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Then, no matchResult will be thrown out.
50605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
506256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
506356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
50645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
50655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
50665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile("\\p{Digit}"));
50675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult matchResult = s.match();
50685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
50695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
50705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
50715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile("\\p{Digit}+"));
50725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
50735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.start());
50745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.end());
50755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
50765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
50775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip(Pattern.compile("test"));
507956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
508056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
50815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
50825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
50835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MockStringReader2Read reader = new MockStringReader2Read("test");
50845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(reader);
50855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip(Pattern.compile("\\p{Digit}{4}"));
508756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
508856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
50895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
50905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
50915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
509256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
509356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
50945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
50955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile("\\p{Digit}{3}\\p{Lower}"));
50965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
50975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
50985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(4, matchResult.end());
50995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
51015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
51025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip((Pattern) null);
510356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
510456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
51055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
510656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder stringBuilder = new StringBuilder();
51085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        char [] chars = new char[1024];
51095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
51105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
51115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append('3');
51125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
51135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile("\\p{Lower}+\\p{Digit}"));
51145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
51155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
51165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1025, matchResult.end());
511756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Large amount of input may be cached
51195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        chars = new char[102400];
51205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
51215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
51225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
51235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
51245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile(".*"));
51255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
51265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
51275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102400, matchResult.end());
512856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // skip something without risking a NoSuchElementException
51305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.skip(Pattern.compile("[ \t]*"));
51315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
51325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102400, matchResult.start());
51335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(102400, matchResult.end());
51345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
51355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
51375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#skip(String)
51385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
51395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_skip_LString() {
51405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
51415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
51425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.skip((String) null);
514356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
514456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NullPointerException expected) {
51455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
51465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
514756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
51495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
51505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextDouble()
51515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
51525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextDouble() throws IOException {
51535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
51545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
51555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.0, s.nextDouble());
51565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(456.0, s.nextDouble());
51575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.4, s.nextDouble());
51585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0.123, s.nextDouble());
51595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
51605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextDouble();
516156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
516256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
51635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
51645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
51665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
51675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123.4, s.nextDouble());
51685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-456.7, s.nextDouble());
51695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123456.789, s.nextDouble());
51705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
51715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextDouble();
517256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
517356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
51745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
51755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
51775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
51785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
51795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1.234E12, s.nextDouble());
51805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-4.567E14, s.nextDouble());
51815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1.23456789E-5, s.nextDouble());
51825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN Infinity -Infinity");
51845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.NaN, s.nextDouble());
51855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
51865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.NEGATIVE_INFINITY, s.nextDouble());
518756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        //The following test case fails on RI
51895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s=new Scanner("\u221e");
51905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
51915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
51925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
51935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String str=String.valueOf(Double.MAX_VALUE*2);
51945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s=new Scanner(str);
51955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(Double.POSITIVE_INFINITY,s.nextDouble());
519656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
51975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
51985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
51995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
52005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
52015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
52025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.0, s.nextDouble());
52045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
52055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23.456, s.nextDouble());
52065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
52085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23.456, s.nextDouble());
52105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
52115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.0, s.nextDouble());
52125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7 23.456,7");
52145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.7, s.nextDouble());
52165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
52175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(23456.7, s.nextDouble());
52185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123.4");
52205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(-123.4, s.nextDouble());
52225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
522356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
52245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
52255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @throws IOException
52265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextBigDecimal()
52275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
52285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextBigDecimal() throws IOException {
52295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 45\u0666. 123.4 .123 ");
52305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123"), s.nextBigDecimal());
52325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("456"), s.nextBigDecimal());
52335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
52345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("0.123"), s.nextBigDecimal());
52355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
52365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
523756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
523856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
52395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
52405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
52425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
52445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-456.7"), s.nextBigDecimal());
52455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("123456.789"), s.nextBigDecimal());
52465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
52475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
524856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
524956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
52505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
52515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Scientific notation
52535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
52545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
52565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
52575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
52585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("NaN");
52605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
52615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextBigDecimal();
526256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
526356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InputMismatchException expected) {
52645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
52655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        /*
52675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * Different locale can only recognize corresponding locale sensitive
52685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         * string. ',' is used in many locales as group separator.
52695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes         */
52705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456 23,456");
52715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
52735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
52745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
52755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23.456 23.456");
52775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
52795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.GERMANY);
52805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
52815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("23,456.7");
52835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("23456.7"), s.nextBigDecimal());
52855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("-123.4");
52875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.useLocale(Locale.ENGLISH);
52885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(new BigDecimal("-123.4"), s.nextBigDecimal());
52895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
52905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
52925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#toString()
52935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
52945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_toString() {
52955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test");
52965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertNotNull(s.toString());
52975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
52985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
52995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
53005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#nextLine()
53015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
53025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_nextLine() {
53035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
53045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
53055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
53065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.nextLine();
530756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
530856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
53095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
531056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
53115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\r\ntest");
53125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        String result = s.nextLine();
53135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
53145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult matchResult = s.match();
53155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(6, matchResult.end());
53175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u0085");
53195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
53215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
532456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
53255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u2028");
53265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
53285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
533156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
53325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u2029");
53335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
53355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
533856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
53395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
53405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
53415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            result = s.nextLine();
534256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
534356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (NoSuchElementException expected) {
53445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
53455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
53465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.match();
534756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
534856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
53495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
53505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("Ttest");
53525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("Ttest", result);
53545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, matchResult.end());
53575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\r\n");
53595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
53615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, matchResult.end());
53645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        char[] chars = new char[1024];
53665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
53675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder stringBuilder = new StringBuilder();
53685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
53695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        chars = new char[] { '+', '-' };
53705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
53715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append("\u2028");
53725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
53735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.toString().substring(0, 1026), result);
53765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1027, matchResult.end());
53795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53805c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        chars = new char[1023];
53815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
53825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder = new StringBuilder();
53835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
53845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append("\r\n");
53855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
53865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53875c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(stringBuilder.toString().substring(0, 1023), result);
53895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
53905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
53915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1025, matchResult.end());
53925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("  ");
53945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("  ", result);
53965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
53975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\n\n\n");
53985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
53995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
54005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, matchResult.end());
54035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, matchResult.start());
54065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(6, matchResult.end());
54075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
54085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\n\n\n");
54095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("", result);
54115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
54145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.start());
54175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2, matchResult.end());
541856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("123 test\n   ");
54205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        int value = s.nextInt();
54215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(123, value);
542256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(" test", result);
542556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\n ");
54275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54285c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals("test", result);
54295c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
54305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // Regression test for Harmony-4774
54315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        class CountReadable implements Readable {
54325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            int counter = 0;
54335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            public int read(CharBuffer charBuffer) throws IOException {
54345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                counter++;
54355c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                charBuffer.append("hello\n");
54365c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                return 6;
54375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            }
54385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
54395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        CountReadable cr = new CountReadable();
54405c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(cr);
54415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.nextLine();
54425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // We expect read() to be called only once, otherwise we see the problem
54435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // when reading from System.in described in Harmony-4774
54445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, cr.counter);
544556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        assertEquals("hello", result);
54465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
544756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54485c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    /**
54495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     * @tests java.util.Scanner#hasNextLine()
54505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes     */
54515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLine() {
54525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("");
54535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s.close();
54545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
54555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            s.hasNextLine();
545656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            fail();
545756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (IllegalStateException expected) {
54585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
545956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\r\ntest");
54615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        boolean result = s.hasNextLine();
54625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(result);
54635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        MatchResult matchResult = s.match();
54645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(6, matchResult.end());
54665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
54675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u0085");
54685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.hasNextLine();
54695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(result);
54705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54715c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
547356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u2028");
54755c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.hasNextLine();
54765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(result);
54775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54795c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
548056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54815c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\u2029");
54825c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.hasNextLine();
54835c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(result);
54845c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54855c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54865c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
548756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
54885c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("test\n");
54895c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLine());
54905c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
54915c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
54925c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(5, matchResult.end());
54935c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
54945c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        char[] chars = new char[2048];
54955c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Arrays.fill(chars, 'a');
54965c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        StringBuilder stringBuilder = new StringBuilder();
54975c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        stringBuilder.append(chars);
54985c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner(stringBuilder.toString());
54995c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        result = s.hasNextLine();
55005c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(result);
55015c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55025c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
55035c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
55045c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(2048, matchResult.end());
55055c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55065c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        s = new Scanner("\n\n\n");
55075c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLine());
55085c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
55095c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
55105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
55115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        // The scanner will not advance any input.
55135c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertTrue(s.hasNextLine());
55145c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        matchResult = s.match();
55155c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(0, matchResult.start());
55165c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertEquals(1, matchResult.end());
55175c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
55185c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55195c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    public void test_hasNextLine_sequence() throws IOException {
55205c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        final PipedInputStream pis = new PipedInputStream();
55215c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        final PipedOutputStream pos = new PipedOutputStream();
55225c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        final Scanner scanner = new Scanner(pis);
55235c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pis.connect(pos);
55245c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        final List<String> result = new ArrayList<String>();
55255c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        Thread thread = new Thread(new Runnable() {
55265c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            public void run() {
55275c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                while (scanner.hasNextLine()) {
552856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes                    String line = scanner.nextLine();
552956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes                    result.add(line);
55305c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                }
55315c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            }
55325c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        });
55335c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        thread.start();
55345c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        for (int index = 0; index < 5; index++) {
553556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            String line = "line" + index + "\n";
553656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            pos.write(line.getBytes());
55375c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            pos.flush();
55385c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            try {
55395c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes                Thread.sleep(1000);
554056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            } catch (InterruptedException ignored) {
55415c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            }
55425c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            assertEquals(index + 1, result.size());
55435c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
55445c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pis.close();
55455c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        pos.close();
55465c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
55475c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            thread.join(1000);
554856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (InterruptedException ignored) {
55495c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
55505c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        assertFalse(scanner.hasNextLine());
55515c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
55525c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55535c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    protected void setUp() throws Exception {
55545c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        super.setUp();
55555c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55565c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        server = new ServerSocket(0);
55575c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        address = new InetSocketAddress("127.0.0.1", server.getLocalPort());
55585c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55595c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        client = SocketChannel.open();
55605c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        client.connect(address);
55615c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        serverSocket = server.accept();
55625c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55635c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        os = serverSocket.getOutputStream();
55645c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
55655c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55665c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    protected void tearDown() throws Exception {
55675c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        super.tearDown();
55685c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes
55695c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
55705c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            serverSocket.close();
557156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (Exception ignored) {
55725c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
55735c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
55745c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            client.close();
557556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (Exception ignored) {
55765c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
55775c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        try {
55785c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes            server.close();
557956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        } catch (Exception ignored) {
558056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
558156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    }
558256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
558356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    // http://code.google.com/p/android/issues/detail?id=57050
558456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes    public void testPerformance() throws Exception {
558556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        int count = 100000;
558656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
558756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
558856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(baos));
558956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        for (int i = 0; i < count; ++i) {
559056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            out.write(Integer.toString(123) + " ");
559156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
559256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        out.close();
559356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
559456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
559556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        bais.mark(-1);
559656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
559756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(bais)));
559856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        for (int i = 0; i < count; ++i) {
559956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            if (s.nextInt() != 123) {
560056ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes                fail();
560156ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            }
560256ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        }
560356ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes
560456ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        bais.reset();
560556ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        s = new Scanner(new BufferedReader(new InputStreamReader(bais)));
560656ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes        for (int i = 0; i < count; ++i) {
560756ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            if (s.nextFloat() != 123.0) {
560856ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes                fail();
560956ff05b16d4a82bc2386082409c78c3d94e0df01Elliott Hughes            }
56105c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes        }
56115c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes    }
56125c8452e1fca6a47ecbe71ac7f71e378b3be16ec7Elliott Hughes}
5613