tests: fix NPE, add BasicSupportUtilities tests
[nikiroo-utils.git] / src / be / nikiroo / fanfix / test / Test.java
CommitLineData
92fb0719
NR
1package be.nikiroo.fanfix.test;
2
22848428
NR
3import java.io.File;
4import java.io.FileOutputStream;
5import java.io.IOException;
6import java.util.Properties;
7
581d42c0 8import be.nikiroo.fanfix.Instance;
22848428
NR
9import be.nikiroo.fanfix.bundles.ConfigBundle;
10import be.nikiroo.utils.IOUtils;
2aac79c7 11import be.nikiroo.utils.TempFiles;
22848428 12import be.nikiroo.utils.resources.Bundles;
92fb0719
NR
13import be.nikiroo.utils.test.TestLauncher;
14
15/**
16 * Tests for Fanfix.
17 *
18 * @author niki
19 */
20public class Test extends TestLauncher {
2aac79c7
NR
21 /**
22 * The temporary files handler.
23 */
24 static TempFiles tempFiles;
25
2a25f781
NR
26 /**
27 * Create the Fanfix {@link TestLauncher}.
28 *
29 * @param args
30 * the arguments to configure the number of columns and the ok/ko
31 * {@link String}s
32 */
92fb0719 33 public Test(String[] args) {
68e370a4 34 super("Fanfix", args);
581d42c0 35 Instance.setTraceHandler(null);
8d59ce07
NR
36 addSeries(new BasicSupportUtilitiesTest(args));
37 addSeries(new BasicSupportDeprecatedTest(args));
6cac0e45 38 addSeries(new LibraryTest(args));
f7460e4c 39 addSeries(new ConversionTest(args));
92fb0719
NR
40 }
41
42 /**
43 * Main entry point of the program.
44 *
45 * @param args
46 * the arguments passed to the {@link TestLauncher}s.
22848428 47 * @throws IOException
2a25f781 48 * in case of I/O error
92fb0719 49 */
22848428 50 static public void main(String[] args) throws IOException {
8d59ce07
NR
51 Instance.init();
52
2aac79c7
NR
53 int result = 0;
54 tempFiles = new TempFiles("fanfix-test");
9fe3f177 55 try {
2aac79c7
NR
56 File tmpConfig = tempFiles.createTempDir("fanfix-config");
57 File tmpCache = tempFiles.createTempDir("fanfix-cache");
58
59 FileOutputStream out = null;
60 try {
61 out = new FileOutputStream(new File(tmpConfig,
62 "config.properties"));
63 Properties props = new Properties();
64 props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
65 props.store(out, null);
66 } finally {
67 if (out != null) {
68 out.close();
69 }
9fe3f177 70 }
22848428 71
2aac79c7
NR
72 ConfigBundle config = new ConfigBundle();
73 Bundles.setDirectory(tmpConfig.getAbsolutePath());
74 config.updateFile(tmpConfig.getPath());
22848428 75
2aac79c7 76 System.setProperty("CONFIG_DIR", tmpConfig.getAbsolutePath());
22848428 77
2aac79c7 78 result = new Test(args).launch();
22848428 79
2aac79c7
NR
80 IOUtils.deltree(tmpConfig);
81 IOUtils.deltree(tmpCache);
82 } finally {
83 // Test temp files
84 tempFiles.close();
85
86 // This is usually done in Fanfix.Main:
87 Instance.getTempFiles().close();
88 }
22848428
NR
89
90 System.exit(result);
92fb0719
NR
91 }
92}