Ejemplo n.º 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());
 }
Ejemplo n.º 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
   }
 }
Ejemplo n.º 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
   }
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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
   }
 }