-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using java.time classes & make work for dates past 2038.
- Loading branch information
1 parent
3a909d0
commit fb55ea1
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.jcraft.jsch; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Date; | ||
import java.util.Random; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SftpATTRSTest { | ||
|
||
private final Random random = new Random(); | ||
|
||
@Test | ||
public void testToDateString0() { | ||
String expected = new Date(0L).toString(); | ||
String actual = SftpATTRS.toDateString(0L); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testToDateStringNow() { | ||
long now = System.currentTimeMillis() / 1000L; | ||
String expected = new Date(now * 1000L).toString(); | ||
String actual = SftpATTRS.toDateString(now); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testToDateStringRandom() { | ||
for (int i = 0; i < 1000000; i++) { | ||
int j = random.ints(Integer.MIN_VALUE, Integer.MAX_VALUE).findFirst().getAsInt(); | ||
long l = Integer.toUnsignedLong(j); | ||
String expected = new Date(l * 1000L).toString(); | ||
String actual = SftpATTRS.toDateString(l); | ||
assertEquals(expected, actual); | ||
} | ||
} | ||
} |