2023-05-01

Tests for methods using ZonedDateTime

Diffblue Cover now has the ability to write complete unit tests, with meaningful assertions, for methods which use the ZonedDateTime class, as shown in the example below.

  /**
  * Method under test: {@link Time#addAnHour(ZonedDateTime)}
  */
  @Test
  public void testAddAnHour() {
    // Arrange
    Time time = new Time(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC));
    LocalDate ofResult = LocalDate.of(1970, 1, 1);

    // Act
    ZonedDateTime actualAddAnHourResult = time.addAnHour(ofResult.atStartOfDay().atZone(ZoneOffset.UTC));

    // Assert
    assertEquals("Z", actualAddAnHourResult.getZone().toString());
    LocalDateTime toLocalDateTimeResult = actualAddAnHourResult.toLocalDateTime();
    LocalDate toLocalDateResult = toLocalDateTimeResult.toLocalDate();
    assertSame(ofResult, toLocalDateResult);
    assertEquals("1970-01-01", toLocalDateResult.toString());
    assertEquals("01:00", toLocalDateTimeResult.toLocalTime().toString());
  }

The test shown above initializes a Time object with a ZonedDateTime set to January 1, 1970 at midnight in UTC. It then calls the addAnHour method with a ZonedDateTime object set to the same date and time, but with a UTC offset of zero.

This test asserts that the result of addAnHour has a time zone of UTC, and that its local date is the same as the original date. It also asserts that the local time of the result is one hour after midnight.

Diffblue licensing service status page

We are pleased to announce the launch of Diffblue's Licensing Service Status page. This new resource provides users with real-time updates on the status of our licensing services. With this service, users can quickly and easily check the status of Diffblue's licensing service and receive updates on any service disruptions or maintenance periods.

Enhancements

  • Cover now writes tests with meaningful assertions for methods which use ZonedDateTime. [Ref: TG-18406]

  • IntelliJ Plugin: Improved logging and remediation advice for situations where attempts to license Cover fail due to insufficient directory permissions. [Ref: TG-19015]

Resolved Issues

  • Reports: Resolved an issue which, in some circumstances, would prevent Cover from uploading reports to a Cover Reports instance, reporting an ERROR containing Message: could not execute statement; SQL [n/a]; constraint [run_coverage_pkey];. [Ref: TG-19096]

  • IntelliJ Plugin: Resolved an issue which caused Cover to report an AlreadyDisposedException if a module was renamed shortly after clicking 'Write Tests'. [Ref: TG-19017]

  • IntelliJ Plugin: Resolved an issue which caused Cover to silently fail after clicking 'fix all issues' after renaming a module. [Ref: TG-18992]

  • Resolved an issue which, in some circumstances, caused Cover to not write tests for code using JwsHeader class. [Ref: TG-19018]

  • Resolved an issue which, in some circumstances, caused Cover to write failing tests containing .getClassLoader(). [Ref: TG-18998]

  • Resolved an issue which caused Cover to not write tests because of Spring beans with primitive type names. [Ref: TG-18628]

Known Issues

  • Cover may produce tests for JUnit 4.10 and lower that do not compile due to the use of assertNotEquals. [Ref: TG-17605]

  • IntelliJ Plugin: Upgrading to IntelliJ IDEA 2022.3 may, in some circumstances, cause existing run configurations to no longer produce tests. Removing any run configurations for that entity and writing tests again will recreate a working run configuration. [Ref: TG-18282]

Last updated