38
38
import org .junit .Before ;
39
39
import org .junit .Test ;
40
40
41
+ import static java .time .temporal .ChronoUnit .SECONDS ;
42
+
41
43
/** Tests for {@link TarStreamBuilder}. */
42
44
public class TarStreamBuilderTest {
43
45
46
+
44
47
private Path fileA ;
45
48
private Path fileB ;
46
49
private Path directoryA ;
@@ -97,12 +100,15 @@ public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOExc
97
100
98
101
@ Test
99
102
public void testToBlob_multiByte () throws IOException {
103
+ Instant MODIFICATION_TIME = Instant .ofEpochMilli (1618041179516l );
104
+ Instant TIME_FROM_TAR_ARCHIVE_ENTRY = MODIFICATION_TIME .truncatedTo (SECONDS );
105
+
100
106
testTarStreamBuilder .addByteEntry (
101
- "日本語" .getBytes (StandardCharsets .UTF_8 ), "test" , Instant . EPOCH );
107
+ "日本語" .getBytes (StandardCharsets .UTF_8 ), "test" , MODIFICATION_TIME );
102
108
testTarStreamBuilder .addByteEntry (
103
- "asdf" .getBytes (StandardCharsets .UTF_8 ), "crepecake" , Instant . EPOCH );
109
+ "asdf" .getBytes (StandardCharsets .UTF_8 ), "crepecake" , MODIFICATION_TIME );
104
110
testTarStreamBuilder .addBlobEntry (
105
- Blobs .from ("jib" ), "jib" .getBytes (StandardCharsets .UTF_8 ).length , "jib" , Instant . EPOCH );
111
+ Blobs .from ("jib" ), "jib" .getBytes (StandardCharsets .UTF_8 ).length , "jib" , MODIFICATION_TIME );
106
112
107
113
// Writes the BLOB and captures the output.
108
114
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream ();
@@ -125,13 +131,13 @@ public void testToBlob_multiByte() throws IOException {
125
131
Assert .assertEquals ("crepecake" , headerFile .getName ());
126
132
Assert .assertEquals (
127
133
"asdf" , new String (ByteStreams .toByteArray (tarArchiveInputStream ), StandardCharsets .UTF_8 ));
128
- Assert .assertEquals (Instant . EPOCH , headerFile .getModTime ().toInstant ());
134
+ Assert .assertEquals (TIME_FROM_TAR_ARCHIVE_ENTRY , headerFile .getModTime ().toInstant ());
129
135
130
136
headerFile = tarArchiveInputStream .getNextTarEntry ();
131
137
Assert .assertEquals ("jib" , headerFile .getName ());
132
138
Assert .assertEquals (
133
139
"jib" , new String (ByteStreams .toByteArray (tarArchiveInputStream ), StandardCharsets .UTF_8 ));
134
- Assert .assertEquals (Instant . EPOCH , headerFile .getModTime ().toInstant ());
140
+ Assert .assertEquals (TIME_FROM_TAR_ARCHIVE_ENTRY , headerFile .getModTime ().toInstant ());
135
141
136
142
Assert .assertNull (tarArchiveInputStream .getNextTarEntry ());
137
143
}
0 commit comments