/* * Test for Duration.getField(DatatypeConstants.Field). */ @Test(dataProvider = "duration-fields") public void checkDurationGetField( String lexRepresentation, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes, BigDecimal seconds) { Duration duration = datatypeFactory.newDuration(lexRepresentation); assertEquals(duration.getField(YEARS), years); assertEquals(duration.getField(MONTHS), months); assertEquals(duration.getField(DAYS), days); assertEquals(duration.getField(HOURS), hours); assertEquals(duration.getField(MINUTES), minutes); assertEquals(duration.getField(SECONDS), seconds); }
protected void validateTimezone(DayTimeDurationValue offset) throws XPathException { Duration tz = offset.duration; Number secs = tz.getField(DatatypeConstants.SECONDS); if (secs != null && ((BigDecimal) secs).compareTo(BigDecimal.valueOf(0)) != 0) throw new XPathException( "duration " + offset + " has fractional minutes so cannot be used as a timezone offset"); if (!(tz.equals(tzLowerBound) || tz.equals(tzUpperBound) || (tz.isLongerThan(tzLowerBound) && tz.isShorterThan(tzUpperBound)))) throw new XPathException("duration " + offset + " outside valid timezone offset range"); }
/* * Test for - getField(SECONDS) */ @Test public void checkDurationGetSecondsField() { Duration duration85 = datatypeFactory.newDuration("P1Y1M1DT1H1M100000000S"); assertEquals((duration85.getField(SECONDS)).intValue(), 100000000); }
/* * Test for -getField(DatatypeConstants.Field) DatatypeConstants.Field is * null - throws NPE. */ @Test(expectedExceptions = NullPointerException.class) public void checkDurationGetFieldNeg() { Duration duration67 = datatypeFactory.newDuration("P1Y1M1DT1H1M1S"); duration67.getField(null); }