Skip to content

Commit

Permalink
fixed test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lwluc committed Nov 29, 2024
1 parent 8b7bd11 commit 09f5c64
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");

}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {

Expand Down

0 comments on commit 09f5c64

Please sign in to comment.