001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime13.v14.java.lang;
032:
033: import java.util.*;
034: import junit.framework.TestCase;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _CharSequenceTestCase extends TestCase {
040:
041: private List<Object> charSequenceList = Arrays.<Object> asList(
042: "abc", new StringBuffer("abc"), new MyCharSequence("abc"));
043: private Object integer = 123;
044:
045: private static class MyCharSequence implements CharSequence {
046:
047: private String s;
048:
049: public MyCharSequence(String s) {
050: this .s = s;
051: }
052:
053: public int length() {
054: return s.length();
055: }
056:
057: public char charAt(int index) {
058: return s.charAt(index);
059: }
060:
061: public CharSequence subSequence(int start, int end) {
062: return s.substring(start, end);
063: }
064: }
065:
066: public void testExecuteInstanceOfInstruction() throws Exception {
067: for (Object o : charSequenceList) {
068: assertTrue(o instanceof CharSequence);
069: }
070: assertFalse(integer instanceof CharSequence);
071: }
072:
073: public void testExecuteCheckCastInstruction() throws Exception {
074: for (Object o : charSequenceList) {
075: CharSequence charSequence = (CharSequence) o;
076: assertNotNull(charSequence);
077: }
078: try {
079: CharSequence charSequence = (CharSequence) integer;
080: assertNotNull(charSequence);
081: fail();
082: } catch (ClassCastException e) {
083: //ok
084: }
085: }
086:
087: public void testCharAt() throws Exception {
088: for (Object o : charSequenceList) {
089: assertEquals('b', ((CharSequence) o).charAt(1));
090: }
091: }
092:
093: public void testLength() throws Exception {
094: for (Object o : charSequenceList) {
095: assertEquals(3, ((CharSequence) o).length());
096: }
097: }
098:
099: public void testSubSequence() throws Exception {
100: for (Object o : charSequenceList) {
101: assertEquals("bc", ((CharSequence) o).subSequence(1, 3)
102: .toString());
103: }
104: }
105:
106: }
|