-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWindowsExtraFieldTimeTests.java
62 lines (56 loc) · 1.86 KB
/
WindowsExtraFieldTimeTests.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package software.coley.lljzip;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.coley.lljzip.format.model.LocalFileHeader;
import software.coley.lljzip.format.model.ZipArchive;
import software.coley.lljzip.util.ExtraFieldTime;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests ensuring that the extra field can be read for custom/detailed windows time values.
* This generally means the extra-field is assigned correctly.
*
* @author Matt Coley
*/
public class WindowsExtraFieldTimeTests {
@ParameterizedTest
@ValueSource(strings = {"standard", "naive", "jvm"})
public void validity(@Nonnull String mode) {
Path path = Paths.get("src/test/resources/content-with-windows-time.jar");
try {
long timeCreate = 1000000000000L;
long timeModify = 1200000000000L;
long timeAccess = 1400000000000L;
ZipArchive archive;
switch (mode) {
case "standard":
archive = ZipIO.readStandard(path);
break;
case "naive":
archive = ZipIO.readNaive(path);
break;
case "jvm":
archive = ZipIO.readJvm(path);
break;
default:
throw new IllegalStateException();
}
ExtraFieldTime.TimeWrapper wrapper = read(archive);
assertEquals(timeCreate, wrapper.getCreationMs());
assertEquals(timeModify, wrapper.getModifyMs());
assertEquals(timeAccess, wrapper.getAccessMs());
} catch (IOException ex) {
fail(ex);
}
}
@Nonnull
private ExtraFieldTime.TimeWrapper read(@Nonnull ZipArchive archive) {
LocalFileHeader header = archive.getLocalFiles().get(0);
return Objects.requireNonNull(ExtraFieldTime.read(header), "Missing time data");
}
}