summaryrefslogtreecommitdiff
path: root/src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-21 01:50:08 +0800
committerKeuin <[email protected]>2021-01-21 01:50:08 +0800
commitac3b5e1476dedcefb723f19bd0fdd9a22fcb16e9 (patch)
tree75d0994f3f7aa37c3d240933f0f2d179d318e597 /src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java
parent82e3986045ac7eaca6aaa290fb2283fd6c6c901a (diff)
parent7a5297de3467b1069fdf5e4a1b2aaf510ca35663 (diff)
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java')
-rw-r--r--src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java b/src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java
new file mode 100644
index 0000000..abc19d5
--- /dev/null
+++ b/src/test/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoderTest.java
@@ -0,0 +1,50 @@
+package com.keuin.kbackupfabric.util.backup.name;
+
+import org.junit.Test;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+
+import static org.junit.Assert.*;
+
+public class PrimitiveBackupFileNameEncoderTest {
+
+ @Test
+ public void testConsistency() {
+ LocalDateTime time = LocalDateTime.ofEpochSecond(System.currentTimeMillis() / 1000, 0, ZoneOffset.UTC);
+ String name = "Test Na_me";
+ PrimitiveBackupFileNameEncoder encoder = new PrimitiveBackupFileNameEncoder();
+ BackupFileNameEncoder.BackupBasicInformation information = encoder.decode(encoder.encode(name, time));
+ assertEquals(time, information.time);
+ assertEquals(name, information.customName);
+ }
+
+ @Test
+ public void testEncode() {
+ LocalDateTime time = LocalDateTime.of(1, 1, 1, 1, 1, 1);
+ String customName = "name";
+ PrimitiveBackupFileNameEncoder encoder = new PrimitiveBackupFileNameEncoder();
+ assertEquals("kbackup-0001-01-01_01-01-01_name.zip", encoder.encode(customName, time));
+ }
+
+ @Test
+ public void testDecode() {
+ LocalDateTime time = LocalDateTime.of(1, 1, 1, 1, 1, 1);
+ String customName = "name";
+ PrimitiveBackupFileNameEncoder encoder = new PrimitiveBackupFileNameEncoder();
+ BackupFileNameEncoder.BackupBasicInformation information = encoder.decode("kbackup-0001-01-01_01-01-01_name.zip");
+ assertEquals(time, information.time);
+ assertEquals(customName, information.customName);
+ }
+
+ @Test
+ public void isValid() {
+ PrimitiveBackupFileNameEncoder encoder = new PrimitiveBackupFileNameEncoder();
+ assertTrue(encoder.isValidFileName("kbackup-0001-01-01_01-01-01_name.zip"));
+ assertTrue(encoder.isValidFileName("kbackup-0001-01-01_01-01-01_0001-01-01_01-01-01_name.zip"));
+ assertFalse(encoder.isValidFileName("kbackup-0001-01-01_01-01-01kbackup-0001-01-01_01-01-01_name.zip"));
+ assertFalse(encoder.isValidFileName("kbackup-0001-01-01_01-01-01_name"));
+ assertFalse(encoder.isValidFileName("kbackup-0001-01-01_01-01-01_name.kbi"));
+ assertFalse(encoder.isValidFileName("somefile"));
+ }
+} \ No newline at end of file