|
1 | 1 | package com.nordstrom.common.file;
|
2 | 2 |
|
| 3 | +import static org.testng.Assert.assertEquals; |
| 4 | +import static org.testng.Assert.assertNull; |
| 5 | + |
3 | 6 | import org.testng.annotations.Test;
|
4 | 7 |
|
| 8 | +import com.nordstrom.common.file.OSUtils.OSProps; |
5 | 9 | import com.nordstrom.common.file.OSUtils.OSType;
|
6 | 10 |
|
7 | 11 | public class OSUtilsTest {
|
8 | 12 |
|
| 13 | + private static String osName = System.getProperty("os.name").toLowerCase(); |
| 14 | + |
9 | 15 | @Test
|
10 |
| - public void testDefault() { |
| 16 | + public void testDefaultMapping() { |
11 | 17 | OSUtils<OSType> osUtils = OSUtils.getDefault();
|
12 |
| - System.out.println(osUtils.getType()); |
13 |
| - System.out.println(OSUtils.osName()); |
14 |
| - System.out.println(OSUtils.version()); |
15 |
| - System.out.println(OSUtils.arch()); |
| 18 | + OSType expected = (osName.startsWith("windows")) ? OSType.WINDOWS : OSType.UNIX; |
| 19 | + assertEquals(osUtils.getType(), expected, "Reported OS type doesn't match expected type"); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testCustomMapping() { |
| 24 | + OSUtils<TestEnum> osUtils = new OSUtils<>(TestEnum.class); |
| 25 | + assertEquals(osUtils.getType(), TestEnum.TEST, "Reported OS type doesn't match expected type"); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testAddOneMapping() { |
| 30 | + OSUtils<OSType> osUtils = OSUtils.getDefault(); |
| 31 | + osUtils.put(TestEnum.TEST); |
| 32 | + assertEquals(osUtils.getType(), TestEnum.TEST, "Reported OS type doesn't match expected type"); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testAddMappingSet() { |
| 37 | + OSUtils<OSType> osUtils = OSUtils.getDefault(); |
| 38 | + osUtils.putAll(TestEnum.class); |
| 39 | + assertEquals(osUtils.getType(), TestEnum.TEST, "Reported OS type doesn't match expected type"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testOverrideMapping() { |
| 44 | + OSUtils<OSType> osUtils = OSUtils.getDefault(); |
| 45 | + osUtils.put(OSType.SOLARIS, "(?i)" + osName); |
| 46 | + assertEquals(osUtils.getType(), OSType.SOLARIS, "Reported OS type doesn't match expected type"); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testUnsupportedType() { |
| 51 | + OSUtils<OSType> osUtils = OSUtils.getDefault(); |
| 52 | + osUtils.put(osUtils.getType(), ""); |
| 53 | + assertNull(osUtils.getType(), "Reported OS type doesn't match expected type"); |
| 54 | + } |
| 55 | + |
| 56 | + public enum TestEnum implements OSProps { |
| 57 | + TEST; |
| 58 | + |
| 59 | + @Override |
| 60 | + public String pattern() { |
| 61 | + return "(?i)" + osName; |
| 62 | + } |
| 63 | + |
16 | 64 | }
|
17 |
| - |
18 | 65 | }
|
0 commit comments