Test support for serializable records in SerializationUtils
See gh-28798
This commit is contained in:
parent
18ce31f18a
commit
5c2870ebd9
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.util;
|
package org.springframework.util;
|
||||||
|
|
||||||
|
import java.io.NotSerializableException;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -28,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
* Unit tests for {@link SerializationUtils}.
|
* Unit tests for {@link SerializationUtils}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 3.0.5
|
* @since 3.0.5
|
||||||
*/
|
*/
|
||||||
class SerializationUtilsTests {
|
class SerializationUtilsTests {
|
||||||
|
|
@ -43,6 +46,24 @@ class SerializationUtilsTests {
|
||||||
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize("foo"))).isEqualTo("foo");
|
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize("foo"))).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
void serializeNonSerializableRecord() {
|
||||||
|
record Person(String firstName, String lastName) {}
|
||||||
|
Person jane = new Person("Jane", "Doe");
|
||||||
|
assertThatIllegalArgumentException()
|
||||||
|
.isThrownBy(() -> SerializationUtils.serialize(jane))
|
||||||
|
.withCauseExactlyInstanceOf(NotSerializableException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
void serializeAndDeserializeSerializableRecord() {
|
||||||
|
record Person(String firstName, String lastName) implements Serializable {}
|
||||||
|
Person jane = new Person("Jane", "Doe");
|
||||||
|
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize(jane))).isEqualTo(jane);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
void deserializeUndefined() {
|
void deserializeUndefined() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue