injecting clock in java
DESCRIPTION
A lightning presentation on using injected Clock instances from JSR-310 (Java 8's java.time.*).TRANSCRIPT
© 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