alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (DateTest.groovy)

This example Groovy source code file (DateTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

calendar, date, date, datetest, february, february, gregoriancalendar, gregoriancalendar, groovytestcase, saturday, saturday

The Groovy DateTest.groovy source code

package groovy

import static java.util.Calendar.*

class DateTest extends GroovyTestCase {
  
    void testNextPrevious() {
        def x = new Date()
        def y = x + 2
        
        assert x < y
        ++x
        --y
        
        assert x == y
        x += 2
        assert x > y
        
        println "have dates ${x} and ${y}"
    }
    
    void testDateRange() {
        
        def today = new Date()
        def later = today + 3
        
        def expected = [today, today + 1, today + 2, today + 3]
        
        def list = []
        for (d in today..later) {
            list << d
        }
        assert list == expected
    }

    void testCalendarIndex() {
        Calendar c = new GregorianCalendar(2002, FEBRUARY, 2)
        assert c[MONTH] == FEBRUARY
        assert c[DAY_OF_WEEK] == SATURDAY
    }

    void testDateIndex() {
        Date d = new GregorianCalendar(2002, FEBRUARY, 2).time
        assert d[MONTH] == FEBRUARY
        assert d[DAY_OF_WEEK] == SATURDAY
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy DateTest.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.