injecting clock in java

12
© 2014 RichRelevance, Inc. All Rights Reserved. Confidential. Injecting Clock

Upload: daniel-sobral

Post on 09-May-2015

265 views

Category:

Technology


0 download

DESCRIPTION

A lightning presentation on using injected Clock instances from JSR-310 (Java 8's java.time.*).

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