BAEL-2667 (#6442)
This commit is contained in:
parent
1013f93179
commit
725a6e04d5
|
@ -23,6 +23,12 @@
|
|||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>${groovy-all.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-dateutil</artifactId>
|
||||
<version>${groovy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
|
@ -103,9 +109,12 @@
|
|||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<groovy.version>2.4.13</groovy.version>
|
||||
<groovy-all.version>2.4.13</groovy-all.version>
|
||||
<groovy-sql.version>2.4.13</groovy-sql.version>
|
||||
<!-- <groovy.version>2.4.13</groovy.version> -->
|
||||
<!-- <groovy-all.version>2.4.13</groovy-all.version> -->
|
||||
<!-- <groovy-sql.version>2.4.13</groovy-sql.version> -->
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
<groovy-all.version>2.5.6</groovy-all.version>
|
||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package com.baeldung.groovy.sql
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import java.util.Calendar.*
|
||||
import java.time.LocalDate
|
||||
import java.text.SimpleDateFormat
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
class DateTest {
|
||||
|
||||
def dateStr = "2019-02-28"
|
||||
def pattern = "yyyy-MM-dd"
|
||||
|
||||
@Test
|
||||
void whenGetStringRepresentation_thenCorrectlyConvertIntoDate() {
|
||||
def dateFormat = new SimpleDateFormat(pattern)
|
||||
def date = dateFormat.parse(dateStr)
|
||||
|
||||
println(" String to Date with DateFormatter : " + date)
|
||||
|
||||
def cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
|
||||
assertEquals(cal.get(Calendar.YEAR),2019)
|
||||
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
|
||||
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenGetStringRepresentation_thenCorrectlyConvertWithDateUtilsExtension() {
|
||||
|
||||
def date = Date.parse(pattern, dateStr)
|
||||
|
||||
println(" String to Date with Date.parse : " + date)
|
||||
|
||||
def cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
|
||||
assertEquals(cal.get(Calendar.YEAR),2019)
|
||||
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
|
||||
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenGetStringRepresentation_thenCorrectlyConvertIntoDateWithLocalDate() {
|
||||
def date = LocalDate.parse(dateStr, pattern)
|
||||
|
||||
println(" String to Date with LocalDate : " + date)
|
||||
|
||||
assertEquals(date.getYear(),2019)
|
||||
assertEquals(date.getMonth(),java.time.Month.FEBRUARY)
|
||||
assertEquals(date.getDayOfMonth(),28)
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue