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.transformer;
032:
033: import junit.framework.TestCase;
034: import java.io.IOException;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class MirandaMethodsVisitorTestCase extends TestCase {
040:
041: public static interface GenericInterface<T> {
042: T getT();
043:
044: void setT(T t);
045: }
046:
047: public abstract static class BaseClass {
048: public String getT() {
049: return null;
050: }
051: }
052:
053: public static abstract class FirstAbstractClass implements
054: MirandaTestInterface {
055: public void justMethod() {
056: }
057: }
058:
059: public static abstract class SecondAbstractClass extends
060: FirstAbstractClass implements MirandaTestInterface {
061: public void justMethod() {
062: }
063: }
064:
065: public static abstract class ThirdAbstractClass extends
066: MirandaTestClass implements MirandaTestInterface {
067: public void justMethod() {
068: }
069: }
070:
071: public static abstract class FourthAbstractClass implements
072: GenericInterface<String> {
073: public void justMethod() {
074: }
075:
076: public void setT(String s) {
077: }
078: }
079:
080: public static abstract class FifthAbstractClass extends BaseClass
081: implements GenericInterface<String> {
082: public void justMethod() {
083: }
084: }
085:
086: public static abstract class SixthAbstractClass implements
087: GenericInterface {
088: public Object getT() {
089: return null;
090: }
091:
092: public void setT(Object o) {
093: }
094:
095: public void justMethod() {
096: }
097: }
098:
099: public static class FirstConcreteClass extends FirstAbstractClass {
100: public void method(StringBuilder builder) throws IOException {
101: }
102: }
103:
104: public static class SecondConcreteClass extends SecondAbstractClass {
105: public void method(StringBuilder builder) throws IOException {
106: }
107: }
108:
109: public static class ThirdConcreteClass extends ThirdAbstractClass {
110: public void method(StringBuilder builder) throws IOException {
111: }
112: }
113:
114: public static class FourthConcreteClass extends FourthAbstractClass {
115: public String getT() {
116: return null;
117: }
118: }
119:
120: public static class FifthConcreteClass extends FifthAbstractClass {
121: public void setT(String s) {
122: }
123: }
124:
125: public static class SixthConcreteClass extends SixthAbstractClass {
126: }
127:
128: public void testMirandaMethods() throws Exception {
129: MirandaTestInterface first = new FirstConcreteClass();
130: first.method(null);
131: MirandaTestInterface second = new SecondConcreteClass();
132: second.method(null);
133: String vmName = System.getProperty("java.vm.name");
134: if (vmName != null && !vmName.startsWith("IBM J9")) {
135: MirandaTestInterface third = new ThirdConcreteClass();
136: third.method(null);
137: }
138: GenericInterface<String> fourth = new FourthConcreteClass();
139: fourth.getT();
140: fourth.setT(null);
141: GenericInterface fifth = new FifthConcreteClass();
142: fifth.getT();
143: fifth.setT(null);
144: GenericInterface sixth = new SixthConcreteClass();
145: sixth.getT();
146: sixth.setT(null);
147: }
148:
149: public void testInheritedMethods() throws Exception {
150: FirstConcreteClass first = new FirstConcreteClass();
151: first.justMethod();
152: SecondConcreteClass second = new SecondConcreteClass();
153: second.justMethod();
154: ThirdConcreteClass third = new ThirdConcreteClass();
155: third.justMethod();
156: FourthConcreteClass fourth = new FourthConcreteClass();
157: fourth.justMethod();
158: FifthConcreteClass fifth = new FifthConcreteClass();
159: fifth.justMethod();
160: SixthConcreteClass sixth = new SixthConcreteClass();
161: sixth.justMethod();
162: }
163:
164: }
|