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.runtime.java.lang.reflect;
032:
033: import junit.framework.*;
034: import java.lang.reflect.*;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _MemberTestCase extends TestCase {
040:
041: public static class CTest {
042: private CTest() {
043: }
044: }
045:
046: public void testIsSynthetic_constructor() throws Exception {
047: new CTest();
048: Member[] constructors = CTest.class.getDeclaredConstructors();
049: assertEquals(2, constructors.length);
050: if (constructors[0].isSynthetic()) {
051: assertFalse(constructors[1].isSynthetic());
052: } else {
053: assertTrue(constructors[1].isSynthetic());
054: }
055: }
056:
057: public void testIsSynthetic_field() throws Exception {
058: class FTest {
059: public int f;
060: }
061: Member[] fields = FTest.class.getDeclaredFields();
062: assertEquals(2, fields.length);
063: if (fields[0].isSynthetic()) {
064: assertFalse(fields[1].isSynthetic());
065: } else {
066: assertTrue(fields[1].isSynthetic());
067: }
068: }
069:
070: public void testIsSynthetic_method() throws Exception {
071: class MTest implements Comparable<String> {
072: public int compareTo(String o) {
073: return 0;
074: }
075: }
076: Member syntheticMember = MTest.class.getMethod("compareTo",
077: Object.class);
078: Member declaredMember = MTest.class.getMethod("compareTo",
079: String.class);
080: assertTrue(syntheticMember.isSynthetic());
081: assertFalse(declaredMember.isSynthetic());
082: }
083:
084: public void testIsSynthetic_other() throws Exception {
085: Member member = new Member() {
086: public Class<?> getDeclaringClass() {
087: return null;
088: }
089:
090: public String getName() {
091: return null;
092: }
093:
094: public int getModifiers() {
095: return 0;
096: }
097:
098: public boolean isSynthetic() {
099: return false;
100: }
101: };
102: assertFalse(member.isSynthetic());
103: }
104:
105: }
|