From 8a56c817a56c004a9a8065c5d9b083e19f549133 Mon Sep 17 00:00:00 2001 From: Bryant Date: Sun, 29 Sep 2019 15:59:38 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-418=20=E6=9B=B4=E6=96=B0=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../update/ui/dialog/RestoreResultDialog.java | 20 ++++++---------- .../ui/dialog/RestoreResultDialogTest.java | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 23 deletions(-) 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 a1211e7ff..5f325a1d9 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 @@ -7,7 +7,6 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.update.domain.UpdateConstants; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; -import com.fr.log.FineLoggerFactory; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -93,7 +92,7 @@ public class RestoreResultDialog extends JDialog { jarProgressLabel.setVisible(true); progressLabelPane.add(jarProgressLabel); pane.add(progressLabelPane, BorderLayout.CENTER); - deletePreviousPropertyFile(RestartHelper.MOVE_FILE,RestartHelper.RECORD_FILE); + deletePreviousPropertyFile(); putJarBackupFiles(); restartButton.setEnabled(true); restartLaterButton.setEnabled(true); @@ -101,18 +100,13 @@ public class RestoreResultDialog extends JDialog { this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Jar_Restore")); } - 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(move + "delete failed!"); - return false; + public static boolean deletePreviousPropertyFile() { + File moveFile = new File(RestartHelper.MOVE_FILE); + File delFile = new File(RestartHelper.RECORD_FILE); + if (StableUtils.mkdirs(moveFile) && StableUtils.mkdirs(delFile)) { + return StableUtils.deleteFile(moveFile) && StableUtils.deleteFile(delFile); } - if ((delFile.exists()) && (!delFile.delete())) { - FineLoggerFactory.getLogger().error(record + "delete failed!"); - return false; - } - return true; + return false; } 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 index 9a30e54fd..86be0450e 100644 --- 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 @@ -1,23 +1,26 @@ package com.fr.design.update.ui.dialog; - -import org.easymock.EasyMock; -import org.easymock.IMocksControl; +import com.fr.design.RestartHelper; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StableUtils; import org.junit.Assert; import org.junit.Test; import java.io.File; +import java.io.IOException; 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")); + File moveFile = new File(RestartHelper.MOVE_FILE); + File recordFile = new File(RestartHelper.RECORD_FILE); + try { + StableUtils.makesureFileExist(moveFile); + StableUtils.makesureFileExist(recordFile); + Assert.assertTrue(RestoreResultDialog.deletePreviousPropertyFile()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage(),e); + } } }