[geary] Make both Engine and AccountInfo a bit more unit testable.



commit 6eac43b2e753260dcfcc1afb2c9fc9bdff66e384
Author: Michael James Gratton <mike vee net>
Date:   Fri Feb 17 17:39:05 2017 +1100

    Make both Engine and AccountInfo a bit more unit testable.
    
    * src/engine/api/geary-account-information.vala (AccountInformation):
      Make main constrcutor public, pass in the id rather than divining it
      from the config dir's name for both ctors. Update call sites.
    
    * src/engine/api/geary-engine.vala (Engine): Also make the ctor public.

 src/engine/api/geary-account-information.vala |    9 +++++----
 src/engine/api/geary-engine.vala              |   16 +++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 173eed0..c2a34b3 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -209,8 +209,8 @@ public class Geary.AccountInformation : BaseObject {
     /**
      * Creates a new, empty account info file.
      */
-    internal AccountInformation(File config_directory, File data_directory) {
-        this.id = config_directory.get_basename();
+    public AccountInformation(string id, File config_directory, File data_directory) {
+        this.id = id;
         this.config_dir = config_directory;
         this.data_dir = data_directory;
         this.file = config_dir.get_child(SETTINGS_FILENAME);
@@ -222,10 +222,11 @@ public class Geary.AccountInformation : BaseObject {
      * Throws an error if the config file was not found, could not be
      * parsed, or doesn't have all required fields.
      */
-    internal AccountInformation.from_file(File config_directory,
+    internal AccountInformation.from_file(string id,
+                                          File config_directory,
                                           File data_directory)
         throws Error {
-        this(config_directory, data_directory);
+        this(id, config_directory, data_directory);
 
         KeyFile key_file = new KeyFile();
         key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index e532732..faaf818 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -105,10 +105,11 @@ public class Geary.Engine : BaseObject {
      */
     public signal void untrusted_host(Geary.AccountInformation account_information,
         Endpoint endpoint, Endpoint.SecurityType security, TlsConnection cx, Service service);
-    
-    private Engine() {
+
+    // Public so it can be tested
+    public Engine() {
     }
-    
+
     private void check_opened() throws EngineError {
         if (!is_open)
             throw new EngineError.OPEN_REQUIRED("Geary.Engine instance not open");
@@ -192,10 +193,12 @@ public class Geary.Engine : BaseObject {
             FileInfo info = info_list.nth_data(0);
             if (info.get_file_type() == FileType.DIRECTORY) {
                 try {
+                    string id = info.get_name();
                     account_list.add(
                         new AccountInformation.from_file(
-                            user_config_dir.get_child(info.get_name()),
-                            user_data_dir.get_child(info.get_name())
+                            id,
+                            user_config_dir.get_child(id),
+                            user_data_dir.get_child(id)
                         )
                     );
                 } catch (Error err) {
@@ -291,8 +294,7 @@ public class Geary.Engine : BaseObject {
             throw new EngineError.ALREADY_EXISTS("Account %s already exists", id);
 
         return new AccountInformation(
-            user_config_dir.get_child(id),
-            user_data_dir.get_child(id)
+            id, user_config_dir.get_child(id), user_data_dir.get_child(id)
         );
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]