Skip to content

Commit 3c72f6d

Browse files
authored
Fix Flaky Test SpannerPersistentPropertyImplTests#testNullColumnName (#4214)
## Issue Test `SpannerPersistentPropertyImplTests#testNullColumnName` is flaky. See #4213 ## Fix This fix drops brittle message checks (including dynamic Mockito class names) and instead asserts stable parts of the error plus a regex that accepts any of the expected property names. It still verifies that an exception is thrown for a null field name on TestEntity and that the message references the entity/property, but no longer fails due to environment-dependent wording.
1 parent b381f29 commit 3c72f6d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

spring-cloud-gcp-data-spanner/src/test/java/com/google/cloud/spring/data/spanner/core/mapping/SpannerPersistentPropertyImplTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ void testNullColumnName() {
4848
context.setFieldNamingStrategy(namingStrat);
4949

5050
assertThatThrownBy(() -> context.getPersistentEntity(TestEntity.class))
51-
.hasMessageContaining("Invalid (null or empty) field name returned for "
52-
+ "property @com.google.cloud.spring.data.spanner.core.mapping.PrimaryKey")
53-
.hasMessageContaining("keyOrder=1")
54-
.hasMessageContaining("value=1")
55-
.hasMessageContaining("java.lang.String com.google.cloud.spring.data.spanner.core.mapping."
56-
+ "SpannerPersistentPropertyImplTests$TestEntity.id by class "
57-
+ "org.springframework.data.mapping.model.FieldNamingStrategy$MockitoMock$");
51+
.hasMessageContaining("Invalid (null or empty) field name returned for ")
52+
.hasMessageContaining("com.google.cloud.spring.data.spanner.core.mapping.SpannerPersistentPropertyImplTests$TestEntity")
53+
.satisfies(t -> {
54+
String msg = t.getMessage();
55+
assertThat(msg).matches("(?s).*SpannerPersistentPropertyImplTests\\$TestEntity\\.(id|doubleList|other)\\b.*");
56+
});
5857
}
5958

6059

0 commit comments

Comments
 (0)