Skip to content

Commit

Permalink
Kata cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: c-guntur <[email protected]>
  • Loading branch information
c-guntur committed Apr 13, 2019
1 parent 45324ef commit 4482f82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* DateTime in Streams.
Expand Down Expand Up @@ -108,6 +107,8 @@ public void verifyStreamOperationsOnTemporalAdjustment() {
// TODO: Add a localDate manipulation that returns
// either the next sunday after current date
// it is a or current date, if Sunday.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
// Check: java.time.temporal.TemporalAdjusters.nextOrSame(DayOfWeek)
localDate = localDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
return temporal.with(localDate);
};
Expand All @@ -118,6 +119,7 @@ public void verifyStreamOperationsOnTemporalAdjustment() {
LocalDate.of(2015, 1, 4));

// TODO: Fix the list mapping below.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
List<LocalDate> collectSundays = someDates
.map(each -> each.with(nextOrSameSunday))
.collect(Collectors.toList());
Expand Down Expand Up @@ -149,13 +151,14 @@ public void twoBusinessDaysShippingCalculator() {
// enum for simplicity.
TemporalAdjuster tPlusTwoBusinessDates = temporal -> {
LocalDate localDate = LocalDate.from(temporal);
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
if (dayOfWeek.getValue() >= 5) {
localDate = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
} else {
int dayOfWeekValue = localDate.getDayOfWeek().getValue();
if (dayOfWeekValue < 4) {
localDate = localDate.plusDays(2);
if (localDate.getDayOfWeek().getValue() > 5) {
} else {
if (dayOfWeekValue == 4) {
localDate = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
} else {
localDate = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
}
}
return temporal.with(localDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* DateTime in Streams.
Expand All @@ -46,31 +45,31 @@ public void verifyFewTemporalAdjusters() {
LocalDate tOJDate = LocalDate.of(1997, 8, 29);


// TODO: Fix the actual to render the "first day of the month".
// TODO: Fix the 'actual' param of the assert to render the "first day of the month".
// Check TemporalAdjusters for the right methods.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
assertEquals("1997-08-01",
tOJDate.toString(),
"First Day Of The Month should be 1997-08-01, 28 days before the date");


// TODO: Fix the actual to render the "last day of the month".
// TODO: Fix the 'actual' param of the assert to render the "last day of the month".
// Check TemporalAdjusters for the right methods.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
assertEquals(tOJDate.plusDays(2),
tOJDate,
"Last Day Of The Month should be 1997-08-31, 2 days after the date");


// TODO: Fix the actual to render the "first day of next month".
// TODO: Fix the 'actual' param of the assert to render the "first day of next month".
// Check TemporalAdjusters for the right methods.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
assertEquals("1997-09-01",
tOJDate.toString(),
"First Day Of Next Month should be 1997-09-01, 3 days after the date");


// TODO: Fix the actual to render the "next Wednesday after the date".
// TODO: Fix the 'actual' param of the assert to render the "next Wednesday after the date".
// Check TemporalAdjusters for the right methods.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
assertEquals(tOJDate.plusDays(5),
Expand All @@ -90,7 +89,7 @@ public void verifyFewTemporalAdjusters() {
"First Day Of Next Year should be 1998-01-01");


// TODO: Fix the actual to render the "first day of year".
// TODO: Fix the 'actual' param of the assert to render the "first day of year".
// Check TemporalAdjusters for the right methods.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
assertEquals(nextYearDate.minusDays(365),
Expand All @@ -108,7 +107,9 @@ public void verifyStreamOperationsOnTemporalAdjustment() {
// TODO: Add a localDate manipulation that returns
// either the next sunday after current date
// it is a or current date, if Sunday.
//localDate = localDate.???(TemporalAdjusters.nextOrSame(???));
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
// Check: java.time.temporal.TemporalAdjusters.nextOrSame(DayOfWeek)
// HINT: localDate = localDate.???(TemporalAdjusters.nextOrSame(???));
return temporal.with(localDate);
};

Expand All @@ -118,6 +119,7 @@ public void verifyStreamOperationsOnTemporalAdjustment() {
LocalDate.of(2015, 1, 4));

// TODO: Fix the list mapping below.
// Check: java.time.LocalDate.with(java.time.temporal.TemporalAdjuster)
List<LocalDate> collectSundays = someDates
.map(each -> each)
.collect(Collectors.toList());
Expand Down Expand Up @@ -149,16 +151,7 @@ public void twoBusinessDaysShippingCalculator() {
// enum for simplicity.
TemporalAdjuster tPlusTwoBusinessDates = temporal -> {
LocalDate localDate = LocalDate.from(temporal);
int dayOfWeekValue = localDate.getDayOfWeek().ordinal();
if(dayOfWeekValue < 3) {
localDate = localDate.plusDays(2);
} else {
if(dayOfWeekValue == 3) {
localDate = localDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
} else {
localDate = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
}
}
localDate = localDate.plusDays(2);
return temporal.with(localDate);
};

Expand Down

0 comments on commit 4482f82

Please sign in to comment.