Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Injecting Clock in Java

Injecting Clock in Java

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

Daniel Capo Sobral

April 18, 2014
Tweet

More Decks by Daniel Capo Sobral

Other Decks in Programming

Transcript

  1. © 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
  2. © 2014 RichRelevance, Inc. All Rights Reserved. Confidential. How do

    I test? •  Inject a clock explicitly – Mocked – From a Clock factory