Search in sources :

Example 36 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class PeriodStyleTests method printSimpleWhenZeroWithoutUnitShouldPrintInDays.

@Test
void printSimpleWhenZeroWithoutUnitShouldPrintInDays() {
    Period period = Period.ofMonths(0);
    assertThat(PeriodStyle.SIMPLE.print(period)).isEqualTo("0d");
}
Also used : Period(java.time.Period) Test(org.junit.jupiter.api.Test)

Example 37 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class NumberToPeriodConverterTests method convert.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Period convert(ConversionService conversionService, Integer source, ChronoUnit defaultUnit) {
    TypeDescriptor targetType = mock(TypeDescriptor.class);
    if (defaultUnit != null) {
        PeriodUnit unitAnnotation = AnnotationUtils.synthesizeAnnotation(Collections.singletonMap("value", defaultUnit), PeriodUnit.class, null);
        given(targetType.getAnnotation(PeriodUnit.class)).willReturn(unitAnnotation);
    }
    given(targetType.getType()).willReturn((Class) Period.class);
    return (Period) conversionService.convert(source, TypeDescriptor.forObject(source), targetType);
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Period(java.time.Period)

Example 38 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method test_multipliedBy_overflowTooBig.

@Test(expected = ArithmeticException.class)
public void test_multipliedBy_overflowTooBig() {
    Period test = Period.ofYears(Integer.MAX_VALUE / 2 + 1);
    test.multipliedBy(2);
}
Also used : Period(java.time.Period) Test(org.junit.Test)

Example 39 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method factory_parse_plus.

@Test()
@UseDataProvider("data_factory_parseSuccess")
public void factory_parse_plus(String text, Period expected) {
    Period p = Period.parse("+" + text);
    assertEquals(p, expected);
}
Also used : Period(java.time.Period) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 40 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method test_multipliedBy.

// -----------------------------------------------------------------------
// multipliedBy()
// -----------------------------------------------------------------------
@Test
public void test_multipliedBy() {
    Period test = Period.of(1, 2, 3);
    assertPeriod(test.multipliedBy(0), 0, 0, 0);
    assertPeriod(test.multipliedBy(1), 1, 2, 3);
    assertPeriod(test.multipliedBy(2), 2, 4, 6);
    assertPeriod(test.multipliedBy(-3), -3, -6, -9);
}
Also used : Period(java.time.Period) Test(org.junit.Test)

Aggregations

Period (java.time.Period)108 Test (org.junit.Test)38 Test (org.testng.annotations.Test)27 LocalDate (java.time.LocalDate)20 Duration (java.time.Duration)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 LocalDateTime (java.time.LocalDateTime)7 ZonedDateTime (java.time.ZonedDateTime)7 Date (java.util.Date)6 LocalTime (java.time.LocalTime)5 ZoneId (java.time.ZoneId)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 List (java.util.List)5 Test (org.junit.jupiter.api.Test)5 Instant (java.time.Instant)4 DateTimeParseException (java.time.format.DateTimeParseException)4 Temporal (java.time.temporal.Temporal)4 TemporalAmount (java.time.temporal.TemporalAmount)4 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4