create changelog entry
[debian/openrocket] / core / test / net / sf / openrocket / arch / TestSystemInfo.java
1 package net.sf.openrocket.arch;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.File;
6
7 import org.junit.Test;
8
9 /*
10  * Note:  These tests have not been tested on Windows, they might fail there
11  * due to a different directory separator character.
12  */
13 public class TestSystemInfo {
14         
15         private String osname;
16         private String userhome;
17         
18         
19         public void setup() {
20                 this.osname = System.getProperty("os.name");
21                 this.userhome = System.getProperty("user.home");
22         }
23         
24         public void tearDown() {
25                 System.setProperty("os.name", this.osname);
26                 System.setProperty("user.home", this.userhome);
27         }
28         
29         @Test
30         public void testWindows() {
31                 setup();
32                 
33                 System.setProperty("os.name", "Windows Me");
34                 System.setProperty("user.home", "C:/Users/my user");
35                 assertEquals(SystemInfo.Platform.WINDOWS, SystemInfo.getPlatform());
36                 if (System.getenv("APPDATA") != null) {
37                         assertEquals(new File(System.getenv("APPDATA") + "/OpenRocket/"), SystemInfo.getUserApplicationDirectory());
38                 } else {
39                         assertEquals(new File("C:/Users/my user/OpenRocket/"), SystemInfo.getUserApplicationDirectory());
40                 }
41                 
42                 tearDown();
43         }
44         
45         @Test
46         public void testMacOS() {
47                 setup();
48                 
49                 System.setProperty("os.name", "Mac OS X");
50                 System.setProperty("user.home", "/Users/My User");
51                 assertEquals(SystemInfo.Platform.MAC_OS, SystemInfo.getPlatform());
52                 assertEquals(new File("/Users/My User/Library/Application Support/OpenRocket/"),
53                                 SystemInfo.getUserApplicationDirectory());
54                 
55                 tearDown();
56         }
57         
58         @Test
59         public void testUnix() {
60                 setup();
61                 
62                 System.setProperty("user.home", "/home/myuser");
63                 for (String os : new String[] { "Linux", "Solaris", "Foobar" }) {
64                         System.setProperty("os.name", os);
65                         
66                         assertEquals(SystemInfo.Platform.UNIX, SystemInfo.getPlatform());
67                         assertEquals(new File("/home/myuser/.openrocket"), SystemInfo.getUserApplicationDirectory());
68                 }
69                 
70                 tearDown();
71         }
72         
73 }