Switch from Postgres to H2

This commit is contained in:
Ali Dehghani
2019-10-28 22:12:19 +03:30
parent db85c8f275
commit c4da87f511
20523 changed files with 1643929 additions and 0 deletions
@@ -0,0 +1,69 @@
package com.baeldung.dateapi;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import org.apache.log4j.Logger;
import org.junit.Test;
public class JavaPeriodUnitTest {
private static final Logger LOG = Logger.getLogger(JavaPeriodUnitTest.class);
@Test
public void givenADatePlus5Days_whenRequestingPeriod_thenExpectFive() {
LocalDate initialDate = LocalDate.parse("2007-05-10");
LocalDate finalDate = initialDate.plus(Period.ofDays(5));
int days = Period.between(initialDate, finalDate)
.getDays();
assertThat(days).isEqualTo(5);
}
@Test
public void givenADatePlus5Days_whenRequestingDaysBetween_thenExpectFive() {
LocalDate initialDate = LocalDate.parse("2007-05-10");
LocalDate finalDate = initialDate.plus(Period.ofDays(5));
long days = ChronoUnit.DAYS.between(initialDate, finalDate);
assertThat(days).isEqualTo(5);
}
@Test
public void whenTestPeriod_thenOk() {
LocalDate startDate = LocalDate.of(2015, 2, 15);
LocalDate endDate = LocalDate.of(2017, 1, 21);
Period period = Period.between(startDate, endDate);
LOG.info(String.format("Years:%d months:%d days:%d", period.getYears(), period.getMonths(), period.getDays()));
assertFalse(period.isNegative());
assertEquals(56, period.plusDays(50)
.getDays());
assertEquals(9, period.minusMonths(2)
.getMonths());
Period fromUnits = Period.of(3, 10, 10);
Period fromDays = Period.ofDays(50);
Period fromMonths = Period.ofMonths(5);
Period fromYears = Period.ofYears(10);
Period fromWeeks = Period.ofWeeks(40);
assertEquals(280, fromWeeks.getDays());
Period fromCharYears = Period.parse("P2Y");
assertEquals(2, fromCharYears.getYears());
Period fromCharUnits = Period.parse("P2Y3M5D");
assertEquals(5, fromCharUnits.getDays());
}
}