BAEL-16980 Slice 7 | The top 100 articles should have their own package in the module (#7663)
This commit is contained in:
committed by
Josh Cummings
parent
f5dcc8e57b
commit
51bd347f6a
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.datetolocaldate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.datetolocaldate.LocalDateTimeToDateConverter;
|
||||
|
||||
/**
|
||||
*
|
||||
* JUnits for {@link LocalDateTimeToDateConverter} class.
|
||||
*
|
||||
* @author abialas
|
||||
*
|
||||
*/
|
||||
public class LocalDateTimeToDateConverterUnitTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturn10thNovember2010time8hour20minWhenConvertViaInstant() {
|
||||
// given
|
||||
LocalDateTime dateToConvert = LocalDateTime.of(2010, 11, 10, 8, 20);
|
||||
|
||||
// when
|
||||
Date date = LocalDateTimeToDateConverter.convertToDateViaInstant(dateToConvert);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
|
||||
// then
|
||||
assertEquals(2010, calendar.get(Calendar.YEAR));
|
||||
assertEquals(10, calendar.get(Calendar.MONTH));
|
||||
assertEquals(10, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(8, calendar.get(Calendar.HOUR));
|
||||
assertEquals(20, calendar.get(Calendar.MINUTE));
|
||||
assertEquals(0, calendar.get(Calendar.SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturn10thNovember2010WhenConvertViaSqlTimestamp() {
|
||||
// given
|
||||
LocalDateTime dateToConvert = LocalDateTime.of(2010, 11, 10, 8, 20);
|
||||
|
||||
// when
|
||||
Date date = LocalDateTimeToDateConverter.convertToDateViaSqlTimestamp(dateToConvert);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
|
||||
// then
|
||||
assertEquals(2010, calendar.get(Calendar.YEAR));
|
||||
assertEquals(10, calendar.get(Calendar.MONTH));
|
||||
assertEquals(10, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(8, calendar.get(Calendar.HOUR));
|
||||
assertEquals(20, calendar.get(Calendar.MINUTE));
|
||||
assertEquals(0, calendar.get(Calendar.SECOND));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user