浏览代码

Change some more files to paths.

The updater code is horrid. In most cases I've just bailed out by
converting to a file.

Issue #24
pull/26/head
Chris Smith 9 年前
父节点
当前提交
b05b3fda15

+ 4
- 2
src/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModel.java 查看文件

@@ -39,6 +39,8 @@ import com.dmdirc.util.validators.Validator;
39 39
 
40 40
 import com.google.common.base.Optional;
41 41
 
42
+import java.nio.file.Path;
43
+
42 44
 import javax.inject.Inject;
43 45
 
44 46
 /**
@@ -50,7 +52,7 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
50 52
     private final ListenerList listeners;
51 53
     private final AggregateConfigProvider config;
52 54
     private final ConnectionManager connectionManager;
53
-    private final String configDirectory;
55
+    private final Path configDirectory;
54 56
     private Optional<String> name;
55 57
     private Optional<String> email;
56 58
     private Optional<String> feedback;
@@ -60,7 +62,7 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
60 62
     @Inject
61 63
     public CoreFeedbackDialogModel(@ClientModule.GlobalConfig final AggregateConfigProvider config,
62 64
             final ConnectionManager connectionManager, final FeedbackSenderFactory feedbackSenderFactory,
63
-            @Directory(DirectoryType.BASE) final String configDirectory) {
65
+            @Directory(DirectoryType.BASE) final Path configDirectory) {
64 66
         this.connectionManager = connectionManager;
65 67
         this.configDirectory = configDirectory;
66 68
         this.feedbackSenderFactory = feedbackSenderFactory;

+ 5
- 3
src/com/dmdirc/updater/UpdateComponent.java 查看文件

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.updater;
24 24
 
25
+import java.nio.file.Path;
26
+
25 27
 /**
26 28
  * The update component interface defines the methods needed to be implemented by updatable
27 29
  * components. The components handle determining the current version and installing updated files.
@@ -62,7 +64,7 @@ public interface UpdateComponent {
62 64
 
63 65
     /**
64 66
      * Provisionally indicates if this component will require a client restart. The result of
65
-     * {@link #doInstall(java.lang.String)} ultimately decides if the client requires a restart.
67
+     * {@link #doInstall(Path)} ultimately decides if the client requires a restart.
66 68
      *
67 69
      * @return True if the client requires a restart
68 70
      *
@@ -89,7 +91,7 @@ public interface UpdateComponent {
89 91
      *
90 92
      * @since 0.6.4
91 93
      */
92
-    String getManualInstructions(final String path);
94
+    String getManualInstructions(final Path path);
93 95
 
94 96
     /**
95 97
      * Installs the updated version of this component. After the update has been installed, the
@@ -101,6 +103,6 @@ public interface UpdateComponent {
101 103
      *
102 104
      * @throws java.lang.Exception If any error occurred
103 105
      */
104
-    boolean doInstall(String path) throws Exception; //NOPMD
106
+    boolean doInstall(Path path) throws Exception; //NOPMD
105 107
 
106 108
 }

+ 4
- 4
src/com/dmdirc/updater/components/ActionGroupComponent.java 查看文件

@@ -28,7 +28,7 @@ import com.dmdirc.updater.UpdateComponent;
28 28
 import com.dmdirc.updater.Version;
29 29
 
30 30
 import java.io.IOException;
31
-import java.nio.file.Paths;
31
+import java.nio.file.Path;
32 32
 
33 33
 /**
34 34
  * Update component for action groups.
@@ -72,13 +72,13 @@ public class ActionGroupComponent implements UpdateComponent {
72 72
     }
73 73
 
74 74
     @Override
75
-    public String getManualInstructions(final String path) {
75
+    public String getManualInstructions(final Path path) {
76 76
         return "";
77 77
     }
78 78
 
79 79
     @Override
80
-    public boolean doInstall(final String path) throws IOException {
81
-        ActionManager.installActionPack(Paths.get(path));
80
+    public boolean doInstall(final Path path) throws IOException {
81
+        ActionManager.installActionPack(path);
82 82
         return false;
83 83
     }
84 84
 

+ 20
- 18
src/com/dmdirc/updater/components/ClientComponent.java 查看文件

@@ -23,6 +23,8 @@
23 23
 package com.dmdirc.updater.components;
24 24
 
25 25
 import com.dmdirc.Main;
26
+import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
+import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
26 28
 import com.dmdirc.interfaces.config.IdentityController;
27 29
 import com.dmdirc.ui.StatusMessage;
28 30
 import com.dmdirc.ui.core.components.StatusBarManager;
@@ -30,7 +32,9 @@ import com.dmdirc.updater.UpdateComponent;
30 32
 import com.dmdirc.updater.Version;
31 33
 import com.dmdirc.util.io.FileUtils;
32 34
 
33
-import java.io.File;
35
+import java.io.IOException;
36
+import java.nio.file.Files;
37
+import java.nio.file.Path;
34 38
 
35 39
 import javax.inject.Inject;
36 40
 
@@ -43,6 +47,8 @@ public class ClientComponent implements UpdateComponent {
43 47
     private final IdentityController identityController;
44 48
     /** The manager to add status bar messages to. */
45 49
     private final StatusBarManager statusBarManager;
50
+    /** Base directory to move updates to. */
51
+    private final Path baseDirectory;
46 52
 
47 53
     /**
48 54
      * Creates a new instance of {@link ClientComponent}.
@@ -53,9 +59,11 @@ public class ClientComponent implements UpdateComponent {
53 59
     @Inject
54 60
     public ClientComponent(
55 61
             final IdentityController identityController,
56
-            final StatusBarManager statusBarManager) {
62
+            final StatusBarManager statusBarManager,
63
+            @Directory(DirectoryType.BASE) final Path baseDirectory) {
57 64
         this.identityController = identityController;
58 65
         this.statusBarManager = statusBarManager;
66
+        this.baseDirectory = baseDirectory;
59 67
     }
60 68
 
61 69
     @Override
@@ -84,9 +92,8 @@ public class ClientComponent implements UpdateComponent {
84 92
     }
85 93
 
86 94
     @Override
87
-    public String getManualInstructions(final String path) {
88
-        final File targetFile = new File(new File(path).getParent()
89
-                + File.separator + ".DMDirc.jar");
95
+    public String getManualInstructions(final Path path) {
96
+        final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
90 97
 
91 98
         if (requiresManualInstall()) {
92 99
             if (FileUtils.isRunningFromJar(Main.class)) {
@@ -95,16 +102,16 @@ public class ClientComponent implements UpdateComponent {
95 102
                         + "not be installed automatically.\n\n"
96 103
                         + "To install this update manually, please replace the\n"
97 104
                         + "existing DMDirc.jar file, located at:\n"
98
-                        + " " + FileUtils.getApplicationPath(Main.class)
105
+                        + ' ' + FileUtils.getApplicationPath(Main.class)
99 106
                         + "\n with the following file:\n "
100
-                        + targetFile.getAbsolutePath();
107
+                        + targetFile.toAbsolutePath();
101 108
             } else {
102 109
                 return "A new version of DMDirc has been downloaded, but as you\n"
103 110
                         + "do not seem to be using the DMDirc launcher, it will\n"
104 111
                         + "not be installed automatically.\n\n"
105 112
                         + "To install this update manually, please extract the\n"
106 113
                         + "new DMDirc.jar file, located at:\n"
107
-                        + " " + targetFile.getAbsolutePath() + "\n"
114
+                        + ' ' + targetFile.toAbsolutePath() + '\n'
108 115
                         + "over your existing DMDirc install located in:\n"
109 116
                         + "  " + FileUtils.getApplicationPath(Main.class);
110 117
             }
@@ -118,21 +125,16 @@ public class ClientComponent implements UpdateComponent {
118 125
     }
119 126
 
120 127
     @Override
121
-    public boolean doInstall(final String path) {
122
-        final File tmpFile = new File(path);
123
-        final File targetFile = new File(tmpFile.getParent() + File.separator
124
-                + ".DMDirc.jar");
128
+    public boolean doInstall(final Path path) throws IOException {
129
+        final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
125 130
 
126
-        if (targetFile.exists()) {
127
-            targetFile.delete();
128
-        }
129
-
130
-        tmpFile.renameTo(targetFile);
131
+        Files.deleteIfExists(targetFile);
132
+        Files.move(path, targetFile);
131 133
 
132 134
         if (requiresManualInstall()) {
133 135
             // @deprecated Should be removed when updater UI changes are
134 136
             // implemented.
135
-            final String message = this.getManualInstructions(path);
137
+            final String message = getManualInstructions(path);
136 138
             statusBarManager.setMessage(new StatusMessage(message,
137 139
                     identityController.getGlobalConfiguration()));
138 140
         }

+ 7
- 5
src/com/dmdirc/updater/components/DefaultsComponent.java 查看文件

@@ -30,8 +30,9 @@ import com.dmdirc.updater.UpdateComponent;
30 30
 import com.dmdirc.updater.Version;
31 31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
32 32
 
33
-import java.io.File;
34 33
 import java.io.IOException;
34
+import java.nio.file.Files;
35
+import java.nio.file.Path;
35 36
 
36 37
 import javax.inject.Inject;
37 38
 
@@ -97,19 +98,20 @@ public class DefaultsComponent implements UpdateComponent {
97 98
     }
98 99
 
99 100
     @Override
100
-    public String getManualInstructions(final String path) {
101
+    public String getManualInstructions(final Path path) {
101 102
         return "";
102 103
     }
103 104
 
104 105
     @Override
105
-    public boolean doInstall(final String path) throws IOException {
106
-        final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
106
+    public boolean doInstall(final Path path) throws IOException {
107
+        final ZipResourceManager ziprm =
108
+                ZipResourceManager.getInstance(path.toAbsolutePath().toString());
107 109
 
108 110
         ziprm.extractResources("", directory);
109 111
 
110 112
         identityController.loadUserIdentities();
111 113
 
112
-        new File(path).delete();
114
+        Files.delete(path);
113 115
 
114 116
         return false;
115 117
     }

+ 7
- 6
src/com/dmdirc/updater/components/LauncherComponent.java 查看文件

@@ -29,6 +29,7 @@ import com.dmdirc.util.resourcemanager.ZipResourceManager;
29 29
 
30 30
 import java.io.File;
31 31
 import java.io.IOException;
32
+import java.nio.file.Path;
32 33
 
33 34
 /**
34 35
  * Component for updates of DMDirc's launcher.
@@ -104,13 +105,13 @@ public class LauncherComponent implements UpdateComponent {
104 105
     }
105 106
 
106 107
     @Override
107
-    public String getManualInstructions(final String path) {
108
+    public String getManualInstructions(final Path path) {
108 109
         return "";
109 110
     }
110 111
 
111 112
     @Override
112
-    public boolean doInstall(final String path) throws IOException {
113
-        final File tmpFile = new File(path);
113
+    public boolean doInstall(final Path path) throws IOException {
114
+        final File tmpFile = path.toFile();
114 115
         if (platform.equalsIgnoreCase("Linux")
115 116
                 || platform.equalsIgnoreCase("unix")) {
116 117
             final File targetFile = new File(tmpFile.getParent()
@@ -124,9 +125,9 @@ public class LauncherComponent implements UpdateComponent {
124 125
             targetFile.setExecutable(true);
125 126
 
126 127
         } else {
127
-            ZipResourceManager.getInstance(path).extractResources("",
128
-                    tmpFile.getParent() + File.separator);
129
-            new File(path).delete();
128
+            ZipResourceManager.getInstance(path.toAbsolutePath().toString())
129
+                    .extractResources("", tmpFile.getParent() + File.separator);
130
+            path.toFile().delete();
130 131
         }
131 132
         return true;
132 133
     }

+ 7
- 5
src/com/dmdirc/updater/components/ModeAliasesComponent.java 查看文件

@@ -30,8 +30,9 @@ import com.dmdirc.updater.UpdateComponent;
30 30
 import com.dmdirc.updater.Version;
31 31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
32 32
 
33
-import java.io.File;
34 33
 import java.io.IOException;
34
+import java.nio.file.Files;
35
+import java.nio.file.Path;
35 36
 
36 37
 import javax.inject.Inject;
37 38
 
@@ -97,19 +98,20 @@ public class ModeAliasesComponent implements UpdateComponent {
97 98
     }
98 99
 
99 100
     @Override
100
-    public String getManualInstructions(final String path) {
101
+    public String getManualInstructions(final Path path) {
101 102
         return "";
102 103
     }
103 104
 
104 105
     @Override
105
-    public boolean doInstall(final String path) throws IOException {
106
-        final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
106
+    public boolean doInstall(final Path path) throws IOException {
107
+        final ZipResourceManager ziprm =
108
+                ZipResourceManager.getInstance(path.toAbsolutePath().toString());
107 109
 
108 110
         ziprm.extractResources("", directory);
109 111
 
110 112
         identityController.loadUserIdentities();
111 113
 
112
-        new File(path).delete();
114
+        Files.delete(path);
113 115
 
114 116
         return false;
115 117
     }

+ 5
- 4
src/com/dmdirc/updater/components/PluginComponent.java 查看文件

@@ -30,6 +30,7 @@ import com.dmdirc.updater.Version;
30 30
 
31 31
 import java.io.File;
32 32
 import java.io.IOException;
33
+import java.nio.file.Path;
33 34
 import java.util.zip.ZipFile;
34 35
 
35 36
 /**
@@ -83,12 +84,12 @@ public class PluginComponent implements UpdateComponent {
83 84
     }
84 85
 
85 86
     @Override
86
-    public String getManualInstructions(final String path) {
87
+    public String getManualInstructions(final Path path) {
87 88
         return "";
88 89
     }
89 90
 
90 91
     @Override
91
-    public boolean doInstall(final String path) {
92
+    public boolean doInstall(final Path path) {
92 93
         final File target = new File(plugin.getMetaData().getPluginUrl().getPath());
93 94
 
94 95
         boolean returnCode = false;
@@ -101,7 +102,7 @@ public class PluginComponent implements UpdateComponent {
101 102
         // Try and move the downloaded plugin to the new location.
102 103
         // If it doesn't work then keep the plugin in a .update file until the next restart.
103 104
         // If it does, update the metadata.
104
-        final File newPlugin = new File(path);
105
+        final File newPlugin = path.toFile();
105 106
         if (!isValid(newPlugin)) {
106 107
             return false;
107 108
         }
@@ -114,7 +115,7 @@ public class PluginComponent implements UpdateComponent {
114 115
                 newTarget.delete();
115 116
             }
116 117
 
117
-            new File(path).renameTo(newTarget);
118
+            path.toFile().renameTo(newTarget);
118 119
             returnCode = true;
119 120
         } else {
120 121
             try {

+ 4
- 3
src/com/dmdirc/updater/installing/LegacyInstallationStrategy.java 查看文件

@@ -28,15 +28,16 @@ import com.dmdirc.util.collections.ListenerList;
28 28
 
29 29
 import javax.inject.Inject;
30 30
 
31
+import org.slf4j.Logger;
31 32
 import org.slf4j.LoggerFactory;
32 33
 
33 34
 /**
34 35
  * An {@link UpdateInstallationStrategy} which uses the old
35
- * {@link UpdateComponent#doInstall(java.lang.String)} methods to perform installation.
36
+ * {@link UpdateComponent#doInstall(java.nio.file.Path)} methods to perform installation.
36 37
  */
37 38
 public class LegacyInstallationStrategy extends TypeSensitiveInstallationStrategy<UpdateComponent, SingleFileRetrievalResult> {
38 39
 
39
-    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(
40
+    private static final Logger LOG = LoggerFactory.getLogger(
40 41
             LegacyInstallationStrategy.class);
41 42
     /** List of registered listeners. */
42 43
     private final ListenerList listenerList = new ListenerList();
@@ -56,7 +57,7 @@ public class LegacyInstallationStrategy extends TypeSensitiveInstallationStrateg
56 57
                 retrievalResult.getFile(), component.getName());
57 58
 
58 59
         try {
59
-            component.doInstall(retrievalResult.getFile().getAbsolutePath());
60
+            component.doInstall(retrievalResult.getFile());
60 61
             listenerList.getCallable(UpdateInstallationListener.class).installCompleted(component);
61 62
         } catch (Exception ex) {
62 63
             LOG.warn("Error installing update for {}", component.getName(), ex);

+ 5
- 6
src/com/dmdirc/updater/retrieving/BaseSingleFileResult.java 查看文件

@@ -24,7 +24,7 @@ package com.dmdirc.updater.retrieving;
24 24
 
25 25
 import com.dmdirc.updater.checking.UpdateCheckResult;
26 26
 
27
-import java.io.File;
27
+import java.nio.file.Path;
28 28
 
29 29
 /**
30 30
  * Simple implementation of a {@link SingleFileRetrievalResult}.
@@ -33,21 +33,20 @@ public class BaseSingleFileResult extends BaseRetrievalResult
33 33
         implements SingleFileRetrievalResult {
34 34
 
35 35
     /** The file where the update is located. */
36
-    private final File file;
36
+    private final Path file;
37 37
 
38 38
     /**
39 39
      * Creates a new instance of {@link BaseSingleFileResult}.
40
-     *
41
-     * @param checkResult The check result that triggered this retrieval
40
+     *  @param checkResult The check result that triggered this retrieval
42 41
      * @param file        The file containing the update
43 42
      */
44
-    public BaseSingleFileResult(final UpdateCheckResult checkResult, final File file) {
43
+    public BaseSingleFileResult(final UpdateCheckResult checkResult, final Path file) {
45 44
         super(checkResult, true);
46 45
 
47 46
         this.file = file;
48 47
     }
49 48
 
50
-    public File getFile() {
49
+    public Path getFile() {
51 50
         return file;
52 51
     }
53 52
 

+ 12
- 12
src/com/dmdirc/updater/retrieving/DownloadRetrievalStrategy.java 查看文件

@@ -29,12 +29,13 @@ import com.dmdirc.updater.checking.DownloadableUpdate;
29 29
 import com.dmdirc.util.collections.ListenerList;
30 30
 import com.dmdirc.util.io.DownloadListener;
31 31
 import com.dmdirc.util.io.Downloader;
32
-import org.slf4j.LoggerFactory;
33 32
 
34
-import javax.inject.Inject;
35
-import java.io.File;
36 33
 import java.io.IOException;
37
-import java.nio.file.Paths;
34
+import java.nio.file.Path;
35
+
36
+import javax.inject.Inject;
37
+
38
+import org.slf4j.LoggerFactory;
38 39
 
39 40
 /**
40 41
  * An {@link UpdateRetrievalStrategy} that downloads a file specified in a
@@ -47,7 +48,7 @@ public class DownloadRetrievalStrategy extends TypeSensitiveRetrievalStrategy<Do
47 48
     /** List of registered listeners. */
48 49
     private final ListenerList listenerList = new ListenerList();
49 50
     /** The directory to put temporary update files in. */
50
-    private final String directory;
51
+    private final Path directory;
51 52
     /** Downloader to download files. */
52 53
     private final Downloader downloader;
53 54
 
@@ -59,7 +60,7 @@ public class DownloadRetrievalStrategy extends TypeSensitiveRetrievalStrategy<Do
59 60
      * @param downloader Used to download files
60 61
      */
61 62
     @Inject
62
-    public DownloadRetrievalStrategy(@Directory(DirectoryType.BASE) final String directory,
63
+    public DownloadRetrievalStrategy(@Directory(DirectoryType.BASE) final Path directory,
63 64
             final Downloader downloader) {
64 65
         super(DownloadableUpdate.class);
65 66
 
@@ -70,19 +71,19 @@ public class DownloadRetrievalStrategy extends TypeSensitiveRetrievalStrategy<Do
70 71
     @Override
71 72
     protected UpdateRetrievalResult retrieveImpl(final DownloadableUpdate checkResult) {
72 73
         try {
73
-            final String file = getFileName();
74
+            final Path file = getFile();
74 75
 
75 76
             listenerList.getCallable(UpdateRetrievalListener.class)
76 77
                     .retrievalProgressChanged(checkResult.getComponent(), 0);
77 78
 
78 79
             LOG.debug("Downloading file from {} to {}", checkResult.getUrl(), file);
79
-            downloader.downloadPage(checkResult.getUrl().toString(), Paths.get(file),
80
+            downloader.downloadPage(checkResult.getUrl().toString(), file,
80 81
                     new DownloadProgressListener(checkResult.getComponent()));
81 82
 
82 83
             listenerList.getCallable(UpdateRetrievalListener.class)
83 84
                     .retrievalCompleted(checkResult.getComponent());
84 85
 
85
-            return new BaseSingleFileResult(checkResult, new File(file));
86
+            return new BaseSingleFileResult(checkResult, file);
86 87
         } catch (IOException ex) {
87 88
             LOG.warn("I/O exception downloading update from {}", checkResult.getUrl(), ex);
88 89
             listenerList.getCallable(UpdateRetrievalListener.class)
@@ -97,9 +98,8 @@ public class DownloadRetrievalStrategy extends TypeSensitiveRetrievalStrategy<Do
97 98
      *
98 99
      * @return The full, local path to download the remote file to
99 100
      */
100
-    private String getFileName() {
101
-        return directory + File.separator + "update."
102
-                + Math.round(10000 * Math.random()) + ".tmp";
101
+    private Path getFile() {
102
+        return directory.resolve("update." + Math.round(10000 * Math.random()) + ".tmp");
103 103
     }
104 104
 
105 105
     @Override

+ 1
- 1
src/com/dmdirc/updater/retrieving/SingleFileRetrievalResult.java 查看文件

@@ -35,6 +35,6 @@ public interface SingleFileRetrievalResult extends UpdateRetrievalResult {
35 35
      *
36 36
      * @return The file containing the retrieved update
37 37
      */
38
-    File getFile();
38
+    java.nio.file.Path getFile();
39 39
 
40 40
 }

+ 13
- 10
test/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java 查看文件

@@ -28,6 +28,8 @@ import com.dmdirc.interfaces.ui.FeedbackDialogModelListener;
28 28
 
29 29
 import com.google.common.base.Optional;
30 30
 
31
+import java.nio.file.Path;
32
+
31 33
 import org.junit.Test;
32 34
 import org.junit.runner.RunWith;
33 35
 import org.mockito.Mock;
@@ -43,6 +45,7 @@ public class CoreFeedbackDialogModelTest {
43 45
     @Mock private ConnectionManager connectionManager;
44 46
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
45 47
     @Mock private FeedbackDialogModelListener listener;
48
+    @Mock private Path path;
46 49
     private static final String NAME = "Bob Dole";
47 50
     private static final String EMAIL = "bob@dole.com";
48 51
     private static final String FEEDBACK = "DMDirc Rocks.";
@@ -51,7 +54,7 @@ public class CoreFeedbackDialogModelTest {
51 54
     public void testName() {
52 55
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
53 56
                 connectionManager,
54
-                feedbackSenderFactory, "configDirectory");
57
+                feedbackSenderFactory, path);
55 58
         assertEquals("testName", Optional.absent(), instance.getName());
56 59
         instance.setName(Optional.fromNullable(NAME));
57 60
         assertEquals("testName", Optional.fromNullable(NAME), instance.getName());
@@ -61,7 +64,7 @@ public class CoreFeedbackDialogModelTest {
61 64
     public void testEmail() {
62 65
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
63 66
                 connectionManager,
64
-                feedbackSenderFactory, "configDirectory");
67
+                feedbackSenderFactory, path);
65 68
         assertEquals("testEmail", Optional.absent(), instance.getEmail());
66 69
         instance.setEmail(Optional.fromNullable(EMAIL));
67 70
         assertEquals("testEmail", Optional.fromNullable(EMAIL), instance.getEmail());
@@ -71,7 +74,7 @@ public class CoreFeedbackDialogModelTest {
71 74
     public void testFeedback() {
72 75
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
73 76
                 connectionManager,
74
-                feedbackSenderFactory, "configDirectory");
77
+                feedbackSenderFactory, path);
75 78
         assertEquals("testFeedback", Optional.absent(), instance.getFeedback());
76 79
         instance.setFeedback(Optional.fromNullable(FEEDBACK));
77 80
         assertEquals("testFeedback", Optional.fromNullable(FEEDBACK), instance.getFeedback());
@@ -81,7 +84,7 @@ public class CoreFeedbackDialogModelTest {
81 84
     public void testServerInfo() {
82 85
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
83 86
                 connectionManager,
84
-                feedbackSenderFactory, "configDirectory");
87
+                feedbackSenderFactory, path);
85 88
         assertEquals("testServerInfo", false, instance.getIncludeServerInfo());
86 89
         instance.setIncludeServerInfo(true);
87 90
         assertEquals("testServerInfo", true, instance.getIncludeServerInfo());
@@ -91,7 +94,7 @@ public class CoreFeedbackDialogModelTest {
91 94
     public void testDMDircInfo() {
92 95
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
93 96
                 connectionManager,
94
-                feedbackSenderFactory, "configDirectory");
97
+                feedbackSenderFactory, path);
95 98
         assertEquals("testDMDircInfo", false, instance.getIncludeDMDircInfo());
96 99
         instance.setIncludeDMDircInfo(true);
97 100
         assertEquals("testDMDircInfo", true, instance.getIncludeDMDircInfo());
@@ -106,7 +109,7 @@ public class CoreFeedbackDialogModelTest {
106 109
     public void testNameListener() {
107 110
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
108 111
                 connectionManager,
109
-                feedbackSenderFactory, "configDirectory");
112
+                feedbackSenderFactory, path);
110 113
         instance.addListener(listener);
111 114
         instance.setName(Optional.fromNullable("Bob Dole"));
112 115
         verify(listener).nameChanged(Optional.fromNullable("Bob Dole"));
@@ -116,7 +119,7 @@ public class CoreFeedbackDialogModelTest {
116 119
     public void testEmailListener() {
117 120
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
118 121
                 connectionManager,
119
-                feedbackSenderFactory, "configDirectory");
122
+                feedbackSenderFactory, path);
120 123
         instance.addListener(listener);
121 124
         instance.setEmail(Optional.fromNullable("bob@dole.com"));
122 125
         verify(listener).emailChanged(Optional.fromNullable("bob@dole.com"));
@@ -126,7 +129,7 @@ public class CoreFeedbackDialogModelTest {
126 129
     public void testFeedbackListener() {
127 130
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
128 131
                 connectionManager,
129
-                feedbackSenderFactory, "configDirectory");
132
+                feedbackSenderFactory, path);
130 133
         instance.addListener(listener);
131 134
         instance.setFeedback(Optional.fromNullable("DMDirc Rocks."));
132 135
         verify(listener).feedbackChanged(Optional.fromNullable("DMDirc Rocks."));
@@ -136,7 +139,7 @@ public class CoreFeedbackDialogModelTest {
136 139
     public void testServerInfoListener() {
137 140
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
138 141
                 connectionManager,
139
-                feedbackSenderFactory, "configDirectory");
142
+                feedbackSenderFactory, path);
140 143
         instance.addListener(listener);
141 144
         instance.setIncludeServerInfo(true);
142 145
         verify(listener).includeServerInfoChanged(true);
@@ -146,7 +149,7 @@ public class CoreFeedbackDialogModelTest {
146 149
     public void testDMDircInfoListener() {
147 150
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
148 151
                 connectionManager,
149
-                feedbackSenderFactory, "configDirectory");
152
+                feedbackSenderFactory, path);
150 153
         instance.addListener(listener);
151 154
         instance.setIncludeDMDircInfo(true);
152 155
         verify(listener).includeDMDircInfoChanged(true);

+ 22
- 10
test/com/dmdirc/updater/installing/LegacyInstallationStrategyTest.java 查看文件

@@ -25,13 +25,16 @@ package com.dmdirc.updater.installing;
25 25
 import com.dmdirc.updater.UpdateComponent;
26 26
 import com.dmdirc.updater.retrieving.SingleFileRetrievalResult;
27 27
 
28
-import java.io.File;
29 28
 import java.io.IOException;
29
+import java.nio.file.Path;
30 30
 
31 31
 import org.junit.Before;
32 32
 import org.junit.Test;
33
+import org.mockito.Matchers;
33 34
 
34
-import static org.mockito.Mockito.*;
35
+import static org.mockito.Mockito.mock;
36
+import static org.mockito.Mockito.verify;
37
+import static org.mockito.Mockito.when;
35 38
 
36 39
 public class LegacyInstallationStrategyTest {
37 40
 
@@ -53,17 +56,23 @@ public class LegacyInstallationStrategyTest {
53 56
 
54 57
     @Test
55 58
     public void testCallsInstallWithCorrectPath() throws Exception { // NOPMD
56
-        final File file = mock(File.class);
57
-        when(file.getAbsolutePath()).thenReturn("/my/path");
59
+        final Path file = mock(Path.class);
60
+        final Path absoluteFile = mock(Path.class);
61
+        when(file.toString()).thenReturn("path");
62
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
63
+        when(absoluteFile.toString()).thenReturn("/my/path");
58 64
         when(result.getFile()).thenReturn(file);
59 65
         strategy.installImpl(component, result);
60
-        verify(component).doInstall("/my/path");
66
+        verify(component).doInstall(file);
61 67
     }
62 68
 
63 69
     @Test
64 70
     public void testRaisesCompletedEvent() throws Exception { // NOPMD
65
-        final File file = mock(File.class);
66
-        when(result.getFile()).thenReturn(file);
71
+        final Path file = mock(Path.class);
72
+        final Path absoluteFile = mock(Path.class);
73
+        when(file.toString()).thenReturn("path");
74
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
75
+        when(absoluteFile.toString()).thenReturn("/my/path");
67 76
         strategy.addUpdateInstallationListener(listener);
68 77
         strategy.installImpl(component, result);
69 78
         verify(listener).installCompleted(component);
@@ -71,9 +80,12 @@ public class LegacyInstallationStrategyTest {
71 80
 
72 81
     @Test
73 82
     public void testRaisesFailedEvent() throws Exception { // NOPMD
74
-        final File file = mock(File.class);
75
-        when(result.getFile()).thenReturn(file);
76
-        when(component.doInstall(anyString())).thenThrow(new IOException());
83
+        final Path file = mock(Path.class);
84
+        final Path absoluteFile = mock(Path.class);
85
+        when(file.toString()).thenReturn("path");
86
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
87
+        when(absoluteFile.toString()).thenReturn("/my/path");
88
+        when(component.doInstall(Matchers.<Path>anyObject())).thenThrow(new IOException());
77 89
         strategy.addUpdateInstallationListener(listener);
78 90
         strategy.installImpl(component, result);
79 91
         verify(listener).installFailed(component);

正在加载...
取消
保存