Skip to main content
edited body
Source Link
KiriSakow
  • 1.3k
  • 1
  • 17
  • 27

Add a new java.time.Clock attribute to the tested class MyService and make sure the new attribute will instantiatebe initialized properly at default values with an instantiation block or a constructor:

import java.time.Clock; import java.time.LocalDateTime; public class MyService { // (...) private Clock clock; public Clock getClock() { return clock; } public void setClock(Clock newClock) { clock = newClock; } public void initDefaultClock() { setClock( Clock.system( Clock.systemDefaultZone().getZone() // You can just as well use // java.util.TimeZone.getDefault().toZoneId() instead ) ); } { initDefaultClock(); // instantiationinitialisation in an instantiation block, but // it can be done in a constructor just as well } // (...) } 

Add a new java.time.Clock attribute to the tested class MyService and make sure the new attribute will instantiate properly at default values with an instantiation block or a constructor:

import java.time.Clock; import java.time.LocalDateTime; public class MyService { // (...) private Clock clock; public Clock getClock() { return clock; } public void setClock(Clock newClock) { clock = newClock; } public void initDefaultClock() { setClock( Clock.system( Clock.systemDefaultZone().getZone() // You can just as well use // java.util.TimeZone.getDefault().toZoneId() instead ) ); } { initDefaultClock(); // instantiation in an instantiation block, but // it can be done in a constructor just as well } // (...) } 

Add a new java.time.Clock attribute to the tested class MyService and make sure the new attribute will be initialized properly at default values with an instantiation block or a constructor:

import java.time.Clock; import java.time.LocalDateTime; public class MyService { // (...) private Clock clock; public Clock getClock() { return clock; } public void setClock(Clock newClock) { clock = newClock; } public void initDefaultClock() { setClock( Clock.system( Clock.systemDefaultZone().getZone() // You can just as well use // java.util.TimeZone.getDefault().toZoneId() instead ) ); } { initDefaultClock(); // initialisation in an instantiation block, but // it can be done in a constructor just as well } // (...) } 
added 9 characters in body
Source Link
KiriSakow
  • 1.3k
  • 1
  • 17
  • 27

Just found a (working) way to override current system time in a Java SE 8 JUnit test class powered by EasyMock, without PowerMock and without Joda Time.

A working way to override current system time for JUnit testing purposes in a Java 8 web application with EasyMock, without Joda Time, and without PowerMock.

Just found a (working) way to override current system time in a Java SE 8 JUnit test class powered by EasyMock, without PowerMock and without Joda Time.

A working way to override current system time for JUnit testing purposes in a Java 8 web application with EasyMock, without Joda Time, and without PowerMock.

added 9 characters in body
Source Link
KiriSakow
  • 1.3k
  • 1
  • 17
  • 27

Just found a (working) way to override current system time in a Java SE 8 JUnit test class powered by EasyMock, without PowerMock orand without Joda Time.

Just found a (working) way to override current system time in a Java SE 8 JUnit test class powered by EasyMock, without PowerMock or Joda Time.

Just found a (working) way to override current system time in a Java SE 8 JUnit test class powered by EasyMock, without PowerMock and without Joda Time.

Source Link
KiriSakow
  • 1.3k
  • 1
  • 17
  • 27
Loading