コード例 #1
0
 /** Tests if empty sequence is returned for empty sequence */
 public void testEmptySequence() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(expressionContextMock, new Value[] {factory.createSequence(new Item[] {})});
   assertTrue(result instanceof Sequence);
   assertEquals(0, result.getSequence().getLength());
 }
コード例 #2
0
 /** Tests if {@link ExpressionException} is thrown when max is called without arguments */
 public void testNoArguments() {
   final Function function = new MaxFunction();
   try {
     function.invoke(expressionContextMock, new Value[] {});
     fail("Exception wasn't thrown when max was invoked with 0 arguments");
   } catch (ExpressionException e) {
     // do nothing, expected situation
   }
 }
コード例 #3
0
 /** Tests if {@link ExpressionException} is thrown when max is called with two arguments */
 public void testTwoArguments() {
   final Function function = new MaxFunction();
   try {
     function.invoke(
         expressionContextMock,
         new Value[] {factory.createSequence(new Item[] {}), factory.createDoubleValue(20.0)});
     fail("Exception wasn't thrown when max was invoked with 2 arguments");
   } catch (ExpressionException e) {
     // do nothing, expected situation
   }
 }
コード例 #4
0
 /**
  * Tests on sequence of strings. Values should be compared using Unicode code point collation
  * (http://www.w3.org/2005/xpath-functions/collation/codepoint).
  */
 public void testSequenceOfStrings() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(
           expressionContextMock,
           new Value[] {
             factory.createSequence(
                 new Item[] {
                   factory.createStringValue("qwe"),
                   factory.createStringValue("rty"),
                   factory.createStringValue("asd")
                 })
           });
   assertTrue(result instanceof StringValue);
   assertEquals("rty", result.stringValue().asJavaString());
 }
コード例 #5
0
 /** Tests max on sequence of integers and doubles */
 public void testSequenceOfNumbers() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(
           expressionContextMock,
           new Value[] {
             factory.createSequence(
                 new Item[] {
                   factory.createIntValue(6),
                   factory.createIntValue(3),
                   factory.createDoubleValue(4.3)
                 })
           });
   assertTrue(result instanceof IntValue);
   assertEquals(6, ((IntValue) result).asJavaInt());
 }
コード例 #6
0
 /** Tests on sequence of dates. Latest date should be returned. */
 public void testSequenceOfDates() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(
           expressionContextMock,
           new Value[] {
             factory.createSequence(
                 new Item[] {
                   factory.createDateValue("2008-03-11"),
                   factory.createDateValue("2006-04-16"),
                   factory.createDateValue("2009-01-02")
                 })
           });
   assertTrue(result instanceof DateValue);
   assertEquals(factory.createDateValue("2009-01-02"), result);
 }
コード例 #7
0
 /** Tests on sequence of times. Latest time should be returned. */
 public void testSequenceOfTimeValues() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(
           expressionContextMock,
           new Value[] {
             factory.createSequence(
                 new Item[] {
                   factory.createTimeValue("07:56:16+00:00"),
                   factory.createTimeValue("12:30:16+00:00"),
                   factory.createTimeValue("22:55:21+00:00"),
                   factory.createTimeValue("22:56:16+00:00")
                 })
           });
   assertTrue(result instanceof TimeValue);
   assertEquals(factory.createTimeValue("22:56:16+00:00"), result);
 }
コード例 #8
0
 /** Tests on sequence of datetimes. Latest datetime should be returned. */
 public void testSequenceOfDatetimes() throws ExpressionException {
   final Function function = new MaxFunction();
   Value result =
       function.invoke(
           expressionContextMock,
           new Value[] {
             factory.createSequence(
                 new Item[] {
                   factory.createDateTimeValue("2004-03-11T07:56:16+00:00"),
                   factory.createDateTimeValue("2006-04-16T12:30:16+00:00"),
                   factory.createDateTimeValue("2006-04-16T06:56:16+00:00"),
                   factory.createDateTimeValue("2005-01-02T02:56:16+00:00")
                 })
           });
   assertTrue(result instanceof DateTimeValue);
   assertEquals(factory.createDateTimeValue("2006-04-16T12:30:16+00:00"), result);
 }
コード例 #9
0
 /** Tests on sequence of strings and numbers. {@link ExpressionException} should be thrown. */
 public void testSequenceOfStringsAndNumbers() throws ExpressionException {
   final Function function = new MaxFunction();
   try {
     function.invoke(
         expressionContextMock,
         new Value[] {
           factory.createSequence(
               new Item[] {
                 factory.createIntValue(6),
                 factory.createIntValue(3),
                 factory.createStringValue("qwe"),
                 factory.createStringValue("rty"),
                 factory.createStringValue("asd")
               })
         });
     fail("Exception wasn't thrown when max was invoked with sequence of strings and numbers");
   } catch (ExpressionException e) {
     // do nothing, expected situation
   }
 }