DATACMNS-867 - Favor LocalDateTime over ZonedDateTime in CurrentDateTimeProvider.

Use LocalDateTime to avoid timezone issues just because the default auditing cannot handle it when the domain type property comes from eg. jodatime.
This commit is contained in:
Christoph Strobl
2017-02-06 15:27:03 +01:00
committed by Oliver Gierke
parent 378baba06a
commit d363e8f2c2
3 changed files with 26 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.data.auditing;
import static org.assertj.core.api.Assertions.*;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Optional;
import org.junit.Test;
@@ -28,6 +29,7 @@ import org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.Refl
* Unit tests for {@link DefaultAuditableBeanWrapperFactory}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.5
*/
public class DefaultAuditableBeanWrapperFactoryUnitTests {
@@ -78,4 +80,17 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
});
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-867
public void errorsWhenUnableToConvertDateViaIntermedeateJavaUtilDateConversion() {
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
ZonedDateTime zonedDateTime = ZonedDateTime.now();
Optional<AuditableBeanWrapper> wrapper = factory.getBeanWrapperFor(Optional.of(user));
assertThat(wrapper).hasValueSatisfying(it -> {
it.setLastModifiedDate(Optional.of(zonedDateTime));
});
}
}