Hello, how can I use a copy method like for data c...
# announcements
i
Hello, how can I use a copy method like for data class with a non data class? I have a class that initialize a date = now() but I want to change it for a test case!
m
You would have to implement that method yourself
i
Any library can do that? it's just for test purpose!
j
You have a (hidden) dependency on a clock, then. Pass the clock (or the date/time/datetime from the clock, depends) into the constructor of the object. In the test, you can use a test clock, which gives any time you like
👍 2
m
The need for this test should make you question the design of the class under test. If the source is under your control, refactor it to accept a date parameter in the constructor; otherwise create a subclass in the test path that can set the date to the value you want and use it in your test case.
👍 1
i
I will try to refactor the code, thx.
👏 1