001: //--------------------------------------------------------------------------
002: // Copyright (c) 2004, Drew Davidson and Luke Blanshard
003: // All rights reserved.
004: //
005: // Redistribution and use in source and binary forms, with or without
006: // modification, are permitted provided that the following conditions are
007: // met:
008: //
009: // Redistributions of source code must retain the above copyright notice,
010: // this list of conditions and the following disclaimer.
011: // Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: // Neither the name of the Drew Davidson nor the names of its contributors
015: // may be used to endorse or promote products derived from this software
016: // without specific prior written permission.
017: //
018: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
023: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
024: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
025: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
028: // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
029: // DAMAGE.
030: //--------------------------------------------------------------------------
031: package org.ognl.test;
032:
033: import junit.framework.TestSuite;
034: import org.ognl.test.objects.Root;
035:
036: public class SetterWithConversionTest extends OgnlTestCase {
037: private static Root ROOT = new Root();
038:
039: private static Object[][] TESTS = {
040: // Property set with conversion
041: { ROOT, "intValue", new Integer(0), new Double(6.5),
042: new Integer(6) },
043: { ROOT, "intValue", new Integer(6), new Double(1025.87645),
044: new Integer(1025) },
045: { ROOT, "intValue", new Integer(1025), "654",
046: new Integer(654) },
047: { ROOT, "stringValue", null, new Integer(25), "25" },
048: { ROOT, "stringValue", "25", new Float(100.25), "100.25" },
049: { ROOT, "anotherStringValue", "foo", new Integer(0), "0" },
050: { ROOT, "anotherStringValue", "0", new Double(0.5), "0.5" },
051: { ROOT, "anotherIntValue", new Integer(123), "5",
052: new Integer(5) },
053: { ROOT, "anotherIntValue", new Integer(5),
054: new Double(100.25), new Integer(100) },
055: // { ROOT, "anotherIntValue", new Integer(100), new String[] { "55" }, new Integer(55)},
056: // { ROOT, "yetAnotherIntValue", new Integer(46), new String[] { "55" }, new Integer(55)},
057:
058: };
059:
060: /*===================================================================
061: Public static methods
062: ===================================================================*/
063: public static TestSuite suite() {
064: TestSuite result = new TestSuite();
065:
066: for (int i = 0; i < TESTS.length; i++) {
067: if (TESTS[i].length == 3) {
068: result.addTest(new SetterWithConversionTest(
069: (String) TESTS[i][1], TESTS[i][0],
070: (String) TESTS[i][1], TESTS[i][2]));
071: } else {
072: if (TESTS[i].length == 4) {
073: result.addTest(new SetterWithConversionTest(
074: (String) TESTS[i][1], TESTS[i][0],
075: (String) TESTS[i][1], TESTS[i][2],
076: TESTS[i][3]));
077: } else {
078: if (TESTS[i].length == 5) {
079: result.addTest(new SetterWithConversionTest(
080: (String) TESTS[i][1], TESTS[i][0],
081: (String) TESTS[i][1], TESTS[i][2],
082: TESTS[i][3], TESTS[i][4]));
083: } else {
084: throw new RuntimeException(
085: "don't understand TEST format");
086: }
087: }
088: }
089: }
090: return result;
091: }
092:
093: /*===================================================================
094: Constructors
095: ===================================================================*/
096: public SetterWithConversionTest() {
097: super ();
098: }
099:
100: public SetterWithConversionTest(String name) {
101: super (name);
102: }
103:
104: public SetterWithConversionTest(String name, Object root,
105: String expressionString, Object expectedResult,
106: Object setValue, Object expectedAfterSetResult) {
107: super (name, root, expressionString, expectedResult, setValue,
108: expectedAfterSetResult);
109: }
110:
111: public SetterWithConversionTest(String name, Object root,
112: String expressionString, Object expectedResult,
113: Object setValue) {
114: super (name, root, expressionString, expectedResult, setValue);
115: }
116:
117: public SetterWithConversionTest(String name, Object root,
118: String expressionString, Object expectedResult) {
119: super(name, root, expressionString, expectedResult);
120: }
121: }
|