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.tests;
032:
033: import java.math.BigDecimal;
034: import java.util.*;
035: import junit.framework.TestCase;
036:
037: /**
038: * @author Taras Puchko
039: */
040: public class CustomBackportTestCase extends TestCase {
041:
042: public void testReplacement() {
043: if (isCustomBackport()) {
044: Exception exception = new UnknownFormatFlagsException("abc");
045: assertEquals(DuplicateFormatFlagsException.class, exception
046: .getClass().getSuperclass());
047: }
048: }
049:
050: public void testFields() {
051: assertEquals(1, BigDecimal.ONE.intValue());
052: if (isCustomBackport()) {
053: assertEquals(1000, BigDecimal.ZERO.intValue());
054: }
055: }
056:
057: public void testMethods() {
058: assertEquals("[1, 2, 3]", Arrays
059: .toString(new int[] { 1, 2, 3 }));
060: if (isCustomBackport()) {
061: assertEquals("[TRUE, FALSE, TRUE]", Arrays
062: .toString(new boolean[] { true, false, true }));
063: }
064: }
065:
066: public void testConvertors() {
067: assertEquals(10, new BigDecimal(10L).intValue());
068: if (isCustomBackport()) {
069: assertEquals(11, new BigDecimal(10).intValue());
070: }
071: }
072:
073: public void testBuilders_1() {
074: TestBean bean = new TestBean(true, 'L', (byte) 12, (short) 10,
075: 1234567, 0.5f, 12345670L, 123.45, "XYZ");
076: assertEquals(true, bean.isVisible());
077: assertEquals('L', bean.getSign());
078: assertEquals((byte) 12, bean.getCode());
079: assertEquals((short) 10, bean.getWidth());
080: assertEquals(1234567, bean.getHeight());
081: assertEquals(0.5f, bean.getOpacity());
082: assertEquals(12345670L, bean.getArea());
083: assertEquals(123.45, bean.getWeight());
084: assertEquals("XYZ", bean.getName());
085: if (isCustomBackport()) {
086: assertEquals("reverse", bean.getDirection());
087: assertEquals("initialized", bean.getState());
088: } else {
089: assertEquals("right", bean.getDirection());
090: assertNull(bean.getState());
091: }
092: }
093:
094: public void testBuilders_2() {
095: TestBean bean = new TestBean("abc");
096: assertEquals("abc", bean.getState());
097: if (isCustomBackport()) {
098: assertEquals("B", bean.getDirection());
099: } else {
100: assertEquals("A", bean.getDirection());
101: }
102: }
103:
104: private boolean isCustomBackport() {
105: return Boolean
106: .getBoolean("net.sf.retrotranslator.tests.custom-backport");
107: }
108:
109: }
|