+ All Categories
Home > Technology > Injecting Clock in Java

Injecting Clock in Java

Date post: 09-May-2015
Category:
Upload: daniel-sobral
View: 260 times
Download: 0 times
Share this document with a friend
Description:
A lightning presentation on using injected Clock instances from JSR-310 (Java 8's java.time.*).
12
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential. Injecting Clock
Transcript
Page 1: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock

Page 2: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock is about

Page 3: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock is about

Page 4: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock is about

Page 5: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock is about

Page 6: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

Injecting Clock is about

Page 7: Injecting Clock in Java

© 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

Page 8: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

How does it work?

Page 9: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

How does it work?

Page 10: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

How does it work?

Page 11: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

How does it work?

Page 12: Injecting Clock in Java

© 2014 RichRelevance, Inc. All Rights Reserved. Confidential.

How do I test? •  Inject a clock explicitly

– Mocked – From a Clock factory


Recommended