Skip to content

Commit

Permalink
#65 modification times are only stored for existing files in Director…
Browse files Browse the repository at this point in the history
…yCodeResolver
  • Loading branch information
casid committed Mar 6, 2021
1 parent 6aef5c7 commit a3369e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jte/src/main/java/gg/jte/resolve/DirectoryCodeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public DirectoryCodeResolver(Path root) {
public String resolve(String name) {
try {
Path file = root.resolve(name);
byte[] bytes = Files.readAllBytes(file);
modificationTimes.put(name, getLastModified(file));
return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
return new String(bytes, StandardCharsets.UTF_8);
} catch (NoSuchFileException e) {
return null;
} catch (IOException e) {
Expand Down
26 changes: 26 additions & 0 deletions jte/src/test/java/gg/jte/resolve/DirectoryCodeResolverTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gg.jte.resolve;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.nio.file.Paths;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class DirectoryCodeResolverTest {

DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Paths.get("src/test/resources/benchmark"));

@SuppressWarnings("unchecked")
@Test
void modificationTimeDoesNotLeak() throws Exception {
Field modificationTimesField = codeResolver.getClass().getDeclaredField("modificationTimes");
modificationTimesField.setAccessible(true);
Map<String, Long> modificationTimes = (Map<String, Long>)modificationTimesField.get(codeResolver);

codeResolver.resolve("doesNotExist.jte");

assertThat(modificationTimes).isEmpty();
}
}

0 comments on commit a3369e1

Please sign in to comment.