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 ognl.DefaultMemberAccess;
035: import org.ognl.test.objects.Root;
036:
037: public class PrivateAccessorTest extends OgnlTestCase {
038: private static Root ROOT = new Root();
039:
040: private static Object[][] TESTS = {
041: // Using private get/set methods
042: { ROOT, "getPrivateAccessorIntValue()", new Integer(67) }, /* Call private method */
043: { ROOT, "privateAccessorIntValue", new Integer(67) }, /* Implied private method */
044: { ROOT, "privateAccessorIntValue", new Integer(67),
045: new Integer(100) }, /* Implied private method */
046: { ROOT, "privateAccessorIntValue2", new Integer(67) }, /* Implied private method */
047: { ROOT, "privateAccessorIntValue2", new Integer(67),
048: new Integer(100) }, /* Implied private method */
049: { ROOT, "privateAccessorIntValue3", new Integer(67) }, /* Implied private method */
050: { ROOT, "privateAccessorIntValue3", new Integer(67),
051: new Integer(100) }, /* Implied private method */
052: { ROOT, "privateAccessorBooleanValue", Boolean.TRUE }, /* Implied private method */
053: { ROOT, "privateAccessorBooleanValue", Boolean.TRUE,
054: Boolean.FALSE }, /* Implied private method */
055: };
056:
057: /*===================================================================
058: Public static methods
059: ===================================================================*/
060: public static TestSuite suite() {
061: TestSuite result = new TestSuite();
062:
063: for (int i = 0; i < TESTS.length; i++) {
064: if (TESTS[i].length == 3) {
065: result.addTest(new PrivateAccessorTest(
066: (String) TESTS[i][1], TESTS[i][0],
067: (String) TESTS[i][1], TESTS[i][2]));
068: } else {
069: if (TESTS[i].length == 4) {
070: result.addTest(new PrivateAccessorTest(
071: (String) TESTS[i][1], TESTS[i][0],
072: (String) TESTS[i][1], TESTS[i][2],
073: TESTS[i][3]));
074: } else {
075: if (TESTS[i].length == 5) {
076: result.addTest(new PrivateAccessorTest(
077: (String) TESTS[i][1], TESTS[i][0],
078: (String) TESTS[i][1], TESTS[i][2],
079: TESTS[i][3], TESTS[i][4]));
080: } else {
081: throw new RuntimeException(
082: "don't understand TEST format");
083: }
084: }
085: }
086: }
087: return result;
088: }
089:
090: /*===================================================================
091: Constructors
092: ===================================================================*/
093: public PrivateAccessorTest() {
094: super ();
095: }
096:
097: public PrivateAccessorTest(String name) {
098: super (name);
099: }
100:
101: public PrivateAccessorTest(String name, Object root,
102: String expressionString, Object expectedResult,
103: Object setValue, Object expectedAfterSetResult) {
104: super (name, root, expressionString, expectedResult, setValue,
105: expectedAfterSetResult);
106: }
107:
108: public PrivateAccessorTest(String name, Object root,
109: String expressionString, Object expectedResult,
110: Object setValue) {
111: super (name, root, expressionString, expectedResult, setValue);
112: }
113:
114: public PrivateAccessorTest(String name, Object root,
115: String expressionString, Object expectedResult) {
116: super (name, root, expressionString, expectedResult);
117: }
118:
119: /*===================================================================
120: Overridden methods
121: ===================================================================*/
122: public void setUp() {
123: super .setUp();
124: context.setMemberAccess(new DefaultMemberAccess(true));
125: }
126: }
|