Esempio n. 1
0
  // -----------------------------------------------------------------------
  public void testToString() {
    Minutes test = Minutes.minutes(20);
    assertEquals("PT20M", test.toString());

    test = Minutes.minutes(-20);
    assertEquals("PT-20M", test.toString());
  }
Esempio n. 2
0
  public void testMultipliedBy_int() {
    Minutes test = Minutes.minutes(2);
    assertEquals(6, test.multipliedBy(3).getMinutes());
    assertEquals(2, test.getMinutes());
    assertEquals(-6, test.multipliedBy(-3).getMinutes());
    assertSame(test, test.multipliedBy(1));

    Minutes halfMax = Minutes.minutes(Integer.MAX_VALUE / 2 + 1);
    try {
      halfMax.multipliedBy(2);
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 3
0
 public void testIsLessThan() {
   assertEquals(false, Minutes.THREE.isLessThan(Minutes.TWO));
   assertEquals(false, Minutes.THREE.isLessThan(Minutes.THREE));
   assertEquals(true, Minutes.TWO.isLessThan(Minutes.THREE));
   assertEquals(false, Minutes.ONE.isLessThan(null));
   assertEquals(true, Minutes.minutes(-1).isLessThan(null));
 }
Esempio n. 4
0
  public void testToStandardDuration() {
    Minutes test = Minutes.minutes(20);
    Duration expected = new Duration(20L * DateTimeConstants.MILLIS_PER_MINUTE);
    assertEquals(expected, test.toStandardDuration());

    expected = new Duration(((long) Integer.MAX_VALUE) * DateTimeConstants.MILLIS_PER_MINUTE);
    assertEquals(expected, Minutes.MAX_VALUE.toStandardDuration());
  }
Esempio n. 5
0
 // -----------------------------------------------------------------------
 public void testFactory_minutes_int() {
   assertSame(Minutes.ZERO, Minutes.minutes(0));
   assertSame(Minutes.ONE, Minutes.minutes(1));
   assertSame(Minutes.TWO, Minutes.minutes(2));
   assertSame(Minutes.THREE, Minutes.minutes(3));
   assertSame(Minutes.MAX_VALUE, Minutes.minutes(Integer.MAX_VALUE));
   assertSame(Minutes.MIN_VALUE, Minutes.minutes(Integer.MIN_VALUE));
   assertEquals(-1, Minutes.minutes(-1).getMinutes());
   assertEquals(4, Minutes.minutes(4).getMinutes());
 }
Esempio n. 6
0
  public void testMinus_Minutes() {
    Minutes test2 = Minutes.minutes(2);
    Minutes test3 = Minutes.minutes(3);
    Minutes result = test2.minus(test3);
    assertEquals(2, test2.getMinutes());
    assertEquals(3, test3.getMinutes());
    assertEquals(-1, result.getMinutes());

    assertEquals(1, Minutes.ONE.minus(Minutes.ZERO).getMinutes());
    assertEquals(1, Minutes.ONE.minus((Minutes) null).getMinutes());

    try {
      Minutes.MIN_VALUE.minus(Minutes.ONE);
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 7
0
  public void testNegated() {
    Minutes test = Minutes.minutes(12);
    assertEquals(-12, test.negated().getMinutes());
    assertEquals(12, test.getMinutes());

    try {
      Minutes.MIN_VALUE.negated();
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 8
0
  public void testToStandardSeconds() {
    Minutes test = Minutes.minutes(3);
    Seconds expected = Seconds.seconds(3 * 60);
    assertEquals(expected, test.toStandardSeconds());

    try {
      Minutes.MAX_VALUE.toStandardSeconds();
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 9
0
  public void testMinus_int() {
    Minutes test2 = Minutes.minutes(2);
    Minutes result = test2.minus(3);
    assertEquals(2, test2.getMinutes());
    assertEquals(-1, result.getMinutes());

    assertEquals(1, Minutes.ONE.minus(0).getMinutes());

    try {
      Minutes.MIN_VALUE.minus(1);
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 10
0
  public void testDividedBy_int() {
    Minutes test = Minutes.minutes(12);
    assertEquals(6, test.dividedBy(2).getMinutes());
    assertEquals(12, test.getMinutes());
    assertEquals(4, test.dividedBy(3).getMinutes());
    assertEquals(3, test.dividedBy(4).getMinutes());
    assertEquals(2, test.dividedBy(5).getMinutes());
    assertEquals(2, test.dividedBy(6).getMinutes());
    assertSame(test, test.dividedBy(1));

    try {
      Minutes.ONE.dividedBy(0);
      fail();
    } catch (ArithmeticException ex) {
      // expected
    }
  }
Esempio n. 11
0
 // -----------------------------------------------------------------------
 public void testAddToLocalDate() {
   Minutes test = Minutes.minutes(26);
   LocalDateTime date = new LocalDateTime(2006, 6, 1, 0, 0, 0, 0);
   LocalDateTime expected = new LocalDateTime(2006, 6, 1, 0, 26, 0, 0);
   assertEquals(expected, date.plus(test));
 }
Esempio n. 12
0
 public void testGetFieldType() {
   Minutes test = Minutes.minutes(20);
   assertEquals(DurationFieldType.minutes(), test.getFieldType());
 }
Esempio n. 13
0
 public void testToStandardHours() {
   Minutes test = Minutes.minutes(3 * 60);
   Hours expected = Hours.hours(3);
   assertEquals(expected, test.toStandardHours());
 }
Esempio n. 14
0
 public void testToStandardDays() {
   Minutes test = Minutes.minutes(60 * 24 * 2);
   Days expected = Days.days(2);
   assertEquals(expected, test.toStandardDays());
 }
Esempio n. 15
0
 // -----------------------------------------------------------------------
 public void testToStandardWeeks() {
   Minutes test = Minutes.minutes(60 * 24 * 7 * 2);
   Weeks expected = Weeks.weeks(2);
   assertEquals(expected, test.toStandardWeeks());
 }
Esempio n. 16
0
 public void testGetPeriodType() {
   Minutes test = Minutes.minutes(20);
   assertEquals(PeriodType.minutes(), test.getPeriodType());
 }
Esempio n. 17
0
 /**
  * Converts this period in weeks to a period in minutes assuming a 7 day week, 24 hour day and 60
  * minute hour.
  *
  * <p>This method allows you to convert between different types of period. However to achieve this
  * it makes the assumption that all weeks are 7 days long, all days are 24 hours long and all
  * hours are 60 minutes long. This is not true when daylight savings is considered and may also
  * not be true for some unusual chronologies. However, it is included as it is a useful operation
  * for many applications and business rules.
  *
  * @return a period representing the number of minutes for this number of weeks
  * @throws ArithmeticException if the number of minutes is too large to be represented
  */
 public Minutes toStandardMinutes() {
   return Minutes.minutes(FieldUtils.safeMultiply(getValue(), DateTimeConstants.MINUTES_PER_WEEK));
 }
Esempio n. 18
0
 // -----------------------------------------------------------------------
 public void testGetMethods() {
   Minutes test = Minutes.minutes(20);
   assertEquals(20, test.getMinutes());
 }