简体   繁体   中英

how to customizely replace dbunit's dataset Object

I am struggling to create a custom DateTime object that looks like this:

  2015-05-07 12:12:00 - > [the date is today's date but the time is custom]

I have a junit test class with dbunit's dataset, I have been able to use ReplacementDataSet's classes addReplacementObject() method to replace a placeholder like [NOW] with today's date, but i have hard time to figure out how to replace the date part of DateTime object while keeping the time. Can any body help!!!

I don't think dbunit can do this far. but you can use another approach. From my prespective i would rather prefer to do the insertion of customized datetime in my test class rather than puting in dbunit dataset. If your dao class has a functionality to insert the date , you can create a TimeStamp object as show below:

    DateTime dt= new DateTime();

    Timestamp timeStamp=new Timestamp(dt.withTime(12,12,0,0).getMillis())

After creating this object , you can safely uset it in your query. I hope this to be helpfull.

NB : i am using Joda Time library to create thed Date time object. it is very powerfull and currently it is the de facto standard date and time library for Java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM