@@ -690,7 +690,34 @@ void serializeCurrentVersionClasses(Class<?> clazz) throws Exception {
690690 }
691691
692692 @ ParameterizedTest
693- @ MethodSource ("getFilesToDeserialize" )
693+ @ MethodSource ("getCurrentSerializedFiles" )
694+ void shouldBeAbleToDeserializeClassFromCurrentVersion (Path filePath ) {
695+ try (FileInputStream fileInputStream = new FileInputStream (filePath .toFile ());
696+ ObjectInputStream objectInputStream = new ObjectInputStream (fileInputStream )) {
697+ Object obj = objectInputStream .readObject ();
698+ Class <?> clazz = Class .forName (filePath .getFileName ().toString ().replace (".serialized" , "" ));
699+ assertThat (obj ).isInstanceOf (clazz );
700+ }
701+ catch (IOException | ClassNotFoundException ex ) {
702+ fail ("Could not deserialize " + filePath , ex );
703+ }
704+ }
705+
706+ static Stream <Path > getCurrentSerializedFiles () throws IOException {
707+ assertThat (currentVersionFolder .toFile ().exists ())
708+ .as ("Make sure that the " + currentVersionFolder + " exists and is not empty" )
709+ .isTrue ();
710+ try (Stream <Path > files = Files .list (currentVersionFolder )) {
711+ if (files .findFirst ().isEmpty ()) {
712+ fail ("Please make sure to run SpringSecurityCoreVersionSerializableTests#serializeCurrentVersionClasses for the "
713+ + getPreviousVersion () + " version" );
714+ }
715+ }
716+ return Files .list (currentVersionFolder );
717+ }
718+
719+ @ ParameterizedTest
720+ @ MethodSource ("getPreviousSerializedFiles" )
694721 void shouldBeAbleToDeserializeClassFromPreviousVersion (Path filePath ) {
695722 try (FileInputStream fileInputStream = new FileInputStream (filePath .toFile ());
696723 ObjectInputStream objectInputStream = new ObjectInputStream (fileInputStream )) {
@@ -703,7 +730,7 @@ void shouldBeAbleToDeserializeClassFromPreviousVersion(Path filePath) {
703730 }
704731 }
705732
706- static Stream <Path > getFilesToDeserialize () throws IOException {
733+ static Stream <Path > getPreviousSerializedFiles () throws IOException {
707734 assertThat (previousVersionFolder .toFile ().exists ())
708735 .as ("Make sure that the " + previousVersionFolder + " exists and is not empty" )
709736 .isTrue ();
0 commit comments