Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
chipkent committed Nov 6, 2023
1 parent b480afb commit edc39e0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2942,7 +2942,6 @@ public static ZonedDateTime atMidnight(@Nullable final LocalDate date, @Nullable
return date.atStartOfDay(timeZone);
}

// TODO: return ZDT?
/**
* Returns an {@link Instant} for the prior midnight in the specified time zone.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public synchronized static BusinessCalendar calendar(final String name) {
/**
* Returns the default business calendar.
*
* @return default business calendar. The default is specified by the {@code Calendar.default} property or {@link #setDefaultCalendar(String)}.
* @return default business calendar. The default is specified by the {@code Calendar.default} property or
* {@link #setDefaultCalendar(String)}.
*/
public synchronized static BusinessCalendar calendar() {
return calendar(defaultName);
Expand All @@ -197,7 +198,8 @@ public synchronized static BusinessCalendar calendar() {
/**
* Returns the default business calendar name.
*
* @return default business calendar name. The default is specified by the {@code Calendar.default} property or {@link #setDefaultCalendar(String)}.
* @return default business calendar name. The default is specified by the {@code Calendar.default} property or
* {@link #setDefaultCalendar(String)}.
*/
public synchronized static String calendarName() {
return defaultName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ public static void assertParserTestCal(final BusinessCalendar cal) {
assertEquals(DateTimeUtils.timeZone("Asia/Tokyo"), cal.timeZone());
assertEquals(LocalDate.of(2000, 1, 2), cal.firstValidDate());
assertEquals(LocalDate.of(2030, 11, 12), cal.lastValidDate());
assertEquals(2,cal.weekendDays().size());
assertEquals(LocalTime.of(6,14), cal.standardBusinessSchedule().businessStart());
assertEquals(LocalTime.of(12,34), cal.standardBusinessSchedule().businessEnd());
assertEquals(2, cal.weekendDays().size());
assertEquals(LocalTime.of(6, 14), cal.standardBusinessSchedule().businessStart());
assertEquals(LocalTime.of(12, 34), cal.standardBusinessSchedule().businessEnd());
assertTrue(cal.weekendDays().contains(DayOfWeek.MONDAY));
assertTrue(cal.weekendDays().contains(DayOfWeek.WEDNESDAY));
assertEquals(2, cal.holidays().size());
assertTrue(cal.holidays().containsKey(LocalDate.of(2015, 1, 1)));
assertTrue(cal.holidays().containsKey(LocalDate.of(2015, 4, 6)));

assertEquals(DateTimeUtils.parseInstant("2015-04-06T14:15 Asia/Tokyo"), cal.businessSchedule("2015-04-06").businessStart());
assertEquals(DateTimeUtils.parseInstant("2015-04-06T16:46 Asia/Tokyo"), cal.businessSchedule("2015-04-06").businessEnd());
assertEquals(DateTimeUtils.parseInstant("2015-04-06T14:15 Asia/Tokyo"),
cal.businessSchedule("2015-04-06").businessStart());
assertEquals(DateTimeUtils.parseInstant("2015-04-06T16:46 Asia/Tokyo"),
cal.businessSchedule("2015-04-06").businessEnd());
}

public void testLoad() throws URISyntaxException {
final String path = Paths
.get(Objects.requireNonNull(TestBusinessCalendarParser.class.getResource("/PARSER-TEST.calendar")).toURI())
.get(Objects.requireNonNull(TestBusinessCalendarParser.class.getResource("/PARSER-TEST.calendar"))
.toURI())
.toString();
final File f = new File(path);
final BusinessCalendar cal = BusinessCalendarParser.loadBusinessCalendar(f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ public void testCalendar() {

public void testAdd() throws URISyntaxException {

try{
try {
final String path = Paths
.get(Objects.requireNonNull(TestBusinessCalendarParser.class.getResource("/PARSER-TEST.calendar")).toURI())
.get(Objects.requireNonNull(TestBusinessCalendarParser.class.getResource("/PARSER-TEST.calendar"))
.toURI())
.toString();
Calendars.addCalendarFromFile(path);

final BusinessCalendar cal = Calendars.calendar("PARSER-TEST-CAL");
TestBusinessCalendarParser.assertParserTestCal(cal);
}finally {
} finally {
Calendars.setDefaultCalendar(Configuration.getInstance().getProperty("Calendar.default"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
*/
public class TestStaticCalendarMethods extends BaseArrayTestCase {

private final Map<Class<?>,Object[]> data = new HashMap<>();
private final Map<Class<?>, Object[]> data = new HashMap<>();
{
data.put(String.class, new String[] {"2017-08-01", "2017-08-05"});
data.put(LocalDate.class, new LocalDate[] {DateTimeUtils.parseLocalDate("2017-08-01"), DateTimeUtils.parseLocalDate("2017-08-05")});
data.put(Instant.class, new Instant[] {DateTimeUtils.parseInstant("2002-01-01T01:00:00.000000000 NY"), DateTimeUtils.parseInstant("2002-01-21T01:00:00.000000000 NY")});
data.put(ZonedDateTime.class, new ZonedDateTime[] {DateTimeUtils.parseZonedDateTime("2002-01-01T01:00:00.000000000 NY"), DateTimeUtils.parseZonedDateTime("2002-01-21T01:00:00.000000000 NY")});
data.put(LocalDate.class, new LocalDate[] {DateTimeUtils.parseLocalDate("2017-08-01"),
DateTimeUtils.parseLocalDate("2017-08-05")});
data.put(Instant.class, new Instant[] {DateTimeUtils.parseInstant("2002-01-01T01:00:00.000000000 NY"),
DateTimeUtils.parseInstant("2002-01-21T01:00:00.000000000 NY")});
data.put(ZonedDateTime.class,
new ZonedDateTime[] {DateTimeUtils.parseZonedDateTime("2002-01-01T01:00:00.000000000 NY"),
DateTimeUtils.parseZonedDateTime("2002-01-21T01:00:00.000000000 NY")});
data.put(boolean.class, new Boolean[] {true, true});
data.put(int.class, new Object[]{1, 2});
data.put(DayOfWeek.class, new Object[]{DayOfWeek.MONDAY, DayOfWeek.TUESDAY});
data.put(int.class, new Object[] {1, 2});
data.put(DayOfWeek.class, new Object[] {DayOfWeek.MONDAY, DayOfWeek.TUESDAY});
}

private final Map<String, Double> deltas = new HashMap<>();
Expand All @@ -40,28 +44,29 @@ public class TestStaticCalendarMethods extends BaseArrayTestCase {
}

@SuppressWarnings("StringConcatenationInLoop")
private void executeTest(final Method m1, final Method m2) throws InvocationTargetException, IllegalAccessException {
private void executeTest(final Method m1, final Method m2)
throws InvocationTargetException, IllegalAccessException {
final ArrayList<Object> args = new ArrayList<>();
final Map<Class<?>,Integer> paramCounter = new HashMap<>();
final Map<Class<?>, Integer> paramCounter = new HashMap<>();

String description = m1.getName() + "(";
boolean isFirst = true;

for(Class<?> t : m1.getParameterTypes()) {
for (Class<?> t : m1.getParameterTypes()) {
final int count = paramCounter.getOrDefault(t, 0) + 1;
paramCounter.put(t, count);

final String name = t.getSimpleName().toLowerCase() + count;
final Object[] d = data.get(t);

if(d == null) {
if (d == null) {
throw new RuntimeException("No data for " + t);
}

final Object val = d[count-1];
final Object val = d[count - 1];
args.add(val);

if(isFirst){
if (isFirst) {
isFirst = false;
} else {
description += ", ";
Expand All @@ -78,9 +83,9 @@ private void executeTest(final Method m1, final Method m2) throws InvocationTarg
final Object actual = m2.invoke(null, args.toArray());
final Double delta = deltas.get(description);

if(delta != null){
if (delta != null) {
assertEquals(description, (double) target, (double) actual, delta);
} else if(target instanceof Object[]) {
} else if (target instanceof Object[]) {
assertEquals(description, (Object[]) target, (Object[]) actual);
} else {
assertEquals(description, target, actual);
Expand All @@ -96,8 +101,8 @@ public void testAll() {
excludes.add("firstValidDate");
excludes.add("lastValidDate");

for(Method m1 : BusinessCalendar.class.getMethods()) {
if(m1.getDeclaringClass() == Object.class ||
for (Method m1 : BusinessCalendar.class.getMethods()) {
if (m1.getDeclaringClass() == Object.class ||
Modifier.isStatic(m1.getModifiers()) ||
!Modifier.isPublic(m1.getModifiers())) {
continue;
Expand All @@ -106,14 +111,14 @@ public void testAll() {
try {
String name2 = m1.getName();

if(excludes.contains(name2)) {
if (excludes.contains(name2)) {
System.out.println("Skipping " + name2);
continue;
}

if(name2.equals("dayOfWeek")) {
if (name2.equals("dayOfWeek")) {
name2 = "calendarDayOfWeek";
} else if(name2.equals("timeZone")) {
} else if (name2.equals("timeZone")) {
name2 = "calendarTimeZone";
}

Expand Down

0 comments on commit edc39e0

Please sign in to comment.