You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/14 15:18:36 UTC
svn commit: r1103095 [20/24] - in /incubator/ognl/trunk/src:
main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/
main/java/org/apache/commons/ognl/internal/
test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/...
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/MethodWithConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/MethodWithConversionTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/MethodWithConversionTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/MethodWithConversionTest.java Sat May 14 13:18:29 2011
@@ -22,21 +22,19 @@ package org.apache.commons.ognl.test;
import junit.framework.TestSuite;
import org.apache.commons.ognl.test.objects.Simple;
-public class MethodWithConversionTest extends OgnlTestCase
+public class MethodWithConversionTest
+ extends OgnlTestCase
{
private static Simple SIMPLE = new Simple();
private static Object[][] TESTS = {
- // Method call with conversion
- { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null },
- { SIMPLE, "stringValue", "10" },
- { SIMPLE, "stringValue", "10", new Character('x'), "x" },
- { SIMPLE, "setStringValue('x')", null }, // set by calling setStringValue() directly
- { SIMPLE, "floatValue", new Float(10.56) },
- { SIMPLE, "getValueIsTrue(rootValue)", Boolean.TRUE},
- { SIMPLE, "messages.format('Testing', one, two, three)", "blah" }
- };
+ // Method call with conversion
+ { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null }, { SIMPLE, "stringValue", "10" },
+ { SIMPLE, "stringValue", "10", new Character( 'x' ), "x" },
+ { SIMPLE, "setStringValue('x')", null }, // set by calling setStringValue() directly
+ { SIMPLE, "floatValue", new Float( 10.56 ) }, { SIMPLE, "getValueIsTrue(rootValue)", Boolean.TRUE },
+ { SIMPLE, "messages.format('Testing', one, two, three)", "blah" } };
/*
* =================================================================== Public static methods
@@ -46,20 +44,31 @@ public class MethodWithConversionTest ex
{
TestSuite result = new TestSuite();
- for(int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result.addTest(new MethodWithConversionTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new MethodWithConversionTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new MethodWithConversionTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new MethodWithConversionTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new MethodWithConversionTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new MethodWithConversionTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3],
+ TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -76,25 +85,25 @@ public class MethodWithConversionTest ex
super();
}
- public MethodWithConversionTest(String name)
+ public MethodWithConversionTest( String name )
{
- super(name);
+ super( name );
}
- public MethodWithConversionTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue, Object expectedAfterSetResult)
+ public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue, Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public MethodWithConversionTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue)
+ public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public MethodWithConversionTest(String name, Object root, String expressionString, Object expectedResult)
+ public MethodWithConversionTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NestedMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NestedMethodTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NestedMethodTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NestedMethodTest.java Sat May 14 13:18:29 2011
@@ -22,17 +22,17 @@ package org.apache.commons.ognl.test;
import junit.framework.TestSuite;
import org.apache.commons.ognl.test.objects.Component;
-public class NestedMethodTest extends OgnlTestCase
+public class NestedMethodTest
+ extends OgnlTestCase
{
private static Component COMPONENT = new Component();
private static Object[][] TESTS = {
- // Expression in a method call argument
- { COMPONENT, "toDisplay.pictureUrl", COMPONENT.getToDisplay().getPictureUrl() },
- { COMPONENT, "page.createRelativeAsset(toDisplay.pictureUrl)",
- COMPONENT.getPage().createRelativeAsset(COMPONENT.getToDisplay().getPictureUrl()) },
- };
+ // Expression in a method call argument
+ { COMPONENT, "toDisplay.pictureUrl", COMPONENT.getToDisplay().getPictureUrl() },
+ { COMPONENT, "page.createRelativeAsset(toDisplay.pictureUrl)",
+ COMPONENT.getPage().createRelativeAsset( COMPONENT.getToDisplay().getPictureUrl() ) }, };
/*
* =================================================================== Public static methods
@@ -42,20 +42,30 @@ public class NestedMethodTest extends Og
{
TestSuite result = new TestSuite();
- for(int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result.addTest(new NestedMethodTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new NestedMethodTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new NestedMethodTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new NestedMethodTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new NestedMethodTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new NestedMethodTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2], TESTS[i][3], TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -72,24 +82,24 @@ public class NestedMethodTest extends Og
super();
}
- public NestedMethodTest(String name)
+ public NestedMethodTest( String name )
{
- super(name);
+ super( name );
}
- public NestedMethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue,
- Object expectedAfterSetResult)
+ public NestedMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
+ Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public NestedMethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ public NestedMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public NestedMethodTest(String name, Object root, String expressionString, Object expectedResult)
+ public NestedMethodTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullHandlerTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullHandlerTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullHandlerTest.java Sat May 14 13:18:29 2011
@@ -23,17 +23,15 @@ import junit.framework.TestSuite;
import org.apache.commons.ognl.OgnlRuntime;
import org.apache.commons.ognl.test.objects.CorrectedObject;
-public class NullHandlerTest extends OgnlTestCase
+public class NullHandlerTest
+ extends OgnlTestCase
{
private static CorrectedObject CORRECTED = new CorrectedObject();
private static Object[][] TESTS = {
- // NullHandler
- { CORRECTED, "stringValue", "corrected" },
- { CORRECTED, "getStringValue()", "corrected" },
- { CORRECTED, "#root.stringValue", "corrected" },
- { CORRECTED, "#root.getStringValue()", "corrected" },
- };
+ // NullHandler
+ { CORRECTED, "stringValue", "corrected" }, { CORRECTED, "getStringValue()", "corrected" },
+ { CORRECTED, "#root.stringValue", "corrected" }, { CORRECTED, "#root.getStringValue()", "corrected" }, };
/*
* =================================================================== Public static methods
@@ -43,21 +41,30 @@ public class NullHandlerTest extends Ogn
{
TestSuite result = new TestSuite();
- for(int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result
- .addTest(new NullHandlerTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new NullHandlerTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new NullHandlerTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new NullHandlerTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new NullHandlerTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new NullHandlerTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2], TESTS[i][3], TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -74,25 +81,25 @@ public class NullHandlerTest extends Ogn
super();
}
- public NullHandlerTest(String name)
+ public NullHandlerTest( String name )
{
- super(name);
+ super( name );
}
- public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult, Object setValue,
- Object expectedAfterSetResult)
+ public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
+ Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult, Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult)
+ public NullHandlerTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
/*
@@ -103,6 +110,6 @@ public class NullHandlerTest extends Ogn
{
super.setUp();
_compileExpressions = false;
- OgnlRuntime.setNullHandler(CorrectedObject.class, new CorrectedObjectNullHandler("corrected"));
+ OgnlRuntime.setNullHandler( CorrectedObject.class, new CorrectedObjectNullHandler( "corrected" ) );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullStringCatenationTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullStringCatenationTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullStringCatenationTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NullStringCatenationTest.java Sat May 14 13:18:29 2011
@@ -22,48 +22,64 @@ package org.apache.commons.ognl.test;
import junit.framework.TestSuite;
import org.apache.commons.ognl.test.objects.Root;
-public class NullStringCatenationTest extends OgnlTestCase {
+public class NullStringCatenationTest
+ extends OgnlTestCase
+{
public static final String MESSAGE = "blarney";
private static Root ROOT = new Root();
- private static Object[][] TESTS = {
+ private static Object[][] TESTS =
+ {
// Null string catenation
- {ROOT, "\"bar\" + null", "barnull"}, // Catenate null to a string
- {ROOT, "\"bar\" + nullObject", "barnull"}, // Catenate null to a string
- {ROOT, "20.56 + nullObject", NullPointerException.class}, // Catenate null to a number
- {ROOT, "(true ? 'tabHeader' : '') + (false ? 'tabHeader' : '')", "tabHeader"},
- {ROOT, "theInt == 0 ? '5%' : theInt + '%'", "6%"},
- {ROOT, "'width:' + width + ';'", "width:238px;" },
- {ROOT, "theLong + '_' + index", "4_1"},
- {ROOT, "'javascript:' + @org.apache.commons.ognl.test.NullStringCatenationTest@MESSAGE", "javascript:blarney" },
- {ROOT, "printDelivery ? '' : 'javascript:deliverySelected(' + property.carrier + ',' + currentDeliveryId + ')'", "" },
- {ROOT, "bean2.id + '_' + theInt", "1_6" }
- };
+ { ROOT, "\"bar\" + null", "barnull" }, // Catenate null to a string
+ { ROOT, "\"bar\" + nullObject", "barnull" }, // Catenate null to a string
+ { ROOT, "20.56 + nullObject", NullPointerException.class }, // Catenate null to a number
+ { ROOT, "(true ? 'tabHeader' : '') + (false ? 'tabHeader' : '')", "tabHeader" },
+ { ROOT, "theInt == 0 ? '5%' : theInt + '%'", "6%" },
+ { ROOT, "'width:' + width + ';'", "width:238px;" },
+ { ROOT, "theLong + '_' + index", "4_1" },
+ { ROOT, "'javascript:' + @org.apache.commons.ognl.test.NullStringCatenationTest@MESSAGE",
+ "javascript:blarney" },
+ {
+ ROOT,
+ "printDelivery ? '' : 'javascript:deliverySelected(' + property.carrier + ',' + currentDeliveryId + ')'",
+ "" }, { ROOT, "bean2.id + '_' + theInt", "1_6" } };
/*
- * =================================================================== Public static methods
- * ===================================================================
- */
+ * =================================================================== Public static methods
+ * ===================================================================
+ */
public static TestSuite suite()
{
TestSuite result = new TestSuite();
- for (int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result.addTest(new NullStringCatenationTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new NullStringCatenationTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new NullStringCatenationTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new NullStringCatenationTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new NullStringCatenationTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new NullStringCatenationTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3],
+ TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -80,25 +96,25 @@ public class NullStringCatenationTest ex
super();
}
- public NullStringCatenationTest(String name)
+ public NullStringCatenationTest( String name )
{
- super(name);
+ super( name );
}
- public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue, Object expectedAfterSetResult)
+ public NullStringCatenationTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue, Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue)
+ public NullStringCatenationTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult)
+ public NullStringCatenationTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumberFormatExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumberFormatExceptionTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumberFormatExceptionTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumberFormatExceptionTest.java Sat May 14 13:18:29 2011
@@ -26,51 +26,67 @@ import org.apache.commons.ognl.test.obje
import java.math.BigDecimal;
import java.math.BigInteger;
-public class NumberFormatExceptionTest extends OgnlTestCase
+public class NumberFormatExceptionTest
+ extends OgnlTestCase
{
private static Simple SIMPLE = new Simple();
- private static Object[][] TESTS = {
- // NumberFormatException handling (default is to throw NumberFormatException on bad string conversions)
- { SIMPLE, "floatValue", new Float(0f), new Float(10f), new Float(10f) },
- { SIMPLE, "floatValue", new Float(10f), "x10x", OgnlException.class },
-
- { SIMPLE, "intValue", new Integer(0), new Integer(34), new Integer(34) },
- { SIMPLE, "intValue", new Integer(34), "foobar", OgnlException.class },
- { SIMPLE, "intValue", new Integer(34), "", OgnlException.class },
- { SIMPLE, "intValue", new Integer(34), " \t", OgnlException.class },
- { SIMPLE, "intValue", new Integer(34), " \t1234\t\t", new Integer(1234) },
-
- { SIMPLE, "bigIntValue", BigInteger.valueOf(0), BigInteger.valueOf(34), BigInteger.valueOf(34) },
- { SIMPLE, "bigIntValue", BigInteger.valueOf(34), null, null },
- { SIMPLE, "bigIntValue", null, "", OgnlException.class },
- { SIMPLE, "bigIntValue", null, "foobar", OgnlException.class },
-
- { SIMPLE, "bigDecValue", new BigDecimal(0.0), new BigDecimal(34.55), new BigDecimal(34.55) },
- { SIMPLE, "bigDecValue", new BigDecimal(34.55), null, null },
- { SIMPLE, "bigDecValue", null, "", OgnlException.class },
- { SIMPLE, "bigDecValue", null, "foobar", OgnlException.class }
-
- };
-
- /*===================================================================
- Public static methods
- ===================================================================*/
+ private static Object[][] TESTS = {
+ // NumberFormatException handling (default is to throw NumberFormatException on bad string conversions)
+ { SIMPLE, "floatValue", new Float( 0f ), new Float( 10f ), new Float( 10f ) },
+ { SIMPLE, "floatValue", new Float( 10f ), "x10x", OgnlException.class },
+
+ { SIMPLE, "intValue", new Integer( 0 ), new Integer( 34 ), new Integer( 34 ) },
+ { SIMPLE, "intValue", new Integer( 34 ), "foobar", OgnlException.class },
+ { SIMPLE, "intValue", new Integer( 34 ), "", OgnlException.class },
+ { SIMPLE, "intValue", new Integer( 34 ), " \t", OgnlException.class },
+ { SIMPLE, "intValue", new Integer( 34 ), " \t1234\t\t", new Integer( 1234 ) },
+
+ { SIMPLE, "bigIntValue", BigInteger.valueOf( 0 ), BigInteger.valueOf( 34 ), BigInteger.valueOf( 34 ) },
+ { SIMPLE, "bigIntValue", BigInteger.valueOf( 34 ), null, null },
+ { SIMPLE, "bigIntValue", null, "", OgnlException.class },
+ { SIMPLE, "bigIntValue", null, "foobar", OgnlException.class },
+
+ { SIMPLE, "bigDecValue", new BigDecimal( 0.0 ), new BigDecimal( 34.55 ), new BigDecimal( 34.55 ) },
+ { SIMPLE, "bigDecValue", new BigDecimal( 34.55 ), null, null },
+ { SIMPLE, "bigDecValue", null, "", OgnlException.class },
+ { SIMPLE, "bigDecValue", null, "foobar", OgnlException.class }
+
+ };
+
+ /*
+ * =================================================================== Public static methods
+ * ===================================================================
+ */
public static TestSuite suite()
{
- TestSuite result = new TestSuite();
+ TestSuite result = new TestSuite();
- for (int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result.addTest(new NumberFormatExceptionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new NumberFormatExceptionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new NumberFormatExceptionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new NumberFormatExceptionTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new NumberFormatExceptionTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new NumberFormatExceptionTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3],
+ TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -78,31 +94,34 @@ public class NumberFormatExceptionTest e
return result;
}
- /*===================================================================
- Constructors
- ===================================================================*/
- public NumberFormatExceptionTest()
- {
- super();
- }
+ /*
+ * =================================================================== Constructors
+ * ===================================================================
+ */
+ public NumberFormatExceptionTest()
+ {
+ super();
+ }
- public NumberFormatExceptionTest(String name)
- {
- super(name);
- }
+ public NumberFormatExceptionTest( String name )
+ {
+ super( name );
+ }
- public NumberFormatExceptionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ public NumberFormatExceptionTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue, Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public NumberFormatExceptionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ public NumberFormatExceptionTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public NumberFormatExceptionTest(String name, Object root, String expressionString, Object expectedResult)
+ public NumberFormatExceptionTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumericConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumericConversionTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumericConversionTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/NumericConversionTest.java Sat May 14 13:18:29 2011
@@ -26,189 +26,181 @@ import org.apache.commons.ognl.OgnlOps;
import java.math.BigDecimal;
import java.math.BigInteger;
-public class NumericConversionTest extends OgnlTestCase {
+public class NumericConversionTest
+ extends OgnlTestCase
+{
private static Object[][] TESTS = {
- /* To Integer.class */
- {"55", Integer.class, new Integer(55)},
- {new Integer(55), Integer.class, new Integer(55)},
- {new Double(55), Integer.class, new Integer(55)},
- {Boolean.TRUE, Integer.class, new Integer(1)},
- {new Byte((byte) 55), Integer.class, new Integer(55)},
- {new Character((char) 55), Integer.class, new Integer(55)},
- {new Short((short) 55), Integer.class, new Integer(55)},
- {new Long(55), Integer.class, new Integer(55)},
- {new Float(55), Integer.class, new Integer(55)},
- {new BigInteger("55"), Integer.class, new Integer(55)},
- {new BigDecimal("55"), Integer.class, new Integer(55)},
-
- /* To Double.class */
- {"55.1234", Double.class, new Double(55.1234)},
- {new Integer(55), Double.class, new Double(55)},
- {new Double(55.1234), Double.class, new Double(55.1234)},
- {Boolean.TRUE, Double.class, new Double(1)},
- {new Byte((byte) 55), Double.class, new Double(55)},
- {new Character((char) 55), Double.class, new Double(55)},
- {new Short((short) 55), Double.class, new Double(55)},
- {new Long(55), Double.class, new Double(55)},
- {new Float(55.1234), Double.class, new Double(55.1234), new Integer(4)},
- {new BigInteger("55"), Double.class, new Double(55)},
- {new BigDecimal("55.1234"), Double.class, new Double(55.1234)},
-
- /* To Boolean.class */
- {"true", Boolean.class, Boolean.TRUE},
- {new Integer(55), Boolean.class, Boolean.TRUE},
- {new Double(55), Boolean.class, Boolean.TRUE},
- {Boolean.TRUE, Boolean.class, Boolean.TRUE},
- {new Byte((byte) 55), Boolean.class, Boolean.TRUE},
- {new Character((char) 55), Boolean.class, Boolean.TRUE},
- {new Short((short) 55), Boolean.class, Boolean.TRUE},
- {new Long(55), Boolean.class, Boolean.TRUE},
- {new Float(55), Boolean.class, Boolean.TRUE},
- {new BigInteger("55"), Boolean.class, Boolean.TRUE},
- {new BigDecimal("55"), Boolean.class, Boolean.TRUE},
-
- /* To Byte.class */
- {"55", Byte.class, new Byte((byte) 55)},
- {new Integer(55), Byte.class, new Byte((byte) 55)},
- {new Double(55), Byte.class, new Byte((byte) 55)},
- {Boolean.TRUE, Byte.class, new Byte((byte) 1)},
- {new Byte((byte) 55), Byte.class, new Byte((byte) 55)},
- {new Character((char) 55), Byte.class, new Byte((byte) 55)},
- {new Short((short) 55), Byte.class, new Byte((byte) 55)},
- {new Long(55), Byte.class, new Byte((byte) 55)},
- {new Float(55), Byte.class, new Byte((byte) 55)},
- {new BigInteger("55"), Byte.class, new Byte((byte) 55)},
- {new BigDecimal("55"), Byte.class, new Byte((byte) 55)},
-
- /* To Character.class */
- {"55", Character.class, new Character((char) 55)},
- {new Integer(55), Character.class, new Character((char) 55)},
- {new Double(55), Character.class, new Character((char) 55)},
- {Boolean.TRUE, Character.class, new Character((char) 1)},
- {new Byte((byte) 55), Character.class, new Character((char) 55)},
- {new Character((char) 55), Character.class, new Character((char) 55)},
- {new Short((short) 55), Character.class, new Character((char) 55)},
- {new Long(55), Character.class, new Character((char) 55)},
- {new Float(55), Character.class, new Character((char) 55)},
- {new BigInteger("55"), Character.class, new Character((char) 55)},
- {new BigDecimal("55"), Character.class, new Character((char) 55)},
-
- /* To Short.class */
- {"55", Short.class, new Short((short) 55)},
- {new Integer(55), Short.class, new Short((short) 55)},
- {new Double(55), Short.class, new Short((short) 55)},
- {Boolean.TRUE, Short.class, new Short((short) 1)},
- {new Byte((byte) 55), Short.class, new Short((short) 55)},
- {new Character((char) 55), Short.class, new Short((short) 55)},
- {new Short((short) 55), Short.class, new Short((short) 55)},
- {new Long(55), Short.class, new Short((short) 55)},
- {new Float(55), Short.class, new Short((short) 55)},
- {new BigInteger("55"), Short.class, new Short((short) 55)},
- {new BigDecimal("55"), Short.class, new Short((short) 55)},
-
- /* To Long.class */
- {"55", Long.class, new Long(55)},
- {new Integer(55), Long.class, new Long(55)},
- {new Double(55), Long.class, new Long(55)},
- {Boolean.TRUE, Long.class, new Long(1)},
- {new Byte((byte) 55), Long.class, new Long(55)},
- {new Character((char) 55), Long.class, new Long(55)},
- {new Short((short) 55), Long.class, new Long(55)},
- {new Long(55), Long.class, new Long(55)},
- {new Float(55), Long.class, new Long(55)},
- {new BigInteger("55"), Long.class, new Long(55)},
- {new BigDecimal("55"), Long.class, new Long(55)},
-
- /* To Float.class */
- {"55.1234", Float.class, new Float(55.1234)},
- {new Integer(55), Float.class, new Float(55)},
- {new Double(55.1234), Float.class, new Float(55.1234)},
- {Boolean.TRUE, Float.class, new Float(1)},
- {new Byte((byte) 55), Float.class, new Float(55)},
- {new Character((char) 55), Float.class, new Float(55)},
- {new Short((short) 55), Float.class, new Float(55)},
- {new Long(55), Float.class, new Float(55)},
- {new Float(55.1234), Float.class, new Float(55.1234)},
- {new BigInteger("55"), Float.class, new Float(55)},
- {new BigDecimal("55.1234"), Float.class, new Float(55.1234)},
-
- /* To BigInteger.class */
- {"55", BigInteger.class, new BigInteger("55")},
- {new Integer(55), BigInteger.class, new BigInteger("55")},
- {new Double(55), BigInteger.class, new BigInteger("55")},
- {Boolean.TRUE, BigInteger.class, new BigInteger("1")},
- {new Byte((byte) 55), BigInteger.class, new BigInteger("55")},
- {new Character((char) 55), BigInteger.class, new BigInteger("55")},
- {new Short((short) 55), BigInteger.class, new BigInteger("55")},
- {new Long(55), BigInteger.class, new BigInteger("55")},
- {new Float(55), BigInteger.class, new BigInteger("55")},
- {new BigInteger("55"), BigInteger.class, new BigInteger("55")},
- {new BigDecimal("55"), BigInteger.class, new BigInteger("55")},
-
- /* To BigDecimal.class */
- {"55.1234", BigDecimal.class, new BigDecimal("55.1234")},
- {new Integer(55), BigDecimal.class, new BigDecimal("55")},
- {new Double(55.1234), BigDecimal.class, new BigDecimal("55.1234"), new Integer(4)},
- {Boolean.TRUE, BigDecimal.class, new BigDecimal("1")},
- {new Byte((byte) 55), BigDecimal.class, new BigDecimal("55")},
- {new Character((char) 55), BigDecimal.class, new BigDecimal("55")},
- {new Short((short) 55), BigDecimal.class, new BigDecimal("55")},
- {new Long(55), BigDecimal.class, new BigDecimal("55")},
- {new Float(55.1234), BigDecimal.class, new BigDecimal("55.1234"), new Integer(4)},
- {new BigInteger("55"), BigDecimal.class, new BigDecimal("55")},
- {new BigDecimal("55.1234"), BigDecimal.class, new BigDecimal("55.1234")},
- };
+ /* To Integer.class */
+ { "55", Integer.class, new Integer( 55 ) }, { new Integer( 55 ), Integer.class, new Integer( 55 ) },
+ { new Double( 55 ), Integer.class, new Integer( 55 ) }, { Boolean.TRUE, Integer.class, new Integer( 1 ) },
+ { new Byte( (byte) 55 ), Integer.class, new Integer( 55 ) },
+ { new Character( (char) 55 ), Integer.class, new Integer( 55 ) },
+ { new Short( (short) 55 ), Integer.class, new Integer( 55 ) },
+ { new Long( 55 ), Integer.class, new Integer( 55 ) }, { new Float( 55 ), Integer.class, new Integer( 55 ) },
+ { new BigInteger( "55" ), Integer.class, new Integer( 55 ) },
+ { new BigDecimal( "55" ), Integer.class, new Integer( 55 ) },
+
+ /* To Double.class */
+ { "55.1234", Double.class, new Double( 55.1234 ) }, { new Integer( 55 ), Double.class, new Double( 55 ) },
+ { new Double( 55.1234 ), Double.class, new Double( 55.1234 ) },
+ { Boolean.TRUE, Double.class, new Double( 1 ) }, { new Byte( (byte) 55 ), Double.class, new Double( 55 ) },
+ { new Character( (char) 55 ), Double.class, new Double( 55 ) },
+ { new Short( (short) 55 ), Double.class, new Double( 55 ) },
+ { new Long( 55 ), Double.class, new Double( 55 ) },
+ { new Float( 55.1234 ), Double.class, new Double( 55.1234 ), new Integer( 4 ) },
+ { new BigInteger( "55" ), Double.class, new Double( 55 ) },
+ { new BigDecimal( "55.1234" ), Double.class, new Double( 55.1234 ) },
+
+ /* To Boolean.class */
+ { "true", Boolean.class, Boolean.TRUE }, { new Integer( 55 ), Boolean.class, Boolean.TRUE },
+ { new Double( 55 ), Boolean.class, Boolean.TRUE }, { Boolean.TRUE, Boolean.class, Boolean.TRUE },
+ { new Byte( (byte) 55 ), Boolean.class, Boolean.TRUE },
+ { new Character( (char) 55 ), Boolean.class, Boolean.TRUE },
+ { new Short( (short) 55 ), Boolean.class, Boolean.TRUE }, { new Long( 55 ), Boolean.class, Boolean.TRUE },
+ { new Float( 55 ), Boolean.class, Boolean.TRUE }, { new BigInteger( "55" ), Boolean.class, Boolean.TRUE },
+ { new BigDecimal( "55" ), Boolean.class, Boolean.TRUE },
+
+ /* To Byte.class */
+ { "55", Byte.class, new Byte( (byte) 55 ) }, { new Integer( 55 ), Byte.class, new Byte( (byte) 55 ) },
+ { new Double( 55 ), Byte.class, new Byte( (byte) 55 ) }, { Boolean.TRUE, Byte.class, new Byte( (byte) 1 ) },
+ { new Byte( (byte) 55 ), Byte.class, new Byte( (byte) 55 ) },
+ { new Character( (char) 55 ), Byte.class, new Byte( (byte) 55 ) },
+ { new Short( (short) 55 ), Byte.class, new Byte( (byte) 55 ) },
+ { new Long( 55 ), Byte.class, new Byte( (byte) 55 ) }, { new Float( 55 ), Byte.class, new Byte( (byte) 55 ) },
+ { new BigInteger( "55" ), Byte.class, new Byte( (byte) 55 ) },
+ { new BigDecimal( "55" ), Byte.class, new Byte( (byte) 55 ) },
+
+ /* To Character.class */
+ { "55", Character.class, new Character( (char) 55 ) },
+ { new Integer( 55 ), Character.class, new Character( (char) 55 ) },
+ { new Double( 55 ), Character.class, new Character( (char) 55 ) },
+ { Boolean.TRUE, Character.class, new Character( (char) 1 ) },
+ { new Byte( (byte) 55 ), Character.class, new Character( (char) 55 ) },
+ { new Character( (char) 55 ), Character.class, new Character( (char) 55 ) },
+ { new Short( (short) 55 ), Character.class, new Character( (char) 55 ) },
+ { new Long( 55 ), Character.class, new Character( (char) 55 ) },
+ { new Float( 55 ), Character.class, new Character( (char) 55 ) },
+ { new BigInteger( "55" ), Character.class, new Character( (char) 55 ) },
+ { new BigDecimal( "55" ), Character.class, new Character( (char) 55 ) },
+
+ /* To Short.class */
+ { "55", Short.class, new Short( (short) 55 ) }, { new Integer( 55 ), Short.class, new Short( (short) 55 ) },
+ { new Double( 55 ), Short.class, new Short( (short) 55 ) },
+ { Boolean.TRUE, Short.class, new Short( (short) 1 ) },
+ { new Byte( (byte) 55 ), Short.class, new Short( (short) 55 ) },
+ { new Character( (char) 55 ), Short.class, new Short( (short) 55 ) },
+ { new Short( (short) 55 ), Short.class, new Short( (short) 55 ) },
+ { new Long( 55 ), Short.class, new Short( (short) 55 ) },
+ { new Float( 55 ), Short.class, new Short( (short) 55 ) },
+ { new BigInteger( "55" ), Short.class, new Short( (short) 55 ) },
+ { new BigDecimal( "55" ), Short.class, new Short( (short) 55 ) },
+
+ /* To Long.class */
+ { "55", Long.class, new Long( 55 ) }, { new Integer( 55 ), Long.class, new Long( 55 ) },
+ { new Double( 55 ), Long.class, new Long( 55 ) }, { Boolean.TRUE, Long.class, new Long( 1 ) },
+ { new Byte( (byte) 55 ), Long.class, new Long( 55 ) },
+ { new Character( (char) 55 ), Long.class, new Long( 55 ) },
+ { new Short( (short) 55 ), Long.class, new Long( 55 ) }, { new Long( 55 ), Long.class, new Long( 55 ) },
+ { new Float( 55 ), Long.class, new Long( 55 ) }, { new BigInteger( "55" ), Long.class, new Long( 55 ) },
+ { new BigDecimal( "55" ), Long.class, new Long( 55 ) },
+
+ /* To Float.class */
+ { "55.1234", Float.class, new Float( 55.1234 ) }, { new Integer( 55 ), Float.class, new Float( 55 ) },
+ { new Double( 55.1234 ), Float.class, new Float( 55.1234 ) }, { Boolean.TRUE, Float.class, new Float( 1 ) },
+ { new Byte( (byte) 55 ), Float.class, new Float( 55 ) },
+ { new Character( (char) 55 ), Float.class, new Float( 55 ) },
+ { new Short( (short) 55 ), Float.class, new Float( 55 ) }, { new Long( 55 ), Float.class, new Float( 55 ) },
+ { new Float( 55.1234 ), Float.class, new Float( 55.1234 ) },
+ { new BigInteger( "55" ), Float.class, new Float( 55 ) },
+ { new BigDecimal( "55.1234" ), Float.class, new Float( 55.1234 ) },
+
+ /* To BigInteger.class */
+ { "55", BigInteger.class, new BigInteger( "55" ) },
+ { new Integer( 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new Double( 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { Boolean.TRUE, BigInteger.class, new BigInteger( "1" ) },
+ { new Byte( (byte) 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new Character( (char) 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new Short( (short) 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new Long( 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new Float( 55 ), BigInteger.class, new BigInteger( "55" ) },
+ { new BigInteger( "55" ), BigInteger.class, new BigInteger( "55" ) },
+ { new BigDecimal( "55" ), BigInteger.class, new BigInteger( "55" ) },
+
+ /* To BigDecimal.class */
+ { "55.1234", BigDecimal.class, new BigDecimal( "55.1234" ) },
+ { new Integer( 55 ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new Double( 55.1234 ), BigDecimal.class, new BigDecimal( "55.1234" ), new Integer( 4 ) },
+ { Boolean.TRUE, BigDecimal.class, new BigDecimal( "1" ) },
+ { new Byte( (byte) 55 ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new Character( (char) 55 ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new Short( (short) 55 ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new Long( 55 ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new Float( 55.1234 ), BigDecimal.class, new BigDecimal( "55.1234" ), new Integer( 4 ) },
+ { new BigInteger( "55" ), BigDecimal.class, new BigDecimal( "55" ) },
+ { new BigDecimal( "55.1234" ), BigDecimal.class, new BigDecimal( "55.1234" ) }, };
private Object value;
+
private Class toClass;
+
private Object expectedValue;
+
private int scale;
- /*===================================================================
- Public static methods
- ===================================================================*/
+ /*
+ * =================================================================== Public static methods
+ * ===================================================================
+ */
public static TestSuite suite()
{
TestSuite result = new TestSuite();
- for (int i = 0; i < TESTS.length; i++) {
- result.addTest(new NumericConversionTest(TESTS[i][0],
- (Class) TESTS[i][1],
- TESTS[i][2],
- (TESTS[i].length > 3) ? ((Integer) TESTS[i][3]).intValue() : -1));
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ result.addTest( new NumericConversionTest( TESTS[i][0], (Class) TESTS[i][1], TESTS[i][2],
+ ( TESTS[i].length > 3 ) ? ( (Integer) TESTS[i][3] ).intValue()
+ : -1 ) );
}
return result;
}
- /*===================================================================
- Constructors
- ===================================================================*/
- public NumericConversionTest(Object value, Class toClass, Object expectedValue, int scale)
+ /*
+ * =================================================================== Constructors
+ * ===================================================================
+ */
+ public NumericConversionTest( Object value, Class toClass, Object expectedValue, int scale )
{
- super(value + " [" + value.getClass().getName() + "] -> " + toClass.getName() + " == " + expectedValue
- + " [" + expectedValue.getClass().getName() + "]" + ((scale >= 0) ? (" (to within " + scale + " decimal places)") : ""));
+ super( value + " [" + value.getClass().getName() + "] -> " + toClass.getName() + " == " + expectedValue + " ["
+ + expectedValue.getClass().getName() + "]"
+ + ( ( scale >= 0 ) ? ( " (to within " + scale + " decimal places)" ) : "" ) );
this.value = value;
this.toClass = toClass;
this.expectedValue = expectedValue;
this.scale = scale;
}
- /*===================================================================
- Overridden methods
- ===================================================================*/
- protected void runTest() throws OgnlException
+ /*
+ * =================================================================== Overridden methods
+ * ===================================================================
+ */
+ protected void runTest()
+ throws OgnlException
{
Object result;
- result = OgnlOps.convertValue(value, toClass);
- if (!isEqual(result, expectedValue)) {
- if (scale >= 0) {
- double scalingFactor = Math.pow(10, scale),
- v1 = ((Number) value).doubleValue() * scalingFactor,
- v2 = ((Number) expectedValue).doubleValue() * scalingFactor;
+ result = OgnlOps.convertValue( value, toClass );
+ if ( !isEqual( result, expectedValue ) )
+ {
+ if ( scale >= 0 )
+ {
+ double scalingFactor = Math.pow( 10, scale ), v1 = ( (Number) value ).doubleValue() * scalingFactor, v2 =
+ ( (Number) expectedValue ).doubleValue() * scalingFactor;
- assertTrue((int) v1 == (int) v2);
- } else {
+ assertTrue( (int) v1 == (int) v2 );
+ }
+ else
+ {
fail();
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedPropertyTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedPropertyTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedPropertyTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedPropertyTest.java Sat May 14 13:18:29 2011
@@ -24,35 +24,38 @@ import org.apache.commons.ognl.OgnlExcep
import org.apache.commons.ognl.test.objects.Bean1;
import org.apache.commons.ognl.test.objects.ObjectIndexed;
-public class ObjectIndexedPropertyTest extends OgnlTestCase {
+public class ObjectIndexedPropertyTest
+ extends OgnlTestCase
+{
private static ObjectIndexed OBJECT_INDEXED = new ObjectIndexed();
+
private static Bean1 root = new Bean1();
+
private static Object[][] TESTS = {
- // Arbitrary indexed properties
- {OBJECT_INDEXED, "attributes[\"bar\"]", "baz"}, // get non-indexed property through
- // attributes Map
- {OBJECT_INDEXED, "attribute[\"foo\"]", "bar"}, // get indexed property
- {OBJECT_INDEXED, "attribute[\"bar\"]", "baz", "newValue", "newValue"}, // set
- // indexed
- // property
- {OBJECT_INDEXED, "attribute[\"bar\"]", "newValue"},// get indexed property back to
- // confirm
- {OBJECT_INDEXED, "attributes[\"bar\"]", "newValue"}, // get property back through Map
- // to confirm
- {OBJECT_INDEXED, "attribute[\"other\"].attribute[\"bar\"]", "baz"}, // get indexed
- // property from
- // indexed, then
- // through other
- {OBJECT_INDEXED, "attribute[\"other\"].attributes[\"bar\"]", "baz"}, // get property
- // back through
- // Map to
- // confirm
- {OBJECT_INDEXED, "attribute[$]", OgnlException.class}, // illegal DynamicSubscript
- // access to object indexed
- // property
- {root, "bean2.bean3.indexedValue[25]", null}
- };
+ // Arbitrary indexed properties
+ { OBJECT_INDEXED, "attributes[\"bar\"]", "baz" }, // get non-indexed property through
+ // attributes Map
+ { OBJECT_INDEXED, "attribute[\"foo\"]", "bar" }, // get indexed property
+ { OBJECT_INDEXED, "attribute[\"bar\"]", "baz", "newValue", "newValue" }, // set
+ // indexed
+ // property
+ { OBJECT_INDEXED, "attribute[\"bar\"]", "newValue" },// get indexed property back to
+ // confirm
+ { OBJECT_INDEXED, "attributes[\"bar\"]", "newValue" }, // get property back through Map
+ // to confirm
+ { OBJECT_INDEXED, "attribute[\"other\"].attribute[\"bar\"]", "baz" }, // get indexed
+ // property from
+ // indexed, then
+ // through other
+ { OBJECT_INDEXED, "attribute[\"other\"].attributes[\"bar\"]", "baz" }, // get property
+ // back through
+ // Map to
+ // confirm
+ { OBJECT_INDEXED, "attribute[$]", OgnlException.class }, // illegal DynamicSubscript
+ // access to object indexed
+ // property
+ { root, "bean2.bean3.indexedValue[25]", null } };
/*
* =================================================================== Public static methods
@@ -62,20 +65,31 @@ public class ObjectIndexedPropertyTest e
{
TestSuite result = new TestSuite();
- for (int i = 0; i < TESTS.length; i++) {
- if (TESTS[i].length == 3) {
- result.addTest(new ObjectIndexedPropertyTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
- TESTS[i][2]));
- } else {
- if (TESTS[i].length == 4) {
- result.addTest(new ObjectIndexedPropertyTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3]));
- } else {
- if (TESTS[i].length == 5) {
- result.addTest(new ObjectIndexedPropertyTest((String) TESTS[i][1], TESTS[i][0],
- (String) TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
- } else {
- throw new RuntimeException("don't understand TEST format");
+ for ( int i = 0; i < TESTS.length; i++ )
+ {
+ if ( TESTS[i].length == 3 )
+ {
+ result.addTest( new ObjectIndexedPropertyTest( (String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
+ TESTS[i][2] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 4 )
+ {
+ result.addTest( new ObjectIndexedPropertyTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3] ) );
+ }
+ else
+ {
+ if ( TESTS[i].length == 5 )
+ {
+ result.addTest( new ObjectIndexedPropertyTest( (String) TESTS[i][1], TESTS[i][0],
+ (String) TESTS[i][1], TESTS[i][2], TESTS[i][3],
+ TESTS[i][4] ) );
+ }
+ else
+ {
+ throw new RuntimeException( "don't understand TEST format" );
}
}
}
@@ -92,25 +106,25 @@ public class ObjectIndexedPropertyTest e
super();
}
- public ObjectIndexedPropertyTest(String name)
+ public ObjectIndexedPropertyTest( String name )
{
- super(name);
+ super( name );
}
- public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue, Object expectedAfterSetResult)
+ public ObjectIndexedPropertyTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue, Object expectedAfterSetResult )
{
- super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
}
- public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult,
- Object setValue)
+ public ObjectIndexedPropertyTest( String name, Object root, String expressionString, Object expectedResult,
+ Object setValue )
{
- super(name, root, expressionString, expectedResult, setValue);
+ super( name, root, expressionString, expectedResult, setValue );
}
- public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult)
+ public ObjectIndexedPropertyTest( String name, Object root, String expressionString, Object expectedResult )
{
- super(name, root, expressionString, expectedResult);
+ super( name, root, expressionString, expectedResult );
}
}
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ObjectIndexedTest.java Sat May 14 13:18:29 2011
@@ -27,205 +27,233 @@ import org.apache.commons.ognl.OgnlExcep
import org.apache.commons.ognl.OgnlRuntime;
import org.apache.commons.ognl.SimpleNode;
-public class ObjectIndexedTest extends TestCase
+public class ObjectIndexedTest
+ extends TestCase
{
- protected OgnlContext context;
+ protected OgnlContext context;
- /*===================================================================
- Public static classes
- ===================================================================*/
+ /*
+ * =================================================================== Public static classes
+ * ===================================================================
+ */
public static interface TestInterface
{
- String getSunk(String index);
- void setSunk(String index, String sunk);
+ String getSunk( String index );
+
+ void setSunk( String index, String sunk );
}
- public static class Test1 extends Object implements TestInterface
+ public static class Test1
+ extends Object
+ implements TestInterface
{
- public String getSunk(String index)
+ public String getSunk( String index )
{
return "foo";
}
- public void setSunk(String index, String sunk)
+ public void setSunk( String index, String sunk )
{
/* do nothing */
}
}
- public static class Test2 extends Test1
+ public static class Test2
+ extends Test1
{
- public String getSunk(String index)
+ public String getSunk( String index )
{
return "foo";
}
- public void setSunk(String index, String sunk)
+ public void setSunk( String index, String sunk )
{
/* do nothing */
}
}
- public static class Test3 extends Test1
+ public static class Test3
+ extends Test1
{
- public String getSunk(String index)
+ public String getSunk( String index )
{
return "foo";
}
- public void setSunk(String index, String sunk)
+ public void setSunk( String index, String sunk )
{
/* do nothing */
}
- public String getSunk(Object index)
+ public String getSunk( Object index )
{
return null;
}
}
- public static class Test4 extends Test1
+ public static class Test4
+ extends Test1
{
- public String getSunk(String index)
+ public String getSunk( String index )
{
return "foo";
}
- public void setSunk(String index, String sunk)
+ public void setSunk( String index, String sunk )
{
/* do nothing */
}
- public void setSunk(Object index, String sunk)
+ public void setSunk( Object index, String sunk )
{
/* do nothing */
}
}
- public static class Test5 extends Test1
+ public static class Test5
+ extends Test1
{
- public String getSunk(String index)
+ public String getSunk( String index )
{
return "foo";
}
- public void setSunk(String index, String sunk)
+ public void setSunk( String index, String sunk )
{
/* do nothing */
}
- public String getSunk(Object index)
+ public String getSunk( Object index )
{
return null;
}
- public void setSunk(Object index, String sunk)
+ public void setSunk( Object index, String sunk )
{
/* do nothing */
}
}
- /*===================================================================
- Public static methods
- ===================================================================*/
+ /*
+ * =================================================================== Public static methods
+ * ===================================================================
+ */
public static TestSuite suite()
{
- return new TestSuite(ObjectIndexedTest.class);
+ return new TestSuite( ObjectIndexedTest.class );
}
- /*===================================================================
- Constructors
- ===================================================================*/
+ /*
+ * =================================================================== Constructors
+ * ===================================================================
+ */
public ObjectIndexedTest()
{
super();
}
- public ObjectIndexedTest(String name)
+ public ObjectIndexedTest( String name )
{
- super(name);
+ super( name );
}
- /*===================================================================
- Public methods
- ===================================================================*/
- public void testPropertyDescriptorReflection() throws Exception
+ /*
+ * =================================================================== Public methods
+ * ===================================================================
+ */
+ public void testPropertyDescriptorReflection()
+ throws Exception
{
- OgnlRuntime.getPropertyDescriptor(java.util.AbstractList.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.AbstractSequentialList.class, "");
- OgnlRuntime.getPropertyDescriptor(java.lang.reflect.Array.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.ArrayList.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.BitSet.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.Calendar.class, "");
- OgnlRuntime.getPropertyDescriptor(java.lang.reflect.Field.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.LinkedList.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.List.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.Iterator.class, "");
- OgnlRuntime.getPropertyDescriptor(java.lang.ThreadLocal.class, "");
- OgnlRuntime.getPropertyDescriptor(java.net.URL.class, "");
- OgnlRuntime.getPropertyDescriptor(java.util.Vector.class, "");
+ OgnlRuntime.getPropertyDescriptor( java.util.AbstractList.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.AbstractSequentialList.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.lang.reflect.Array.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.ArrayList.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.BitSet.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.Calendar.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.lang.reflect.Field.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.LinkedList.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.List.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.Iterator.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.lang.ThreadLocal.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.net.URL.class, "" );
+ OgnlRuntime.getPropertyDescriptor( java.util.Vector.class, "" );
}
- public void testObjectIndexAccess() throws OgnlException
+ public void testObjectIndexAccess()
+ throws OgnlException
{
- SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+ SimpleNode expression = (SimpleNode) Ognl.parseExpression( "#ka.sunk[#root]" );
- context.put("ka", new Test1());
- Ognl.getValue(expression, context, "aksdj");
+ context.put( "ka", new Test1() );
+ Ognl.getValue( expression, context, "aksdj" );
}
- public void testObjectIndexInSubclass() throws OgnlException
+ public void testObjectIndexInSubclass()
+ throws OgnlException
{
- SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+ SimpleNode expression = (SimpleNode) Ognl.parseExpression( "#ka.sunk[#root]" );
- context.put("ka", new Test2());
- Ognl.getValue(expression, context, "aksdj");
+ context.put( "ka", new Test2() );
+ Ognl.getValue( expression, context, "aksdj" );
}
- public void testMultipleObjectIndexGetters() throws OgnlException
+ public void testMultipleObjectIndexGetters()
+ throws OgnlException
{
- SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+ SimpleNode expression = (SimpleNode) Ognl.parseExpression( "#ka.sunk[#root]" );
- context.put("ka", new Test3());
- try {
- Ognl.getValue(expression, context, new Test3());
+ context.put( "ka", new Test3() );
+ try
+ {
+ Ognl.getValue( expression, context, new Test3() );
fail();
- } catch (OgnlException ex) {
+ }
+ catch ( OgnlException ex )
+ {
/* Should throw */
}
}
- public void testMultipleObjectIndexSetters() throws OgnlException
+ public void testMultipleObjectIndexSetters()
+ throws OgnlException
{
- SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+ SimpleNode expression = (SimpleNode) Ognl.parseExpression( "#ka.sunk[#root]" );
- context.put("ka", new Test4());
- try {
- Ognl.getValue(expression, context, "aksdj");
+ context.put( "ka", new Test4() );
+ try
+ {
+ Ognl.getValue( expression, context, "aksdj" );
fail();
- } catch (OgnlException ex) {
+ }
+ catch ( OgnlException ex )
+ {
/* Should throw */
}
}
- public void testMultipleObjectIndexMethodPairs() throws OgnlException
+ public void testMultipleObjectIndexMethodPairs()
+ throws OgnlException
{
- SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+ SimpleNode expression = (SimpleNode) Ognl.parseExpression( "#ka.sunk[#root]" );
- context.put("ka", new Test5());
- try {
- Ognl.getValue(expression, context, "aksdj");
+ context.put( "ka", new Test5() );
+ try
+ {
+ Ognl.getValue( expression, context, "aksdj" );
fail();
- } catch (OgnlException ex) {
+ }
+ catch ( OgnlException ex )
+ {
/* Should throw */
}
}
- /*===================================================================
- Overridden methods
- ===================================================================*/
+ /*
+ * =================================================================== Overridden methods
+ * ===================================================================
+ */
protected void setUp()
{
- context = (OgnlContext)Ognl.createDefaultContext(null);
+ context = (OgnlContext) Ognl.createDefaultContext( null );
}
}
\ No newline at end of file
Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/test/OgnlTestCase.java Sat May 14 13:18:29 2011
@@ -28,93 +28,116 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Array;
-public class OgnlTestCase extends TestCase {
-
+public class OgnlTestCase
+ extends TestCase
+{
+
protected OgnlContext _context;
+
private String _expressionString;
+
private SimpleNode _expression;
+
private Object _expectedResult;
+
private Object _root;
+
protected boolean _compileExpressions = true;
+
private boolean hasSetValue;
+
private Object setValue;
+
private boolean hasExpectedAfterSetResult;
+
private Object expectedAfterSetResult;
- /*===================================================================
- Public static methods
- ===================================================================*/
+ /*
+ * =================================================================== Public static methods
+ * ===================================================================
+ */
/**
- * Returns true if object1 is equal to object2 in either the
- * sense that they are the same object or, if both are non-null
- * if they are equal in the <CODE>equals()</CODE> sense.
+ * Returns true if object1 is equal to object2 in either the sense that they are the same object or, if both are
+ * non-null if they are equal in the <CODE>equals()</CODE> sense.
*/
- public static boolean isEqual(Object object1, Object object2)
+ public static boolean isEqual( Object object1, Object object2 )
{
boolean result = false;
- if (object1 == object2) {
+ if ( object1 == object2 )
+ {
result = true;
- } else {
- if ((object1 != null) && object1.getClass().isArray()) {
- if ((object2 != null) && object2.getClass().isArray() && (object2.getClass() == object1.getClass())) {
- result = (Array.getLength(object1) == Array.getLength(object2));
- if (result) {
- for (int i = 0, icount = Array.getLength(object1); result && (i < icount); i++) {
- result = isEqual(Array.get(object1, i), Array.get(object2, i));
+ }
+ else
+ {
+ if ( ( object1 != null ) && object1.getClass().isArray() )
+ {
+ if ( ( object2 != null ) && object2.getClass().isArray() && ( object2.getClass() == object1.getClass() ) )
+ {
+ result = ( Array.getLength( object1 ) == Array.getLength( object2 ) );
+ if ( result )
+ {
+ for ( int i = 0, icount = Array.getLength( object1 ); result && ( i < icount ); i++ )
+ {
+ result = isEqual( Array.get( object1, i ), Array.get( object2, i ) );
}
}
}
- } else {
- result = (object1 != null) && (object2 != null) && object1.equals(object2);
+ }
+ else
+ {
+ result = ( object1 != null ) && ( object2 != null ) && object1.equals( object2 );
}
}
return result;
}
- /*===================================================================
- Constructors
- ===================================================================*/
+ /*
+ * =================================================================== Constructors
+ * ===================================================================
+ */
public OgnlTestCase()
{
super();
}
- public OgnlTestCase(String name)
+ public OgnlTestCase( String name )
{
- super(name);
+ super( name );
}
- public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ public OgnlTestCase( String name, Object root, String expressionString, Object expectedResult, Object setValue,
+ Object expectedAfterSetResult )
{
- this(name, root, expressionString, expectedResult, setValue);
+ this( name, root, expressionString, expectedResult, setValue );
this.hasExpectedAfterSetResult = true;
this.expectedAfterSetResult = expectedAfterSetResult;
}
- public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ public OgnlTestCase( String name, Object root, String expressionString, Object expectedResult, Object setValue )
{
- this(name, root, expressionString, expectedResult);
+ this( name, root, expressionString, expectedResult );
this.hasSetValue = true;
this.setValue = setValue;
}
- public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult)
+ public OgnlTestCase( String name, Object root, String expressionString, Object expectedResult )
{
- this(name);
+ this( name );
this._root = root;
this._expressionString = expressionString;
this._expectedResult = expectedResult;
}
- /*===================================================================
- Public methods
- ===================================================================*/
- public String getExpressionDump(SimpleNode node)
+ /*
+ * =================================================================== Public methods
+ * ===================================================================
+ */
+ public String getExpressionDump( SimpleNode node )
{
StringWriter writer = new StringWriter();
- node.dump(new PrintWriter(writer), " ");
+ node.dump( new PrintWriter( writer ), " " );
return writer.toString();
}
@@ -124,16 +147,16 @@ public class OgnlTestCase extends TestCa
}
public SimpleNode getExpression()
- throws Exception
+ throws Exception
{
- if (_expression == null)
+ if ( _expression == null )
{
- _expression = (SimpleNode) Ognl.parseExpression(_expressionString);
+ _expression = (SimpleNode) Ognl.parseExpression( _expressionString );
}
- if (_compileExpressions)
+ if ( _compileExpressions )
{
- _expression = (SimpleNode) Ognl.compileExpression(_context, _root, _expressionString);
+ _expression = (SimpleNode) Ognl.compileExpression( _context, _root, _expressionString );
}
return _expression;
@@ -144,77 +167,89 @@ public class OgnlTestCase extends TestCa
return _expectedResult;
}
- public static void assertEquals(Object expected, Object actual)
+ public static void assertEquals( Object expected, Object actual )
{
- if (expected != null && expected.getClass().isArray()
- && actual != null && actual.getClass().isArray()) {
+ if ( expected != null && expected.getClass().isArray() && actual != null && actual.getClass().isArray() )
+ {
- TestCase.assertEquals(Array.getLength(expected), Array.getLength(actual));
+ TestCase.assertEquals( Array.getLength( expected ), Array.getLength( actual ) );
- int length = Array.getLength(expected);
+ int length = Array.getLength( expected );
- for (int i = 0; i < length; i++) {
- Object aexpected = Array.get(expected, i);
- Object aactual = Array.get(actual, i);
+ for ( int i = 0; i < length; i++ )
+ {
+ Object aexpected = Array.get( expected, i );
+ Object aactual = Array.get( actual, i );
- if (aexpected != null && aactual != null && Boolean.class.isAssignableFrom(aexpected.getClass())) {
- TestCase.assertEquals(aexpected.toString(), aactual.toString());
- } else
- OgnlTestCase.assertEquals(aexpected, aactual);
+ if ( aexpected != null && aactual != null && Boolean.class.isAssignableFrom( aexpected.getClass() ) )
+ {
+ TestCase.assertEquals( aexpected.toString(), aactual.toString() );
+ }
+ else
+ OgnlTestCase.assertEquals( aexpected, aactual );
}
- } else if (expected != null && actual != null
- && Character.class.isInstance(expected)
- && Character.class.isInstance(actual)) {
+ }
+ else if ( expected != null && actual != null && Character.class.isInstance( expected )
+ && Character.class.isInstance( actual ) )
+ {
- TestCase.assertEquals(((Character) expected).charValue(), ((Character) actual).charValue());
- } else {
+ TestCase.assertEquals( ( (Character) expected ).charValue(), ( (Character) actual ).charValue() );
+ }
+ else
+ {
- TestCase.assertEquals(expected, actual);
+ TestCase.assertEquals( expected, actual );
}
}
- /*===================================================================
- Overridden methods
- ===================================================================*/
- protected void runTest() throws Exception
+ /*
+ * =================================================================== Overridden methods
+ * ===================================================================
+ */
+ protected void runTest()
+ throws Exception
{
Object testedResult = null;
- try {
+ try
+ {
SimpleNode expr;
testedResult = _expectedResult;
expr = getExpression();
- assertEquals(_expectedResult, Ognl.getValue(expr, _context, _root));
+ assertEquals( _expectedResult, Ognl.getValue( expr, _context, _root ) );
- if (hasSetValue)
+ if ( hasSetValue )
{
testedResult = hasExpectedAfterSetResult ? expectedAfterSetResult : setValue;
- Ognl.setValue(expr, _context, _root, setValue);
+ Ognl.setValue( expr, _context, _root, setValue );
- assertEquals(testedResult, Ognl.getValue(expr, _context, _root));
+ assertEquals( testedResult, Ognl.getValue( expr, _context, _root ) );
}
- } catch (Exception ex) {
- System.out.println("Caught exception " + ex);
- if (NullPointerException.class.isInstance(ex))
+ }
+ catch ( Exception ex )
+ {
+ System.out.println( "Caught exception " + ex );
+ if ( NullPointerException.class.isInstance( ex ) )
ex.printStackTrace();
- if (RuntimeException.class.isInstance(ex) && ((RuntimeException) ex).getCause() != null
- && Exception.class.isAssignableFrom(((RuntimeException) ex).getCause().getClass()))
- ex = (Exception) ((RuntimeException) ex).getCause();
+ if ( RuntimeException.class.isInstance( ex ) && ( (RuntimeException) ex ).getCause() != null
+ && Exception.class.isAssignableFrom( ( (RuntimeException) ex ).getCause().getClass() ) )
+ ex = (Exception) ( (RuntimeException) ex ).getCause();
- if (testedResult instanceof Class)
+ if ( testedResult instanceof Class )
{
- assertTrue(Exception.class.isAssignableFrom((Class) testedResult));
- } else
+ assertTrue( Exception.class.isAssignableFrom( (Class) testedResult ) );
+ }
+ else
throw ex;
}
}
protected void setUp()
{
- _context = (OgnlContext) Ognl.createDefaultContext(null);
+ _context = (OgnlContext) Ognl.createDefaultContext( null );
}
}