From 8f77afc2fb1ad9c9b7e8e86499591fb812bee384 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 5 Nov 2018 10:01:18 +0000 Subject: [PATCH] JAL-3141 Slightly improved message and more thorough tests --- resources/lang/Messages.properties | 2 +- resources/lang/Messages_es.properties | 2 +- test/jalview/io/BackupFilesTest.java | 101 ++++++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 0d584b8..35b885c 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1364,7 +1364,7 @@ label.most_polymer_residues = Most Polymer Residues label.cached_structures = Cached Structures label.free_text_search = Free Text Search label.backupfiles_confirm_delete = Confirm delete -label.backupfiles_confirm_delete_old_files = Delete the following older backup files? +label.backupfiles_confirm_delete_old_files = Delete the following older backup files? (see the Backups tab in Preferences for more options) label.backupfiles_confirm_save_file = Confirm save file label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Something possibly went wrong with the backups of this file, write the new file anyway? label.backups = Backups diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index bd7c7b3..e109cd3 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1366,7 +1366,7 @@ label.cached_structures = Estructuras en Cach label.free_text_search = Búsqueda de texto libre # dodgy tranlations by Ben and Google translate -- probably could do better label.backupfiles_confirm_delete = Confirmar borrar -label.backupfiles_confirm_delete_old_files = ¿Borrar los siguientes archivos? +label.backupfiles_confirm_delete_old_files = ¿Borrar los siguientes archivos? (ver la pestaña 'Copias' de la ventana de Preferencias para más opciones) label.backupfiles_confirm_save_file = Confirmar guardar archivo label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Posiblemente algo está mal con los archivos de copia de seguridad. ¿Guardar el nuevo archivo? label.backups = Copias diff --git a/test/jalview/io/BackupFilesTest.java b/test/jalview/io/BackupFilesTest.java index c1a8d4c..f15716b 100644 --- a/test/jalview/io/BackupFilesTest.java +++ b/test/jalview/io/BackupFilesTest.java @@ -13,6 +13,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; import java.util.List; import java.util.TreeMap; @@ -33,13 +36,19 @@ public class BackupFilesTest private static boolean actuallyDeleteTmpFiles = true; private static String testDir = "examples"; - private static String testFilename = "backupfilestest.fa"; + private static String testBasename = "backupfilestest"; + + private static String testExt = ".fa"; + + private static String testFilename = testBasename + testExt; private static String testFile = testDir + File.separatorChar + testFilename; - private static String newFilename = "backupfilestestTemp.fa"; + private static String newBasename = testBasename + "Temp"; + + private static String newFilename = newBasename + testExt; private static String newFile = testDir + File.separatorChar + newFilename; @@ -67,7 +76,7 @@ public class BackupFilesTest setBackupFilesOptions(false, true, true); // init the newFile and backups (i.e. make sure newFile exists on its own - // and has no backups) + // and has no backups initNewFileForTesting(); // now save again @@ -98,10 +107,32 @@ public class BackupFilesTest } // check 10 backup files - int[] indexes1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + HashMap correctindexmap = new HashMap(); + correctindexmap.put(1, "backupfilestestTemp_BACKUPTEST-00000001.fa"); + correctindexmap.put(2, "backupfilestestTemp_BACKUPTEST-00000002.fa"); + correctindexmap.put(3, "backupfilestestTemp_BACKUPTEST-00000003.fa"); + correctindexmap.put(4, "backupfilestestTemp_BACKUPTEST-00000004.fa"); + correctindexmap.put(5, "backupfilestestTemp_BACKUPTEST-00000005.fa"); + correctindexmap.put(6, "backupfilestestTemp_BACKUPTEST-00000006.fa"); + correctindexmap.put(7, "backupfilestestTemp_BACKUPTEST-00000007.fa"); + correctindexmap.put(8, "backupfilestestTemp_BACKUPTEST-00000008.fa"); + correctindexmap.put(9, "backupfilestestTemp_BACKUPTEST-00000009.fa"); + correctindexmap.put(10, "backupfilestestTemp_BACKUPTEST-00000010.fa"); + HashMap wrongindexmap = new HashMap(); + wrongindexmap.put(1, "backupfilestestTemp_BACKUPTEST-1.fa"); + wrongindexmap.put(2, "backupfilestestTemp_BACKUPTEST-00000002.fa"); + wrongindexmap.put(3, "backupfilestestTemp_BACKUPTEST-00000003.fa"); + wrongindexmap.put(4, "backupfilestestTemp_BACKUPTEST-00000004.fa"); + wrongindexmap.put(5, "backupfilestestTemp_BACKUPTEST-00000005.fa"); + wrongindexmap.put(6, "backupfilestestTemp_BACKUPTEST-00000006.fa"); + wrongindexmap.put(7, "backupfilestestTemp_BACKUPTEST-00000007.fa"); + wrongindexmap.put(8, "backupfilestestTemp_BACKUPTEST-00000008.fa"); + wrongindexmap.put(9, "backupfilestestTemp_BACKUPTEST-00000009.fa"); + wrongindexmap.put(10, "backupfilestestTemp_BACKUPTEST-00000010.fa"); int[] indexes2 = { 3, 4, 5, 6, 7, 8, 9, 10 }; int[] indexes3 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - Assert.assertTrue(checkBackupFiles(indexes1)); + Assert.assertTrue(checkBackupFiles(correctindexmap)); + Assert.assertFalse(checkBackupFiles(wrongindexmap)); Assert.assertFalse(checkBackupFiles(indexes2)); Assert.assertFalse(checkBackupFiles(indexes3)); } @@ -127,10 +158,12 @@ public class BackupFilesTest // check there are "rollMax" backup files and they are all saved correctly // check 10 backup files - int[] indexes1 = { 9, 10 }; + HashMap correctindexmap = new HashMap(); + correctindexmap.put(9, "backupfilestestTemp_BACKUPTEST-00000009.fa"); + correctindexmap.put(10, "backupfilestestTemp_BACKUPTEST-00000010.fa"); int[] indexes2 = { 10 }; int[] indexes3 = { 8, 9, 10 }; - Assert.assertTrue(checkBackupFiles(indexes1)); + Assert.assertTrue(checkBackupFiles(correctindexmap)); Assert.assertFalse(checkBackupFiles(indexes2)); Assert.assertFalse(checkBackupFiles(indexes3)); } @@ -156,10 +189,12 @@ public class BackupFilesTest // check there are "rollMax" backup files and they are all saved correctly // check 10 backup files - int[] indexes1 = { 1, 2 }; + HashMap correctindexmap = new HashMap(); + correctindexmap.put(1, "backupfilestestTemp_BACKUPTEST-00000001.fa"); + correctindexmap.put(2, "backupfilestestTemp_BACKUPTEST-00000002.fa"); int[] indexes2 = { 1 }; int[] indexes3 = { 1, 2, 3 }; - Assert.assertTrue(checkBackupFiles(indexes1)); + Assert.assertTrue(checkBackupFiles(correctindexmap)); Assert.assertFalse(checkBackupFiles(indexes2)); Assert.assertFalse(checkBackupFiles(indexes3)); } @@ -256,6 +291,45 @@ public class BackupFilesTest return BackupFiles.lsBackupFiles(newFile, suffix, digits); } + private static boolean checkBackupFiles(HashMap indexmap) + throws IOException + { + TreeMap map = BackupFiles.lsBackupFilesAsTreeMap(newFile, + suffix, digits); + Enumeration indexesenum = Collections + .enumeration(indexmap.keySet()); + while (indexesenum.hasMoreElements()) + { + int i = indexesenum.nextElement(); + String indexfilename = indexmap.get(i); + if (!map.containsKey(i)) + { + return false; + } + File f = map.get(i); + if (!filesContentEqual(newFile, f.getPath())) + { + return false; + } + map.remove(i); + if (f == null) + { + return false; + } + if (!f.getName().equals(indexfilename)) + { + return false; + } + } + // should be nothing left in map + if (map.size() > 0) + { + return false; + } + + return true; + } + private static boolean checkBackupFiles(int[] indexes) throws IOException { TreeMap map = BackupFiles.lsBackupFilesAsTreeMap(newFile, @@ -277,6 +351,15 @@ public class BackupFilesTest { return false; } + // check the filename -- although this uses the same code to forumulate the filename so not much of a test! + String filename = BackupFilenameFilter.getBackupFilename(i, + newBasename, suffix, digits, testExt); + if (!filename.equals(f.getName())) + { + System.out.println("Supposed filename '" + filename + + "' not equal to actual filename '" + f.getName() + "'"); + return false; + } } // should be nothing left in map if (map.size() > 0) -- 1.7.10.2