Skip to content

Commit

Permalink
BAEL-2667 (#6442)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-ligios authored and maibin committed Mar 1, 2019
1 parent 1013f93 commit 725a6e0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core-groovy/pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
57 changes: 57 additions & 0 deletions core-groovy/src/test/groovy/com/baeldung/date/DateTest.groovy
@@ -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)
}


}

0 comments on commit 725a6e0

Please sign in to comment.