Junit with new Date() -
what junit test when have following method:
@override public void savelastsuccesfulllogin(final user user) { gebruiker.setlastlogin(new date()); storeuser(user); }
submethode storeuser:
@override public void storeuser(final user user) { entitymanager em = emf.createentitymanager(); em.gettransaction().begin(); em.merge(user); em.gettransaction().commit(); em.close(); }
the problem have date, being set entity user , stored. im using junit , easymock.
try pulling new date() method default access specifier below
@override public void savelastsuccesfulllogin(final user user) { gebruiker.setlastlogin(getdate()); storeuser(user); } date getdate() { return new date(); }
in test class override class below using mock or stubbed date.
<classundertest> classundertest = new <classundertest> () { @override date getdate() { return mockdate; } }
in way can assert date value going stubbed out.
Comments
Post a Comment