KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > 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.filter.plugins;
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 = { "DateFilterTest",
39             "ColorFilterTest", "HeaderfieldFilterTest",
40             "FlagsFilterTest", "BodyFilterTest",
41             "PriorityFilterTest","AccountFilterTest",
42             "SizeFilterTest"};
43
44     /**
45      * Add all testcases to the passed testsuite, using a the folder type as
46      * created in the factory.
47      *
48      * @param suite
49      * test suite
50      * @param factory
51      * factory which creates the folder instances
52      */

53     private static void setup(TestSuite suite, MailboxTstFactory factory) {
54         try {
55             for (int j = 0; j < list.length; j++) {
56                 Class JavaDoc clazz = Class.forName("org.columba.mail.filter.plugins."
57                         + list[j]);
58
59                 Method JavaDoc[] methods = clazz.getDeclaredMethods();
60                 for (int i = 0; i < methods.length; i++) {
61                     if (methods[i].getName().startsWith("test")) {
62
63                         suite.addTest((TestCase) clazz.getConstructor(
64                                 new Class JavaDoc[] { MailboxTstFactory.class,
65                                         String JavaDoc.class}).newInstance(
66                                 new Object JavaDoc[] { factory, methods[i].getName()}));
67                     }
68                 }
69             }
70         } catch (SecurityException JavaDoc e) {
71
72             e.printStackTrace();
73         } catch (IllegalArgumentException JavaDoc e) {
74
75             e.printStackTrace();
76         } catch (ClassNotFoundException JavaDoc e) {
77
78             e.printStackTrace();
79         } catch (InstantiationException JavaDoc e) {
80
81             e.printStackTrace();
82         } catch (IllegalAccessException JavaDoc e) {
83
84             e.printStackTrace();
85         } catch (InvocationTargetException JavaDoc e) {
86
87             e.printStackTrace();
88         } catch (NoSuchMethodException JavaDoc e) {
89
90             e.printStackTrace();
91         }
92     }
93
94     public static Test suite() {
95         TestSuite suite = new TestSuite("Test for org.columba.mail.folder");
96
97         setup(suite, new MHFolderFactory());
98         setup(suite, new MBOXFolderTstFactory());
99         setup(suite, new TempFolderFactory());
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