156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more 256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * contributor license agreements. See the NOTICE file distributed with 356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * this work for additional information regarding copyright ownership. 456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * (the "License"); you may not use this file except in compliance with 656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * the License. You may obtain a copy of the License at 756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 1056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Unless required by applicable law or agreed to in writing, software 1156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * See the License for the specific language governing permissions and 1456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * limitations under the License. 1556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 1656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 17e5fea3d504609d22337a5311d3ce0e72314bceeeNarayan Kamathpackage org.apache.harmony.tests.java.nio.charset; 1856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 1956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.BufferOverflowException; 2056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.BufferUnderflowException; 2156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.charset.CoderResult; 2256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.charset.MalformedInputException; 2356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.charset.UnmappableCharacterException; 2456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport junit.framework.TestCase; 2656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/** 2856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test class java.nio.charset.CoderResult. 2956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughespublic class CoderResultTest extends TestCase { 3156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 3256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 3356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @see TestCase#setUp() 3456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected void setUp() throws Exception { 3656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes super.setUp(); 3756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 3856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 3956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 4056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @see TestCase#tearDown() 4156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 4256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected void tearDown() throws Exception { 4356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes super.tearDown(); 4456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 4556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 4756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test the constant OVERFLOW and UNDERFLOW. 4856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 4956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testConstants() throws Exception { 5056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotSame(CoderResult.OVERFLOW, CoderResult.UNDERFLOW); 5156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.OVERFLOW); 5356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isError()); 5456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isMalformed()); 5556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isUnderflow()); 5656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isUnmappable()); 5756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.OVERFLOW.isOverflow()); 5856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.OVERFLOW.toString().indexOf("OVERFLOW") != -1); 5956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 6056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.OVERFLOW.throwException(); 6156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw BufferOverflowException"); 6256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (BufferOverflowException ex) { 6356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 6456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 6556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 6656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.OVERFLOW.length(); 6756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw UnsupportedOperationException"); 6856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (UnsupportedOperationException ex) { 6956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 7056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 7156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 7256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.UNDERFLOW); 7356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isError()); 7456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isMalformed()); 7556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.UNDERFLOW.isUnderflow()); 7656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isUnmappable()); 7756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isOverflow()); 7856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.UNDERFLOW.toString().indexOf("UNDERFLOW") != -1); 7956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 8056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.UNDERFLOW.throwException(); 8156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw BufferOverflowException"); 8256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (BufferUnderflowException ex) { 8356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 8456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 8556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 8656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.UNDERFLOW.length(); 8756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw UnsupportedOperationException"); 8856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (UnsupportedOperationException ex) { 8956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 9056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 9156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 9256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 9356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 9456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method isError(). 9556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 9656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 9756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testIsError() { 9856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isError()); 9956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isError()); 10056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.malformedForLength(1).isError()); 10156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.unmappableForLength(1).isError()); 10256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 10356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 10456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 10556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method isMalformed(). 10656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 10756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 10856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testIsMalformed() { 10956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isMalformed()); 11056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isMalformed()); 11156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.malformedForLength(1).isMalformed()); 11256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.unmappableForLength(1).isMalformed()); 11356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 11456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 11556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 11656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method isMalformed(). 11756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 11856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 11956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testIsUnmappable() { 12056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isUnmappable()); 12156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isUnmappable()); 12256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.malformedForLength(1).isUnmappable()); 12356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.unmappableForLength(1).isUnmappable()); 12456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 12556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 12656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 12756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method isOverflow(). 12856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 12956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 13056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testIsOverflow() { 13156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.UNDERFLOW.isOverflow()); 13256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.OVERFLOW.isOverflow()); 13356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.malformedForLength(1).isOverflow()); 13456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.unmappableForLength(1).isOverflow()); 13556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 13656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 13756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 13856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method isUnderflow(). 13956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 14056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 14156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testIsUnderflow() { 14256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.UNDERFLOW.isUnderflow()); 14356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.OVERFLOW.isUnderflow()); 14456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.malformedForLength(1).isUnderflow()); 14556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertFalse(CoderResult.unmappableForLength(1).isUnderflow()); 14656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 14756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 14856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 14956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method length(). 15056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 15156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 15256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testLength() { 15356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 15456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.UNDERFLOW.length(); 15556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw UnsupportedOperationException"); 15656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (UnsupportedOperationException ex) { 15756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 15856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 15956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 16056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.OVERFLOW.length(); 16156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw UnsupportedOperationException"); 16256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (UnsupportedOperationException ex) { 16356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 16456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 16556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 16656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(CoderResult.malformedForLength(1).length(), 1); 16756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(CoderResult.unmappableForLength(1).length(), 1); 16856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 16956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 17056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 17156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method malformedForLength(int). 17256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 17356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 17456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testMalformedForLength() { 17556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.malformedForLength(Integer.MAX_VALUE)); 17656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.malformedForLength(1)); 17756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertSame(CoderResult.malformedForLength(1), CoderResult 17856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .malformedForLength(1)); 17956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotSame(CoderResult.malformedForLength(1), CoderResult 18056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .unmappableForLength(1)); 18156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotSame(CoderResult.malformedForLength(2), CoderResult 18256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .malformedForLength(1)); 18356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 18456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.malformedForLength(-1); 18556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw IllegalArgumentException"); 18656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (IllegalArgumentException ex) { 18756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 18856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 18956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 19056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.malformedForLength(0); 19156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw IllegalArgumentException"); 19256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (IllegalArgumentException ex) { 19356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 19456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 19556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 19656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 19756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 19856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method unmappableForLength(int). 19956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 20056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 20156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testUnmappableForLength() { 20256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.unmappableForLength(Integer.MAX_VALUE)); 20356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotNull(CoderResult.unmappableForLength(1)); 20456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertSame(CoderResult.unmappableForLength(1), CoderResult 20556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .unmappableForLength(1)); 20656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertNotSame(CoderResult.unmappableForLength(2), CoderResult 20756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .unmappableForLength(1)); 20856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 20956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.unmappableForLength(-1); 21056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw IllegalArgumentException"); 21156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (IllegalArgumentException ex) { 21256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 21356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 21456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 21556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.unmappableForLength(0); 21656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw IllegalArgumentException"); 21756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (IllegalArgumentException ex) { 21856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 21956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 22056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 22156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 22256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 22356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method throwException(). 22456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 22556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 22656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testThrowException() throws Exception { 22756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 22856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.OVERFLOW.throwException(); 22956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw BufferOverflowException"); 23056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (BufferOverflowException ex) { 23156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 23256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 23356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 23456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.UNDERFLOW.throwException(); 23556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw BufferOverflowException"); 23656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (BufferUnderflowException ex) { 23756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // expected 23856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 23956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 24056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.malformedForLength(1).throwException(); 24156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw MalformedInputException"); 24256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (MalformedInputException ex) { 24356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(ex.getInputLength(), 1); 24456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 24556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes try { 24656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes CoderResult.unmappableForLength(1).throwException(); 24756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes fail("Should throw UnmappableCharacterException"); 24856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } catch (UnmappableCharacterException ex) { 24956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(ex.getInputLength(), 1); 25056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 25156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 25256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 25356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 25456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test method toString(). 25556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 25656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 25756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testToString() throws Exception { 25856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.OVERFLOW.toString().indexOf("OVERFLOW") != -1); 25956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.UNDERFLOW.toString().indexOf("UNDERFLOW") != -1); 26056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.malformedForLength(666).toString() 26156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes .indexOf("666") != -1); 26256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertTrue(CoderResult.unmappableForLength(666).toString().indexOf( 26356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes "666") != -1); 26456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 26556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes} 266