diff --git a/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/adapter/carbonawarecomputing/CarbonAwareComputingMapperTest.java b/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/adapter/carbonawarecomputing/CarbonAwareComputingMapperTest.java index c96bafc..342739e 100644 --- a/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/adapter/carbonawarecomputing/CarbonAwareComputingMapperTest.java +++ b/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/adapter/carbonawarecomputing/CarbonAwareComputingMapperTest.java @@ -2,11 +2,13 @@ import de.envite.greenbpm.api.carbonawarecomputing.model.EmissionsData; import de.envite.greenbpm.carbonreductor.core.domain.model.EmissionTimeframe; +import io.github.domainprimitives.validation.InvariantException; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -43,4 +45,17 @@ void should_map_all_fields_except_earliestForecastedValue_for_timestamp_in_the_f softAssertions.assertThat(result.getOptimalValue().getValue()).isEqualTo(emissionsData.getValue()); softAssertions.assertAll(); } + + @Test + void should_throw_if_timestamp_is_null() { + EmissionsData emissionsData = mock(EmissionsData.class); + when(emissionsData.getValue()).thenReturn(2.0); + when(emissionsData.getTimestamp()).thenReturn(null); + + assertThatThrownBy(() -> classUnderTest.mapToDomain(emissionsData)) + .isInstanceOf(InvariantException.class) + .hasMessageContaining("OptimalTime should not be null"); + + } + } \ No newline at end of file diff --git a/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/domain/model/emissionframe/OptimalTimeTest.java b/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/domain/model/emissionframe/OptimalTimeTest.java index 0b4cf43..eba4938 100644 --- a/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/domain/model/emissionframe/OptimalTimeTest.java +++ b/carbon-reductor-core/src/test/java/de/envite/greenbpm/carbonreductor/core/domain/model/emissionframe/OptimalTimeTest.java @@ -1,6 +1,7 @@ package de.envite.greenbpm.carbonreductor.core.domain.model.emissionframe; import io.github.domainprimitives.validation.InvariantException; +import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -18,6 +19,22 @@ void should_not_throw_if_valid() { assertDoesNotThrow(() -> new OptimalTime(OffsetDateTime.now())); } + @Nested + class ConvertToOffsetDateTime { + + @Test + void should_convert() { + final OffsetDateTime offsetDateTime = OffsetDateTime.now(); + + final OptimalTime optimalTime = new OptimalTime(offsetDateTime); + + SoftAssertions softAssertions = new SoftAssertions(); + softAssertions.assertThat(optimalTime.asOffsetDateTime()).isEqualTo(offsetDateTime); + softAssertions.assertThat(optimalTime.asOffsetDateTime()).isInstanceOf(OffsetDateTime.class); + softAssertions.assertAll(); + } + } + @Nested class IsInFuture {