Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:28:54+00:00 2026-05-13T18:28:54+00:00

This was taken nearly verbatim from IBM’s Mastering Grails series. DateTagLib.groovy: class DateTagLib {

  • 0

This was taken nearly verbatim from IBM’s Mastering Grails series.

DateTagLib.groovy:

class DateTagLib {
  def thisYear = {
    out << Calendar.getInstance().get(Calendar.YEAR)
  }
}

DateTagLibTests.groovy:

class DateTagLibTests extends TagLibUnitTestCase {
    def dateTagLib

    protected void setUp() {
        super.setUp()

        dateTagLib = new DateTagLib()
    }

    void testThisYear() {
        String expected = Calendar.getInstance().get(Calendar.YEAR)
        assertEquals("years do NOT match", expected, dateTagLib.thisYear())
    }

    protected void tearDown() {
        super.tearDown()
    }
}

grails test-app DateTagLib output:

-------------------------------------------------------
Running 1 unit test...
Running test DateTagLibTests...
                    testThisYear...FAILED
Tests Completed in 359ms ...
-------------------------------------------------------
Tests passed: 0
Tests failed: 1
-------------------------------------------------------

I tried matching the types (int/long/String), but I’m still banging my head against the wall.

This test also fails:

void testThisYear() {
    long expected = Calendar.getInstance().get(Calendar.YEAR)
    assertEquals("years do NOT match", expected, (long) dateTagLib.thisYear())
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:28:54+00:00Added an answer on May 13, 2026 at 6:28 pm

    Try the following instead

    class DateTagLibTests extends TagLibUnitTestCase {
    
        void testThisYear() {
            String expected = Calendar.getInstance().get(Calendar.YEAR)
            tagLib.thisYear()
            assertEquals("years do NOT match", expected, tagLib.out)
        }
    
    }
    

    Your original code has 2 problems:

    • You should not instantiate DateTagLib explicitly. It is already available through a property of the test class named tagLib
    • thisYear does not return the year value, it writes it to out. Within a test you can access the content written to the output via tagLib.out
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code taken from here : import smtplib def prompt(prompt): return
I have taken this example from net . But when i tried it is
This is inspired by/taken from this thread: http://www.allegro.cc/forums/thread/603383 The Problem Assume the user gives
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
I'm struggling to find how to call the equivalent of (taken from this article
This is a code sample taken from the Google Maps API developer's guide. I'm
I use this code which is taken from MVC futures and attach the Attribute
i got this SQL query where post_title taken from $_GET $sql = SELECT ID
Im new to iPhone development and I have really taken this to me. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.