]> source.dussan.org Git - gitblit.git/commitdiff
Unit test of the MailExecutor.
authorJames Moger <james.moger@gitblit.com>
Mon, 26 Sep 2011 20:35:32 +0000 (16:35 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 26 Sep 2011 20:35:32 +0000 (16:35 -0400)
.gitignore
src/com/gitblit/MailExecutor.java
tests/com/gitblit/tests/MailTest.java [new file with mode: 0644]

index 389f6635964bec3c0b3bae385263ee83cd6e60d9..0b215f1eab2bb69dd8f2e7de108eccc50337ec51 100644 (file)
@@ -14,4 +14,5 @@
 /*.war
 /proposals
 /*.jar
-/federation.properties
\ No newline at end of file
+/federation.properties
+/mailtest.properties
index 202875ed2e87624cb13158f5b2372f45d253e080..bfe2232f8eb94e95e448f4895b1c46e84f90955a 100644 (file)
@@ -145,8 +145,11 @@ public class MailExecutor implements Runnable {
        public Message createMessage(List<String> toAddresses) {\r
                MimeMessage message = new MimeMessage(session);\r
                try {\r
-                       InternetAddress from = new InternetAddress(settings.getString(Keys.mail.fromAddress,\r
-                                       "gitblit@gitblit.com"), "Gitblit");\r
+                       String fromAddress = settings.getString(Keys.mail.fromAddress, null);\r
+                       if (StringUtils.isEmpty(fromAddress)) {\r
+                               fromAddress = "gitblit@gitblit.com";\r
+                       }\r
+                       InternetAddress from = new InternetAddress(fromAddress, "Gitblit");\r
                        message.setFrom(from);\r
 \r
                        InternetAddress[] tos = new InternetAddress[toAddresses.size()];\r
@@ -161,6 +164,15 @@ public class MailExecutor implements Runnable {
                return message;\r
        }\r
 \r
+       /**\r
+        * Returns the status of the mail queue.\r
+        * \r
+        * @return true, if the queue is empty\r
+        */\r
+       public boolean hasEmptyQueue() {\r
+               return queue.isEmpty();\r
+       }\r
+\r
        /**\r
         * Queue's an email message to be sent.\r
         * \r
diff --git a/tests/com/gitblit/tests/MailTest.java b/tests/com/gitblit/tests/MailTest.java
new file mode 100644 (file)
index 0000000..55002ce
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import javax.mail.Message;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import com.gitblit.FileSettings;\r
+import com.gitblit.MailExecutor;\r
+\r
+public class MailTest extends TestCase {\r
+\r
+       public void testSendMail() throws Exception {\r
+               FileSettings settings = new FileSettings("mailtest.properties");\r
+               MailExecutor mail = new MailExecutor(settings);\r
+               Message message = mail.createMessageForAdministrators();\r
+               message.setSubject("Test");\r
+               message.setText("this is a test");\r
+               mail.queue(message);\r
+               mail.run();             \r
+\r
+               assertTrue("mail queue is not empty!", mail.hasEmptyQueue());\r
+       }\r
+}\r