[JAVA-32168] Cleanup un-committed or un-ignored artifacts - Week 11 - 2024 (#16124)

This commit is contained in:
timis1 2024-03-15 10:11:50 +02:00 committed by GitHub
parent 34fec650c0
commit 40326c74b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.baeldung.writehashmaptocsvfile;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import java.io.File;
@ -63,4 +64,16 @@ public class WriteHashmaptoCVSFileUnitTest {
// Ensure the CSV file exists
assertTrue(new File("employee_data2.csv").exists());
}
@AfterAll
public static void cleanUp() {
final File employeeData = new File("employee_data.csv");
if (employeeData.exists()) {
employeeData.deleteOnExit();
}
final File employeeData2 = new File("employee_data2.csv");
if (employeeData2.exists()) {
employeeData2.deleteOnExit();
}
}
}

View File

@ -3,12 +3,15 @@ package com.baeldung.batchtesting;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.batch.test.AssertFile.assertFileEquals;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import com.baeldung.batchtesting.model.Book;
import com.baeldung.batchtesting.model.BookRecord;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
@ -25,13 +28,15 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.test.context.ContextConfiguration;
import com.baeldung.batchtesting.model.Book;
import com.baeldung.batchtesting.model.BookRecord;
@SpringBatchTest
@EnableAutoConfiguration
@ContextConfiguration(classes = { SpringBatchConfiguration.class })
public class SpringBatchStepScopeIntegrationTest {
private static final String TEST_OUTPUT = "src/test/resources/output/actual-output.json";
private static String TEST_OUTPUT = "src/test/resources/output/actual-output.json";
private static final String EXPECTED_OUTPUT_ONE = "src/test/resources/output/expected-output-one.json";
@ -45,6 +50,13 @@ public class SpringBatchStepScopeIntegrationTest {
@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
@BeforeAll
public static void setup() throws IOException {
final File tempFile = Files.createTempFile("actual-output", ".json").toFile();
Files.copy(Paths.get(TEST_OUTPUT), Paths.get(tempFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
TEST_OUTPUT = tempFile.getAbsolutePath();
}
private JobParameters defaultJobParameters() {
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
paramsBuilder.addString("file.input", TEST_INPUT_ONE);