Skip to content

Commit

Permalink
feat(impl): [#528] harden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed May 7, 2024
1 parent 11ba40f commit 55b09f8
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.assertj.core.api.ThrowableAssert;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.edc.client.policy.Policy;
Expand Down Expand Up @@ -104,18 +105,22 @@ void saveDuplicate() throws BlobPersistenceException, JsonProcessingException {
when(mockPersistence.getBlob(anyString())).thenReturn(Optional.of(mapper.writeValueAsBytes(policies)));

// ACT & ASSERT
assertThatThrownBy(() -> testee.save("testBpn", policy)).isInstanceOf(PolicyStoreException.class);
assertThatThrownBy(() -> testee.save("testBpn", policy)).isInstanceOf(PolicyStoreException.class)
.hasMessageContaining("'test'")
.hasMessageContaining("already exists");
}

@Test
void saveWithError() throws BlobPersistenceException {
void saveWithReadError() throws BlobPersistenceException {
// ARRANGE
final var policy = new Policy("test", OffsetDateTime.now(), OffsetDateTime.now(), emptyList());
when(mockPersistence.getBlob(any())).thenThrow(
new BlobPersistenceException("test", new IllegalStateException()));

// ACT & ASSERT
assertThatThrownBy(() -> testee.save("testBpn", policy)).isInstanceOf(PolicyStoreException.class);
final ThrowableAssert.ThrowingCallable call = () -> testee.save("testBpn", policy);
assertThatThrownBy(call).isInstanceOf(PolicyStoreException.class)
.hasMessageContaining("Unable to read policy data");
}

@Test
Expand All @@ -126,7 +131,9 @@ void saveWithWriteError() throws BlobPersistenceException {
.putBlob(any(), any());

// ACT & ASSERT
assertThatThrownBy(() -> testee.save("testBpn", policy)).isInstanceOf(PolicyStoreException.class);
final ThrowableAssert.ThrowingCallable call = () -> testee.save("testBpn", policy);
assertThatThrownBy(call).isInstanceOf(PolicyStoreException.class)
.hasMessageContaining("Unable to store policy data");
}
}

Expand Down Expand Up @@ -213,7 +220,9 @@ void readAll_withBpn_withError() throws BlobPersistenceException, JsonProcessing
final var localTestee = new PolicyPersistence(mockPersistence, mapperMock);

// ACT & ASSERT
assertThatThrownBy(() -> localTestee.readAll("testBpn")).isInstanceOf(PolicyStoreException.class);
final ThrowableAssert.ThrowingCallable call = () -> localTestee.readAll("testBpn");
assertThatThrownBy(call).isInstanceOf(PolicyStoreException.class)
.hasMessageContaining("Could not read the policies from the store");
}
}
}

0 comments on commit 55b09f8

Please sign in to comment.