| To: | Keshav Kode <keshav.kode@xxxxxxxxx>, users@xxxxxxxxxx |
|---|---|
| Subject: | Re: [cinjug-users] help: How to create virtual current system date for J2EE applications hosted under the same WAS? |
| From: | "Jonathan A. Chase" <chaseja@xxxxxxxxxx> |
| Date: | Tue, 22 Mar 2005 15:52:26 -0500 |
| Delivered-to: | mailing list users@cinjug.org |
| In-reply-to: | <dff5562005032114026e0e0ddb@mail.gmail.com> |
| Mailing-list: | contact users-help@cinjug.org; run by ezmlm |
| Organization: | Miami University DARS Project |
| References: | <dff5562005032114026e0e0ddb@mail.gmail.com> |
| User-agent: | Opera7.23/Win32 M2 build 3227 |
|
We had a similar problem. It sounds like we did the same thing you're
thinking about: 1) we defined an interface, say, DateProvider, with one method, getDate() 2) our default implementation of the interface, DefaultDateProvider, looked like: /** return the real date, according to the OS */ public Date getDate() { return new java.util.Date(); } 3) the implementation we used for (junit) testing, AssignableDateProvider, looked like: /** saves a date passed in by the user */ public AssignableDateProvider(Date d) { this.date = d; } /** return whatever date you set in the constructor */ public Date getDate() { return this.date; } In our test code we used the AssignableDateProvider implementation, in production we used the DefaultDateProvider implementation. So you could either use a sigleton like you suggested with the above strategy, or better yet, make the DateProvider an attribute of whatever class it is that's using it, and make sure the class uses a DefaultDateProvider by default (say, set in the constructor). Then, for testing, call yourObject.setDateProvider(new AssignableDateProvider(your date)) and you should be good to go. With the latter approach, you don't run into any of the nastiness of singletons:D. HTH, Jon On Mon, 21 Mar 2005 16:02:51 -0600, Keshav Kode <keshav.kode@xxxxxxxxx> wrote: Hello Cinjuggers,
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: [cinjug-users] request suggestions on Struts book, Mike Helmick |
|---|---|
| Next by Date: | Re: [cinjug-users] request suggestions on Struts book, john . chesher |
| Previous by Thread: | help: How to create virtual current system date for J2EE applications hosted under the same WAS?, Keshav Kode |
| Next by Thread: | help: Co-hosting multiple versions of J2EE applications, Keshav Kode |
| Indexes: | [Date] [Thread] [Top] [All Lists] |