1994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes/* 2994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * Licensed to the Apache Software Foundation (ASF) under one or more 3994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * contributor license agreements. See the NOTICE file distributed with 4994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * this work for additional information regarding copyright ownership. 5994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 6994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * (the "License"); you may not use this file except in compliance with 7994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * the License. You may obtain a copy of the License at 8994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * 9994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 10994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * 11994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * Unless required by applicable law or agreed to in writing, software 12994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 13994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * See the License for the specific language governing permissions and 15994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * limitations under the License. 16994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes */ 17994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughespackage org.apache.harmony.tests.java.text; 18994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes 190cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffinimport java.io.InputStream; 200cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffinimport java.io.ObjectInputStream; 21994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughesimport java.text.DateFormat; 22994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughesimport java.text.ParseException; 23994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes 24994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes@SuppressWarnings("nls") 25994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughespublic class ParseExceptionTest extends junit.framework.TestCase { 26994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes 27994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes /** 28994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * @tests java.text.ParseException#ParseException(java.lang.String, int) 29994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes */ 30994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes public void test_ConstructorLjava_lang_StringI() { 31994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes try { 32994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes DateFormat df = DateFormat.getInstance(); 33994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes df.parse("HelloWorld"); 34994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes fail("ParseException not created/thrown."); 35994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } catch (ParseException e) { 36994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes // expected 37994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } 38994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } 39994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes 40994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes /** 41994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes * @tests java.text.ParseException#getErrorOffset() 42994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes */ 43994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes public void test_getErrorOffset() { 44994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes try { 45994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes DateFormat df = DateFormat.getInstance(); 46994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes df.parse("1999HelloWorld"); 47994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } catch (ParseException e) { 48994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes assertEquals("getErrorOffsetFailed.", 4, e.getErrorOffset()); 49994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } 50994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes } 510cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin 520cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin public void test_serialize() throws Exception { 530cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin try (InputStream inputStream = getClass().getResourceAsStream( 540cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin "/serialization/org/apache/harmony/tests/java/text/ParseException.ser"); 550cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin ObjectInputStream ois = new ObjectInputStream(inputStream)) { 560cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin 570cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin Object object = ois.readObject(); 580cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin assertTrue("Not a ParseException", object instanceof ParseException); 590cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin ParseException parseException = (ParseException) object; 600cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin assertEquals("fred", parseException.getMessage()); 610cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin assertEquals(4, parseException.getErrorOffset()); 620cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin } 630cda87167eea29bca620cd0abab1e40721c2d6baPaul Duffin } 64994e4e5ded616a100ca42b16cffa36aa9f595f64Elliott Hughes} 65