• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Assertion for Date

 
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am writing test cases and i wish to compare the date in the database

to what i entered in the DTO of the object...It is givind me errors..

I wish to comapre two dates...

Is there an assertionEquals or assertionTrue method or any other method..

that wud allow me..to do it. with the dates as arguments?

Thx in advance,
A Kumar.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Date implements the equals method, assertEquals(Object, Object) should work fine...
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I will try to work out this way..and get back to u...

But is it ok..if I compare the two dates...

int val= Date1.compareToDate(Date2)

assertEquals(1,val );

Thx
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by A Kumar:
But is it ok..if I compare the two dates...

int val= Date1.compareToDate(Date2)

assertEquals(1,val );


I would rather do something like this:
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or, if you want to test for equality:
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other thing to watch with dates is the precision. ALl of the methods post about (that check for equality) require the dates to be the same to the millisecond. If you want to check just the date part or the time part, you can write a custom assertion. For example,



I favor assertEquals(date1, date2);
over assertTrue(date1.equals(date2));
because it gives clearer output on an assertion failure.
 
It means our mission is in jeapordy! Quick, read this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic