Injecting Clock in Java
-
Upload
daniel-sobral -
Category
Technology
-
view
259 -
download
0
description
Transcript of Injecting Clock in Java
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock is about
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock is about
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock is about
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock is about
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Injecting Clock is about
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
Why do we care?
• You can write tests that do not depend on when they are run – Ward against Daylight Savings transition
• You can write tests for specific timing conditions – Test these “after NN hours” rules
• Offers another way of controlling timezone to be used by some code – More selective than default time zone
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
How does it work?
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
How does it work?
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
How does it work?
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
How does it work?
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.
How do I test? • Inject a clock explicitly
– Mocked – From a Clock factory