001: /* Licensed to the Apache Software Foundation (ASF) under one or more
002: * contributor license agreements. See the NOTICE file distributed with
003: * this work for additional information regarding copyright ownership.
004: * The ASF licenses this file to You under the Apache License, Version 2.0
005: * (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.harmony.nio.tests.java.nio;
018:
019: import java.nio.BufferOverflowException;
020: import java.nio.CharBuffer;
021: import java.nio.ReadOnlyBufferException;
022:
023: public class WrappedCharBufferTest2 extends ReadOnlyCharBufferTest {
024: protected static final String TEST_STRING = "123456789abcdef12345";
025:
026: protected void setUp() throws Exception {
027: super .setUp();
028: buf = CharBuffer.wrap(TEST_STRING);
029: baseBuf = buf;
030: }
031:
032: protected void tearDown() throws Exception {
033: super .tearDown();
034: baseBuf = null;
035: buf = null;
036: }
037:
038: public void testWrappedCharSequence_IllegalArg() {
039: String str = TEST_STRING;
040: try {
041: CharBuffer.wrap(str, -1, 0);
042: fail("Should throw Exception"); //$NON-NLS-1$
043: } catch (IndexOutOfBoundsException e) {
044: // expected
045: }
046: try {
047: CharBuffer.wrap(str, 21, 21);
048: fail("Should throw Exception"); //$NON-NLS-1$
049: } catch (IndexOutOfBoundsException e) {
050: // expected
051: }
052: try {
053: CharBuffer.wrap(str, 2, 1);
054: fail("Should throw Exception"); //$NON-NLS-1$
055: } catch (IndexOutOfBoundsException e) {
056: // expected
057: }
058: try {
059: CharBuffer.wrap(str, 0, 21);
060: fail("Should throw Exception"); //$NON-NLS-1$
061: } catch (IndexOutOfBoundsException e) {
062: // expected
063: }
064: try {
065: CharBuffer.wrap((String) null, -1, 21);
066: fail("Should throw Exception"); //$NON-NLS-1$
067: } catch (NullPointerException e) {
068: // expected
069: }
070: }
071:
072: public void testArray() {
073: try {
074: buf.array();
075: fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
076: } catch (UnsupportedOperationException e) {
077: }
078: }
079:
080: public void testPutcharArrayintint() {
081: char array[] = new char[1];
082: try {
083: buf.put(array, 0, array.length);
084: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
085: } catch (ReadOnlyBufferException e) {
086: // expected
087: }
088: try {
089: buf.put((char[]) null, 0, 1);
090: fail("Should throw NullPointerException"); //$NON-NLS-1$
091: } catch (NullPointerException e) {
092: // expected
093: }
094: try {
095: buf
096: .put(new char[buf.capacity() + 1], 0, buf
097: .capacity() + 1);
098: fail("Should throw BufferOverflowException"); //$NON-NLS-1$
099: } catch (BufferOverflowException e) {
100: // expected
101: }
102: try {
103: buf.put(array, -1, array.length);
104: fail("Should throw IndexOutOfBoundsException"); //$NON-NLS-1$
105: } catch (IndexOutOfBoundsException e) {
106: // expected
107: }
108: }
109:
110: public void testPutCharBuffer() {
111: CharBuffer other = CharBuffer.allocate(1);
112: try {
113: buf.put(other);
114: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
115: } catch (ReadOnlyBufferException e) {
116: // expected
117: }
118: try {
119: buf.put((CharBuffer) null);
120: fail("Should throw NullPointerException"); //$NON-NLS-1$
121: } catch (NullPointerException e) {
122: // expected
123: }
124: try {
125: buf.put(buf);
126: fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
127: } catch (IllegalArgumentException e) {
128: // expected
129: }
130: }
131: }
|