blob: 41c05a19f8a18b88a1a0fd8af6bca46a9e20cadc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package invalid.lena.scrcpy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.nio.file.Files;
public class CrashlogTest {
@Rule
public TemporaryFolder dir = new TemporaryFolder();
@Test
public void pruneKeepsNewestCrashlogsOnly() throws Exception {
for (int i = 0; i < 7; i++) {
File file = new File(dir.getRoot(), "crash-" + i + ".log");
Files.write(file.toPath(), new byte[]{(byte) i});
assertTrue(file.setLastModified(1_000L + i));
}
File unrelated = dir.newFile("notes.txt");
Crashlog.prune(dir.getRoot(), 5);
File[] logs = dir.getRoot().listFiles((parent, name) -> name.endsWith(".log"));
assertEquals(5, logs.length);
assertFalse(new File(dir.getRoot(), "crash-0.log").exists());
assertFalse(new File(dir.getRoot(), "crash-1.log").exists());
assertTrue(unrelated.exists());
}
}
|