use of java.time.Month in project jdk8u_jdk by JetBrains.
the class TCKTemporalAdjusters method test_firstDayOfYear_nonLeap.
@Test
public void test_firstDayOfYear_nonLeap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), Month.JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
use of java.time.Month in project jdk8u_jdk by JetBrains.
the class TCKMonth method test_factory_int_singleton.
//-----------------------------------------------------------------------
@Test
public void test_factory_int_singleton() {
for (int i = 1; i <= MAX_LENGTH; i++) {
Month test = Month.of(i);
assertEquals(test.getValue(), i);
}
}
use of java.time.Month in project jdk8u_jdk by JetBrains.
the class TCKDateTimeTextPrinting method test_appendTextMap.
//-----------------------------------------------------------------------
@Test
public void test_appendTextMap() throws Exception {
Map<Long, String> map = new HashMap<Long, String>();
map.put(1L, "JNY");
map.put(2L, "FBY");
map.put(3L, "MCH");
map.put(4L, "APL");
map.put(5L, "MAY");
map.put(6L, "JUN");
map.put(7L, "JLY");
map.put(8L, "AGT");
map.put(9L, "SPT");
map.put(10L, "OBR");
map.put(11L, "NVR");
map.put(12L, "DBR");
builder.appendText(MONTH_OF_YEAR, map);
DateTimeFormatter f = builder.toFormatter();
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
for (Month month : Month.values()) {
assertEquals(f.format(dt.with(month)), map.get((long) month.getValue()));
}
}
use of java.time.Month in project uhgroupings by uhawaii-system-its-ti-iam.
the class YearHolidayHolderTest method getYear.
@Test
public void getYear() {
holder = new YearHolidayHolder() {
@Override
protected Integer currentYear() {
return 2016;
}
};
assertTrue(holder.isEmpty());
assertThat(holder.currentYear(), equalTo(2016));
// Weird.
assertThat(holder.getYear(), equalTo(0));
List<Holiday> holidays = new ArrayList<>();
for (int year = 2000; year <= 2017; year++) {
Date date = Dates.toDate(Dates.firstDateOfYear(year));
holidays.add(new Holiday(date, date));
}
holder = new YearHolidayHolder(holidays) {
@Override
protected Integer currentYear() {
return 2016;
}
};
assertFalse(holder.isEmpty());
assertThat(holder.currentYear(), equalTo(2016));
assertThat(holder.getYear(), equalTo(2016));
Set<Integer> years = holder.getYears();
assertThat(years.size(), equalTo(18));
// The year will be the current year if
// the years range spans accross it.
assertThat(holder.getYear(), equalTo(2016));
holidays = new ArrayList<>();
for (int year = 2000; year <= 2014; year++) {
Date date = Dates.toDate(Dates.firstDateOfYear(year));
holidays.add(new Holiday(date, date));
}
holder = new YearHolidayHolder(holidays) {
@Override
protected Integer currentYear() {
return 2016;
}
};
assertFalse(holder.isEmpty());
assertThat(holder.currentYear(), equalTo(2016));
assertThat(holder.getYear(), equalTo(2014));
// The year will be the highest year if the
// current year is outside the range of years.
assertThat(holder.getYear(), equalTo(2014));
holder.setYear(2013);
assertThat(holder.getYear(), equalTo(2013));
holidays = new ArrayList<>();
for (int year = 2014; year <= 2015; year++) {
for (Month month : Month.values()) {
LocalDate localDate = Dates.newLocalDate(year, month, 1);
Date date = Dates.toDate(localDate);
holidays.add(new Holiday(date, date));
}
}
holder = new YearHolidayHolder(holidays) {
@Override
protected Integer currentYear() {
return 2016;
}
};
assertThat(holder.getYear(), equalTo(2015));
}
use of java.time.Month in project uhgroupings by uhawaii-system-its-ti-iam.
the class YearHolidayHolderTest method getHolidays.
@Test
public void getHolidays() {
List<Holiday> holidays = holder.getHolidays(2016);
assertThat(holidays.size(), equalTo(0));
for (int day = 1; day <= 31; day++) {
LocalDate localDate = Dates.newLocalDate(2016, Month.JANUARY, day);
Date date = Dates.toDate(localDate);
holidays.add(new Holiday(date, date));
}
holder = new YearHolidayHolder(holidays);
holidays = holder.getHolidays(2016);
assertThat(holidays.size(), equalTo(31));
holidays = new ArrayList<>();
for (Month month : Month.values()) {
LocalDate localDate = Dates.firstDateOfMonth(month, 2016);
Date date = Dates.toDate(localDate);
holidays.add(new Holiday(date, date));
}
holder = new YearHolidayHolder(holidays);
holidays = holder.getHolidays(2016);
assertThat(holidays.size(), equalTo(12));
}
Aggregations