Skip to content

Commit e879e06

Browse files
committed
Fix testGetVersionFromProperties_InvalidFile test when running as native image test.
1 parent d186e91 commit e879e06

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

powertools-common/src/test/java/software/amazon/lambda/powertools/common/internal/UserAgentConfiguratorTest.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import static software.amazon.lambda.powertools.common.internal.UserAgentConfigurator.getVersionFromProperties;
2222

2323
import java.io.File;
24-
import java.util.Objects;
24+
import java.io.IOException;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
2527
import java.util.regex.Pattern;
28+
2629
import org.junit.jupiter.api.Test;
2730
import org.junitpioneer.jupiter.SetEnvironmentVariable;
2831

@@ -61,14 +64,18 @@ void testGetVersionFromProperties_FileNotExist() {
6164
}
6265

6366
@Test
64-
void testGetVersionFromProperties_InvalidFile() {
65-
File f = new File(Objects.requireNonNull(Thread.currentThread().getContextClassLoader()
66-
.getResource("unreadable.properties")).getPath());
67+
void testGetVersionFromProperties_InvalidFile() throws IOException {
68+
Path tempFile = Files.createTempFile("unreadable", ".properties");
69+
File f = tempFile.toFile();
6770
f.setReadable(false);
6871

69-
String version = getVersionFromProperties("unreadable.properties", VERSION_KEY);
72+
String version = getVersionFromProperties(f.getName(), VERSION_KEY);
7073

7174
assertThat(version).isEqualTo("NA");
75+
76+
// Cleanup
77+
f.setReadable(true);
78+
Files.deleteIfExists(tempFile);
7279
}
7380

7481
@Test

0 commit comments

Comments
 (0)