diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java index 8c1db89ec..a1211e7ff 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java @@ -93,7 +93,7 @@ public class RestoreResultDialog extends JDialog { jarProgressLabel.setVisible(true); progressLabelPane.add(jarProgressLabel); pane.add(progressLabelPane, BorderLayout.CENTER); - deletePreviousPropertyFile(); + deletePreviousPropertyFile(RestartHelper.MOVE_FILE,RestartHelper.RECORD_FILE); putJarBackupFiles(); restartButton.setEnabled(true); restartLaterButton.setEnabled(true); @@ -101,16 +101,18 @@ public class RestoreResultDialog extends JDialog { this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Jar_Restore")); } - public static void deletePreviousPropertyFile() { - //在进行更新升级之前确保move和delete.properties删除 - File moveFile = new File(RestartHelper.MOVE_FILE); - File delFile = new File(RestartHelper.RECORD_FILE); + public static boolean deletePreviousPropertyFile(String move, String record) { + File moveFile = new File(move); + File delFile = new File(record); if ((moveFile.exists()) && (!moveFile.delete())) { - FineLoggerFactory.getLogger().error(RestartHelper.MOVE_FILE + "delete failed!"); + FineLoggerFactory.getLogger().error(move + "delete failed!"); + return false; } if ((delFile.exists()) && (!delFile.delete())) { - FineLoggerFactory.getLogger().error(RestartHelper.RECORD_FILE + "delete failed!"); + FineLoggerFactory.getLogger().error(record + "delete failed!"); + return false; } + return true; } private void initOldVersionRestoreComps() { diff --git a/designer-base/src/test/java/com/fr/design/update/ui/dialog/RestoreResultDialogTest.java b/designer-base/src/test/java/com/fr/design/update/ui/dialog/RestoreResultDialogTest.java new file mode 100644 index 000000000..9a30e54fd --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/update/ui/dialog/RestoreResultDialogTest.java @@ -0,0 +1,23 @@ +package com.fr.design.update.ui.dialog; + + +import org.easymock.EasyMock; +import org.easymock.IMocksControl; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; + +public class RestoreResultDialogTest { + + @Test + public void testDeletePreviousPropertyFile() { + IMocksControl control = EasyMock.createControl(); + File testRecordFile = control.createMock(File.class); + File testMoveFile = control.createMock(File.class); + EasyMock.expect(testRecordFile.getPath()).andReturn("move").anyTimes(); + EasyMock.expect(testMoveFile.getPath()).andReturn("record").anyTimes(); + control.replay(); + Assert.assertTrue(RestoreResultDialog.deletePreviousPropertyFile("move","record")); + } +}