Skip to content

Commit a79c630

Browse files
committed
Adapt tests to MappingException cause when entity creation fails.
Closes #1602
1 parent 0ec97e3 commit a79c630

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/mapping/BasicCassandraPersistentTupleEntityUnitTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,22 @@ void shouldCreateElementsInOrder() {
6464
void shouldReportDuplicateMappings() {
6565

6666
assertThatThrownBy(() -> this.mappingContext.getRequiredPersistentEntity(DuplicateElement.class))
67-
.isInstanceOf(MappingException.class).hasMessageContaining("Duplicate ordinal [0]");
67+
.isInstanceOf(MappingException.class).cause().hasMessageContaining("Duplicate ordinal [0]");
6868
}
6969

7070
@Test // DATACASS-523
7171
void shouldReportMissingOrdinalMappings() {
7272

7373
assertThatThrownBy(() -> this.mappingContext.getRequiredPersistentEntity(MissingElementOrdinals.class))
74-
.isInstanceOf(MappingException.class).hasMessageContaining("Mapped tuple has no")
74+
.isInstanceOf(MappingException.class).rootCause().hasMessageContaining("Mapped tuple has no")
7575
.hasMessageContaining("for ordinal(s): 0");
7676
}
7777

7878
@Test // DATACASS-523
7979
void shouldReportNegativeOrdinalIndex() {
8080

8181
assertThatThrownBy(() -> this.mappingContext.getRequiredPersistentEntity(NegativeIndex.class))
82+
.rootCause()
8283
.isInstanceOf(IllegalArgumentException.class)
8384
.hasMessageContaining("Element ordinal must be greater or equal to zero for property [street] in entity");
8485
}
@@ -88,6 +89,7 @@ void shouldReportNoElements() {
8889

8990
assertThatThrownBy(() -> this.mappingContext.getRequiredPersistentEntity(NoElements.class))
9091
.isInstanceOf(MappingException.class)
92+
.rootCause()
9193
.hasMessageContaining("Mapped tuple contains no persistent elements annotated");
9294
}
9395

@@ -96,6 +98,7 @@ void shouldReportMissingAnnotations() {
9698

9799
assertThatThrownBy(() -> this.mappingContext.getRequiredPersistentEntity(MissingAnnotation.class))
98100
.isInstanceOf(MappingException.class)
101+
.cause()
99102
.hasMessageContaining("Missing @Element annotation in mapped tuple type for property [street]");
100103
}
101104

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/mapping/CassandraMappingContextUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void shouldNotRetainInvalidEntitiesInCache() {
365365
mappingContext.getPersistentEntity(InvalidEntityWithIdAndPrimaryKeyColumn.class);
366366
fail("Missing MappingException");
367367
} catch (MappingException e) {
368-
assertThat(e).isInstanceOf(VerifierMappingExceptions.class);
368+
assertThat(e).hasCauseInstanceOf(VerifierMappingExceptions.class);
369369
}
370370

371371
assertThat(mappingContext.getUserDefinedTypeEntities()).isEmpty();

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/mapping/CompositeCassandraPersistentEntityMetadataVerifierUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void shouldFailWithPersistentAndPrimaryKeyClassAnnotations() {
6767
verifier.verify(context.getRequiredPersistentEntity(TooManyAnnotations.class));
6868
fail("Missing MappingException");
6969
} catch (MappingException e) {
70-
assertThat(e).hasMessageContaining("Entity cannot be of type @Table and @PrimaryKeyClass");
70+
assertThat(e).cause().hasMessageContaining("Entity cannot be of type @Table and @PrimaryKeyClass");
7171
}
7272
}
7373

0 commit comments

Comments
 (0)