01: package pygmy.nntp.test;
02:
03: import pygmy.nntp.NewsGroup;
04: import pygmy.nntp.Article;
05: import pygmy.nntp.NntpInputStream;
06: import pygmy.nntp.Forum;
07:
08: import java.io.*;
09:
10: public class NntpTestUtil {
11: public static void deleteTree(File directory) {
12: File[] files = directory.listFiles();
13: if (files != null) {
14: for (int i = 0; i < files.length; i++) {
15: if (files[i].isDirectory())
16: deleteTree(files[i]);
17: else if (!files[i].delete()) {
18: System.out.println("File was not deleted! "
19: + files[i].getAbsolutePath());
20: }
21: }
22: }
23: if (!directory.delete()) {
24: System.out.println("Directory was not deleted!: "
25: + directory.getAbsolutePath());
26: }
27: }
28:
29: public static NewsGroup createNewsGroup(String name) {
30: NewsGroup group = new NewsGroup(new File(System
31: .getProperty("nntp.root"), name), name);
32: return group;
33: }
34:
35: public static Article createArticle(String filename)
36: throws IOException {
37: File file = new File(System.getProperty("nntp.root"), filename);
38: NntpInputStream is = null;
39: try {
40: is = new NntpInputStream(new FileInputStream(file));
41: Article article = new Article(is);
42: return article;
43: } finally {
44: if (is != null) {
45: is.close();
46: }
47: }
48: }
49:
50: public static Forum createTestForum() throws IOException {
51: if (System.getProperty("nntp.root") == null)
52: throw new IllegalArgumentException(
53: "This test requires that the system property nntp.root be set.");
54: // return new Forum( new File( System.getProperty("nntp.root"), new TestSpool() ) );
55: return null;
56: }
57: }
|