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
Milan Hruban
05/29/2020, 2:27 PM
You would have to implement that method yourself
i
iguissouma
05/29/2020, 2:30 PM
Any library can do that? it's just for test purpose!
j
James Richardson
05/29/2020, 2:59 PM
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
Matteo Mirk
05/29/2020, 3:08 PM
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.