KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > command > AllTests


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder.command;
19
20 import java.lang.reflect.InvocationTargetException JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 import org.columba.mail.folder.MBOXFolderTstFactory;
28 import org.columba.mail.folder.MHFolderFactory;
29 import org.columba.mail.folder.MailboxTstFactory;
30 import org.columba.mail.folder.TempFolderFactory;
31
32 /**
33  * @author fdietz
34  *
35  */

36 public class AllTests {
37
38     private static String JavaDoc[] list = { "CopyMessageCommandTest",
39             "MarkMessageTest", "MoveMessageTest", "MoveFolderCommandTest" };
40
41     /**
42      * Add all testcases to the passed testsuite, using a the folder type as
43      * created in the factory.
44      *
45      * @param suite
46      * test suite
47      * @param factory
48      * factory which creates the folder instances
49      */

50     private static void setup(TestSuite suite, MailboxTstFactory factory) {
51         try {
52             for (int j = 0; j < list.length; j++) {
53                 Class JavaDoc clazz = Class.forName("org.columba.mail.folder.command."
54                         + list[j]);
55
56                 Method JavaDoc[] methods = clazz.getDeclaredMethods();
57                 for (int i = 0; i < methods.length; i++) {
58                     if (methods[i].getName().startsWith("test")) {
59
60                         suite
61                                 .addTest((TestCase) clazz.getConstructor(
62                                         new Class JavaDoc[] { MailboxTstFactory.class,
63                                                 String JavaDoc.class }).newInstance(
64                                         new Object JavaDoc[] { factory,
65                                                 methods[i].getName() }));
66                     }
67                 }
68             }
69         } catch (SecurityException JavaDoc e) {
70
71             e.printStackTrace();
72         } catch (IllegalArgumentException JavaDoc e) {
73
74             e.printStackTrace();
75         } catch (ClassNotFoundException JavaDoc e) {
76
77             e.printStackTrace();
78         } catch (InstantiationException JavaDoc e) {
79
80             e.printStackTrace();
81         } catch (IllegalAccessException JavaDoc e) {
82
83             e.printStackTrace();
84         } catch (InvocationTargetException JavaDoc e) {
85
86             e.printStackTrace();
87         } catch (NoSuchMethodException JavaDoc e) {
88
89             e.printStackTrace();
90         }
91     }
92
93     public static Test suite() {
94         TestSuite suite = new TestSuite(
95                 "Test for org.columba.mail.folder.command");
96
97         setup(suite, new MHFolderFactory());
98         setup(suite, new TempFolderFactory());
99         setup(suite, new MBOXFolderTstFactory());
100         // disabled IMAP folder tests as they require connection
101
// to remote IMAP server
102
// setup(suite, new IMAPTstFactory());
103

104         return suite;
105     }
106
107 }
Popular Tags