Java Code Examples for java.time.YearMonth#of()

The following examples show how to use java.time.YearMonth#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateTypesLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
void whenSavingAHibernateTypeYearMonth_thenTheCorrectValueIsStoredInTheDatabase() {
    Song mySong = new Song();
    YearMonth now = YearMonth.of(2019, 12);
    mySong.setArtist(new Artist());
    mySong.setName("My Song");
    mySong.setLength(Duration.ofMinutes(1).getSeconds());
    mySong.setRecordedOn(now);
    mySong = songRepository.save(mySong);

    Song selectSongQueryResult;
    selectSongQueryResult = songRepository.findById(mySong.getId()).get();
    assertThat(selectSongQueryResult.getRecordedOn().getYear()).isEqualTo(2019);
    assertThat(selectSongQueryResult.getRecordedOn().getMonthValue()).isEqualTo(12);
}
 
Example 2
Source File: TCKYearMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_isValidDay_int_june() {
    YearMonth test = YearMonth.of(2007, 6);
    assertEquals(test.isValidDay(1), true);
    assertEquals(test.isValidDay(30), true);

    assertEquals(test.isValidDay(-1), false);
    assertEquals(test.isValidDay(0), false);
    assertEquals(test.isValidDay(31), false);
    assertEquals(test.isValidDay(32), false);
}
 
Example 3
Source File: TCKYearMonth.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_intsMonth() {
    YearMonth test = YearMonth.of(2008, Month.FEBRUARY);
    check(test, 2008, 2);
}
 
Example 4
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_withYear_tooHigh() {
    YearMonth test = YearMonth.of(2008, 6);
    test.withYear(Year.MAX_VALUE + 1);
}
 
Example 5
Source File: TCKYearMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusMonths_long_negative() {
    YearMonth test = YearMonth.of(2008, 6);
    assertEquals(test.plusMonths(-1), YearMonth.of(2008, 5));
}
 
Example 6
Source File: TCKYearMonth.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusMonths_long() {
    YearMonth test = YearMonth.of(2008, 6);
    assertEquals(test.minusMonths(1), YearMonth.of(2008, 5));
}
 
Example 7
Source File: TCKYearMonth.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_adjustDate_preserveDoM() {
    YearMonth test = YearMonth.of(2011, 3);
    LocalDate date = LocalDate.of(2008, 2, 29);
    assertEquals(test.adjustInto(date), LocalDate.of(2011, 3, 29));
}
 
Example 8
Source File: TCKYearMonth.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_withYear_tooHigh() {
    YearMonth test = YearMonth.of(2008, 6);
    test.withYear(Year.MAX_VALUE + 1);
}
 
Example 9
Source File: TCKYearMonth.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_until_convertedType() {
    YearMonth start = YearMonth.of(2010, 6);
    LocalDate end = start.plusMonths(2).atDay(12);
    assertEquals(start.until(end, MONTHS), 2);
}
 
Example 10
Source File: TCKYearMonth.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxSubtractMin() {
    YearMonth test = YearMonth.of(Year.MIN_VALUE, 12);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 11
Source File: TCKYearMonth.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxSubtractMin() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 12
Source File: TCKDateTimeFormatters.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_print_basicIsoDate_missingField() {
    TemporalAccessor test = YearMonth.of(2008, 6);
    DateTimeFormatter.BASIC_ISO_DATE.format(test);
}
 
Example 13
Source File: TCKYearMonth.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_intsMonth_dayTooHigh() {
    YearMonth.of(Year.MAX_VALUE + 1, Month.JANUARY);
}
 
Example 14
Source File: TCKYearMonth.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_adjustDate_resolve() {
    YearMonth test = YearMonth.of(2007, 2);
    LocalDate date = LocalDate.of(2008, 3, 31);
    assertEquals(test.adjustInto(date), LocalDate.of(2007, 2, 28));
}
 
Example 15
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMin() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.plusMonths(Long.MIN_VALUE);
}
 
Example 16
Source File: TCKYearMonth.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_with_Year() {
    YearMonth test = YearMonth.of(2008, 6);
    assertEquals(test.with(Year.of(2000)), YearMonth.of(2000, 6));
}
 
Example 17
Source File: TCKYearMonth.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_minusMonths_long() {
    YearMonth test = YearMonth.of(2008, 6);
    assertEquals(test.minusMonths(1), YearMonth.of(2008, 5));
}
 
Example 18
Source File: TCKYearMonth.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_intsMonth_nullMonth() {
    YearMonth.of(2008, null);
}
 
Example 19
Source File: TCKYearMonth.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_with_Month_noChange_equal() {
    YearMonth test = YearMonth.of(2008, 6);
    assertEquals(test.with(Month.JUNE), test);
}
 
Example 20
Source File: TCKYearMonth.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_lengthOfMonth_febNonLeap() {
    YearMonth test = YearMonth.of(2007, 2);
    assertEquals(test.lengthOfMonth(), 28);
}