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 NullStringCatenationTest extends OgnlTestCase {
037: private static Root ROOT = new Root();
038:
039: private static Object[][] TESTS = {
040: // Null string catenation
041: { ROOT, "\"bar\" + null", "barnull" }, /* Catenate null to a string */
042: { ROOT, "\"bar\" + nullObject", "barnull" }, /* Catenate null to a string */
043: { ROOT, "20.56 + nullObject", NullPointerException.class }, /* Catenate null to a number */
044: };
045:
046: /*===================================================================
047: Public static methods
048: ===================================================================*/
049: public static TestSuite suite() {
050: TestSuite result = new TestSuite();
051:
052: for (int i = 0; i < TESTS.length; i++) {
053: if (TESTS[i].length == 3) {
054: result.addTest(new NullStringCatenationTest(
055: (String) TESTS[i][1], TESTS[i][0],
056: (String) TESTS[i][1], TESTS[i][2]));
057: } else {
058: if (TESTS[i].length == 4) {
059: result.addTest(new NullStringCatenationTest(
060: (String) TESTS[i][1], TESTS[i][0],
061: (String) TESTS[i][1], TESTS[i][2],
062: TESTS[i][3]));
063: } else {
064: if (TESTS[i].length == 5) {
065: result.addTest(new NullStringCatenationTest(
066: (String) TESTS[i][1], TESTS[i][0],
067: (String) TESTS[i][1], TESTS[i][2],
068: TESTS[i][3], TESTS[i][4]));
069: } else {
070: throw new RuntimeException(
071: "don't understand TEST format");
072: }
073: }
074: }
075: }
076: return result;
077: }
078:
079: /*===================================================================
080: Constructors
081: ===================================================================*/
082: public NullStringCatenationTest() {
083: super ();
084: }
085:
086: public NullStringCatenationTest(String name) {
087: super (name);
088: }
089:
090: public NullStringCatenationTest(String name, Object root,
091: String expressionString, Object expectedResult,
092: Object setValue, Object expectedAfterSetResult) {
093: super (name, root, expressionString, expectedResult, setValue,
094: expectedAfterSetResult);
095: }
096:
097: public NullStringCatenationTest(String name, Object root,
098: String expressionString, Object expectedResult,
099: Object setValue) {
100: super (name, root, expressionString, expectedResult, setValue);
101: }
102:
103: public NullStringCatenationTest(String name, Object root,
104: String expressionString, Object expectedResult) {
105: super(name, root, expressionString, expectedResult);
106: }
107: }
|