Skip to content

Instantly share code, notes, and snippets.

@relax-more
Created December 10, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relax-more/eeaf2ae442b7907e55e1 to your computer and use it in GitHub Desktop.
Save relax-more/eeaf2ae442b7907e55e1 to your computer and use it in GitHub Desktop.
Java Clock.fixed
@Named
public class Service(){
Clock clock;
public Service(Clock clock){
this.clock = clock;
}
public void work(){
System.Out.plintln("time:" + Instant.now(clock));
}
}
Clock clock = Clock.fixed(Instant.parse("2015-01-01T00:00:00Z"), ZoneId.systemDefault());
Service service;
@Before
public void before(){
service = new Service(clock);
}
@Test
public void test(){
service.work(); // shown 2015-01.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment