commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl JexlTest.java
Date Thu, 10 Oct 2002 11:09:32 GMT
jstrachan    2002/10/10 04:09:32

  Modified:    jexl/src/test/org/apache/commons/jexl JexlTest.java
  Log:
  Added a few more test cases (that fail!).
  
  Also added a helper method
  
    assertExpression(jc, expressionText, expectedValue)
  
  that makes it really easy to add lots more tests. Also this helper method gives some helpful
output so its easy to see which test failed etc.
  
  Revision  Changes    Path
  1.18      +33 -52    jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java
  
  Index: JexlTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JexlTest.java	10 Oct 2002 10:40:58 -0000	1.17
  +++ JexlTest.java	10 Oct 2002 11:09:32 -0000	1.18
  @@ -424,42 +424,26 @@
   
           List list = new ArrayList();
   
  -        list.add("");
  -        list.add("");
  -        list.add("");
  -        list.add("");
  -        list.add("");
  +        list.add("1");
  +        list.add("2");
  +        list.add("3");
  +        list.add("4");
  +        list.add("5");
   
           jc.getVars().put("list", list);
   
  -        Expression e = ExpressionFactory.createExpression("size(string)");
  -        Object o = e.evaluate(jc);
  -        assertTrue("1 : o incorrect", o.equals(new Integer(5)));
  -
  -        e = ExpressionFactory.createExpression("size(array)");
  -        o = e.evaluate(jc);
  -        assertTrue("2 : o incorrect", o.equals(new Integer(5)));
  -
  -        e = ExpressionFactory.createExpression("size(map)");
  -        o = e.evaluate(jc);
  -        assertTrue("3 : o incorrect", o.equals(new Integer(5)));
  -
  -        e = ExpressionFactory.createExpression("size(list)");
  -        o = e.evaluate(jc);
  -        assertTrue("4 : o incorrect", o.equals(new Integer(5)));
  -        
  -        
  -        e = ExpressionFactory.createExpression("list.size()");
  -        o = e.evaluate(jc);
  -        assertTrue("4 : o incorrect", o.equals(new Integer(5)));
  -
  -        e = ExpressionFactory.createExpression("map.size()");
  -        o = e.evaluate(jc);
  -        assertTrue("4 : o incorrect", o.equals(new Integer(5)));
  -        
  -        e = ExpressionFactory.createExpression("array.length");
  -        o = e.evaluate(jc);
  -        assertTrue("4 : o incorrect", o.equals(new Integer(5)));
  +        assertExpression(jc, "size(string)", new Integer(5));
  +        assertExpression(jc, "size(array)", new Integer(5));
  +        assertExpression(jc, "size(list)", new Integer(5));
  +        assertExpression(jc, "size(map)", new Integer(5));
  +        assertExpression(jc, "size(list)", new Integer(5));
  +        assertExpression(jc, "list.size()", new Integer(5));
  +        assertExpression(jc, "map.size()", new Integer(5));
  +        assertExpression(jc, "array.length", new Integer(5));
  +
  +        assertExpression(jc, "list.get(size(list) - 1)", "5");
  +        assertExpression(jc, "list[size(list) - 1]", "5");
  +        assertExpression(jc, "list.get(list.size() - 1)", "5");
       }
   
   
  @@ -736,25 +720,11 @@
           assertTrue("o not instanceof Boolean", o instanceof Boolean);
           assertEquals("o incorrect", Boolean.FALSE, o);
   
  -        e = ExpressionFactory.createExpression("bar == ''");
  -        o = e.evaluate(jc);
  -
  -        assertEquals("o incorrect", Boolean.TRUE, o );
   
  -        e = ExpressionFactory.createExpression("barnotexist == ''");
  -        o = e.evaluate(jc);
  -
  -        assertEquals("o incorrect", Boolean.FALSE, o );
  -
  -        e = ExpressionFactory.createExpression("empty bar");
  -        o = e.evaluate(jc);
  -
  -        assertEquals("o incorrect", Boolean.TRUE, o );
  -        
  -        e = ExpressionFactory.createExpression("bar.length() == 0");
  -        o = e.evaluate(jc);
  -
  -        assertEquals("o incorrect", Boolean.TRUE, o );
  +        assertExpression(jc, "bar == ''", Boolean.TRUE);
  +        assertExpression(jc, "barnotexist == ''", Boolean.FALSE);
  +        assertExpression(jc, "empty bar", Boolean.TRUE);
  +        assertExpression(jc, "bar.length() == 0", Boolean.TRUE);
       }
   
       /**
  @@ -994,4 +964,15 @@
           }
       }
   
  +
  +    /**
  +     * Asserts that the given expression returns the given value when applied to the 
  +     * given context
  +     */
  +    protected void assertExpression(JexlContext jc, String expression, Object expected)
throws Exception 
  +    {
  +        Expression e = ExpressionFactory.createExpression("array.length");
  +        Object actual = e.evaluate(jc);
  +        assertEquals(expression, expected, actual);
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message