JAVA-18445 Cleanup un-committed or un-ignored artifacts - Week 6 - 2023 (conti-1) (moved-1) (#13510)

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2023-02-20 21:08:16 +02:00 committed by GitHub
parent 95026e6b88
commit 253c01ef4f
4 changed files with 51 additions and 28 deletions

5
.gitignore vendored
View File

@ -107,4 +107,7 @@ spring-boot-modules/spring-boot-properties-3/*.log
.sdkmanrc
# Localstack
**/.localstack
**/.localstack
#web-modules/ninja
devDb*.db

View File

@ -48,7 +48,7 @@ class AESUtilUnitTest implements WithAssertions {
IvParameterSpec ivParameterSpec = AESUtil.generateIv();
File inputFile = Paths.get("src/test/resources/baeldung.txt")
.toFile();
File encryptedFile = new File("classpath:baeldung.encrypted");
File encryptedFile = new File("baeldung.encrypted");
File decryptedFile = new File("document.decrypted");
// when
@ -57,8 +57,8 @@ class AESUtilUnitTest implements WithAssertions {
// then
assertThat(inputFile).hasSameTextualContentAs(decryptedFile);
encryptedFile.delete();
decryptedFile.delete();
encryptedFile.deleteOnExit();
decryptedFile.deleteOnExit();
}
@Test

View File

@ -1,8 +1,10 @@
package com.baeldung.serializable_singleton;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
@ -10,8 +12,10 @@ import java.io.ObjectOutputStream;
// Unit test for the EnumSingleton class.
public class EnumSingletonUnitTest {
// Checks that when an EnumSingleton instance is serialized
private static final String ENUM_SINGLETON_TEST_TXT = "enum_singleton_test.txt";
// Checks that when an EnumSingleton instance is serialized
// and then deserialized, its state is preserved.
@Test
public void givenEnumSingleton_whenSerializedAndDeserialized_thenStatePreserved() {
@ -19,11 +23,10 @@ public class EnumSingletonUnitTest {
es1.setState("State One");
try (
FileOutputStream fos = new FileOutputStream("enum_singleton_test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream("enum_singleton_test.txt");
ObjectInputStream ois = new ObjectInputStream(fis)) {
try (FileOutputStream fos = new FileOutputStream(ENUM_SINGLETON_TEST_TXT);
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream(ENUM_SINGLETON_TEST_TXT);
ObjectInputStream ois = new ObjectInputStream(fis)) {
// Serializing.
oos.writeObject(es1);
@ -46,11 +49,10 @@ public class EnumSingletonUnitTest {
public void givenEnumSingleton_whenSerializedAndDeserialized_thenOneInstance() {
EnumSingleton es1 = EnumSingleton.getInstance();
try (
FileOutputStream fos = new FileOutputStream("enum_singleton_test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream("enum_singleton_test.txt");
ObjectInputStream ois = new ObjectInputStream(fis)) {
try (FileOutputStream fos = new FileOutputStream(ENUM_SINGLETON_TEST_TXT);
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream(ENUM_SINGLETON_TEST_TXT);
ObjectInputStream ois = new ObjectInputStream(fis)) {
// Serializing.
oos.writeObject(es1);
@ -66,4 +68,12 @@ public class EnumSingletonUnitTest {
System.out.println(e);
}
}
@AfterAll
public static void cleanUp() {
final File removeFile = new File(ENUM_SINGLETON_TEST_TXT);
if (removeFile.exists()) {
removeFile.deleteOnExit();
}
}
}

View File

@ -1,8 +1,10 @@
package com.baeldung.serializable_singleton;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
@ -10,8 +12,10 @@ import java.io.ObjectOutputStream;
// Unit test for the Singleton class.
public class SingletonUnitTest {
// Checks that when a Singleton instance is serialized
private static final String SINGLETON_TEST_TXT = "singleton_test.txt";
// Checks that when a Singleton instance is serialized
// and then deserialized, its state is preserved.
@Test
public void givenSingleton_whenSerializedAndDeserialized_thenStatePreserved() {
@ -19,11 +23,10 @@ public class SingletonUnitTest {
s1.setState("State One");
try (
FileOutputStream fos = new FileOutputStream("singleton_test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream("singleton_test.txt");
ObjectInputStream ois = new ObjectInputStream(fis)) {
try (FileOutputStream fos = new FileOutputStream(SINGLETON_TEST_TXT);
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream(SINGLETON_TEST_TXT);
ObjectInputStream ois = new ObjectInputStream(fis)) {
// Serializing.
oos.writeObject(s1);
@ -46,11 +49,10 @@ public class SingletonUnitTest {
public void givenSingleton_whenSerializedAndDeserialized_thenTwoInstances() {
Singleton s1 = Singleton.getInstance();
try (
FileOutputStream fos = new FileOutputStream("singleton_test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream("singleton_test.txt");
ObjectInputStream ois = new ObjectInputStream(fis)) {
try (FileOutputStream fos = new FileOutputStream(SINGLETON_TEST_TXT);
ObjectOutputStream oos = new ObjectOutputStream(fos);
FileInputStream fis = new FileInputStream(SINGLETON_TEST_TXT);
ObjectInputStream ois = new ObjectInputStream(fis)) {
// Serializing.
oos.writeObject(s1);
@ -65,4 +67,12 @@ public class SingletonUnitTest {
System.out.println(e);
}
}
@AfterAll
public static void cleanUp() {
final File removeFile = new File(SINGLETON_TEST_TXT);
if (removeFile.exists()) {
removeFile.deleteOnExit();
}
}
}