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
|
package com.keuin.kbackupfabric.backup.name;
import org.junit.Test;
import java.time.LocalDateTime;
import static org.junit.Assert.*;
public class IncrementalBackupFileNameEncoderTest {
@Test
public void testEncode() {
LocalDateTime time = LocalDateTime.of(1, 1, 1, 1, 1, 1);
String customName = "name";
IncrementalBackupFileNameEncoder encoder = new IncrementalBackupFileNameEncoder();
assertEquals("incremental-0001-01-01_01-01-01_name.kbi", encoder.encode(customName, time));
}
@Test
public void testDecode() {
LocalDateTime time = LocalDateTime.of(1, 1, 1, 1, 1, 1);
String customName = "name";
IncrementalBackupFileNameEncoder encoder = new IncrementalBackupFileNameEncoder();
BackupFileNameEncoder.BackupBasicInformation information = encoder.decode("incremental-0001-01-01_01-01-01_name.kbi");
assertEquals(time, information.time);
assertEquals(customName, information.customName);
}
@Test
public void isValid() {
IncrementalBackupFileNameEncoder encoder = new IncrementalBackupFileNameEncoder();
assertTrue(encoder.isValidFileName("incremental-0001-01-01_01-01-01_name.kbi"));
assertTrue(encoder.isValidFileName("incremental-0001-01-01_01-01-01_0001-01-01_01-01-01_name.kbi"));
assertFalse(encoder.isValidFileName("incremental-0001-01-01_01-01-01incremental-0001-01-01_01-01-01_name.kbi"));
assertFalse(encoder.isValidFileName("incremental-0001-01-01_01-01-01_name"));
assertFalse(encoder.isValidFileName("incremental-0001-01-01_01-01-01_name.zip"));
assertFalse(encoder.isValidFileName("somefile"));
}
}
|