|
1 | | -/** |
| 1 | +/* |
2 | 2 | * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
19 | 19 | import org.junit.Test; |
20 | 20 | import org.utplsql.sqldev.ui.runner.SmartTime; |
21 | 21 |
|
22 | | -@SuppressWarnings("all") |
23 | 22 | public class SmartTimeTest { |
24 | | - @Test |
25 | | - public void null_default() { |
26 | | - final String effective = new SmartTime(null, false).toString(); |
27 | | - Assert.assertEquals(null, effective); |
28 | | - } |
29 | | - |
30 | | - @Test |
31 | | - public void null_smart() { |
32 | | - final String effective = new SmartTime(null, true).toString(); |
33 | | - Assert.assertEquals(null, effective); |
34 | | - } |
35 | | - |
36 | | - @Test |
37 | | - public void ms_0_default() { |
38 | | - final String effective = new SmartTime(Double.valueOf(0.0), false).toString(); |
39 | | - Assert.assertEquals("0.000", effective); |
40 | | - } |
41 | | - |
42 | | - @Test |
43 | | - public void ms_0_smart() { |
44 | | - final String effective = new SmartTime(Double.valueOf(0.0), true).toString(); |
45 | | - Assert.assertEquals("0 ms", effective); |
46 | | - } |
47 | | - |
48 | | - @Test |
49 | | - public void ms_999_default() { |
50 | | - final String effective = new SmartTime(Double.valueOf(0.999), false).toString(); |
51 | | - Assert.assertEquals("0.999", effective); |
52 | | - } |
53 | | - |
54 | | - @Test |
55 | | - public void ms_999_smart() { |
56 | | - final String effective = new SmartTime(Double.valueOf(0.999), true).toString(); |
57 | | - Assert.assertEquals("999 ms", effective); |
58 | | - } |
59 | | - |
60 | | - @Test |
61 | | - public void s_1_default() { |
62 | | - final String effective = new SmartTime(Double.valueOf(1.0), false).toString(); |
63 | | - Assert.assertEquals("1.000", effective); |
64 | | - } |
65 | | - |
66 | | - @Test |
67 | | - public void s_1_smart() { |
68 | | - final String effective = new SmartTime(Double.valueOf(1.0), true).toString(); |
69 | | - Assert.assertEquals("1.000 s", effective); |
70 | | - } |
71 | | - |
72 | | - @Test |
73 | | - public void s_59_default() { |
74 | | - final String effective = new SmartTime(Double.valueOf(59.999), false).toString(); |
75 | | - Assert.assertEquals("59.999", effective); |
76 | | - } |
77 | | - |
78 | | - @Test |
79 | | - public void s_59_smart() { |
80 | | - final String effective = new SmartTime(Double.valueOf(59.999), true).toString(); |
81 | | - Assert.assertEquals("59.999 s", effective); |
82 | | - } |
83 | | - |
84 | | - @Test |
85 | | - public void min_1_default() { |
86 | | - final String effective = new SmartTime(Double.valueOf(60.0), false).toString(); |
87 | | - Assert.assertEquals("60.000", effective); |
88 | | - } |
89 | | - |
90 | | - @Test |
91 | | - public void min_1_smart() { |
92 | | - final String effective = new SmartTime(Double.valueOf(60.0), true).toString(); |
93 | | - Assert.assertEquals("1.00 min", effective); |
94 | | - } |
95 | | - |
96 | | - @Test |
97 | | - public void min_59_default() { |
98 | | - final String effective = new SmartTime(Double.valueOf(3599.999), false).toString(); |
99 | | - Assert.assertEquals("3,599.999", effective); |
100 | | - } |
101 | | - |
102 | | - @Test |
103 | | - public void min_59_smart_and_rounded() { |
104 | | - final String effective = new SmartTime(Double.valueOf(3599.999), true).toString(); |
105 | | - Assert.assertEquals("60.00 min", effective); |
106 | | - } |
107 | | - |
108 | | - @Test |
109 | | - public void h_1_default() { |
110 | | - final String effective = new SmartTime(Double.valueOf(3600.0), false).toString(); |
111 | | - Assert.assertEquals("3,600.000", effective); |
112 | | - } |
113 | | - |
114 | | - @Test |
115 | | - public void h_1_smart() { |
116 | | - final String effective = new SmartTime(Double.valueOf(3600.0), true).toString(); |
117 | | - Assert.assertEquals("1.00 h", effective); |
118 | | - } |
119 | | - |
120 | | - @Test |
121 | | - public void h_max_default() { |
122 | | - final String effective = new SmartTime(Double.valueOf(99999.999), false).toString(); |
123 | | - Assert.assertEquals("99,999.999", effective); |
124 | | - } |
125 | | - |
126 | | - @Test |
127 | | - public void h_max_smart() { |
128 | | - final String effective = new SmartTime(Double.valueOf(99999.999), true).toString(); |
129 | | - Assert.assertEquals("27.78 h", effective); |
130 | | - } |
131 | | - |
132 | | - @Test |
133 | | - public void h_higher_than_max_default() { |
134 | | - final String effective = new SmartTime(Double.valueOf(100000000.0), false).toString(); |
135 | | - Assert.assertEquals("100,000,000.000", effective); |
136 | | - } |
137 | | - |
138 | | - @Test |
139 | | - public void h_higher_than_max_smart() { |
140 | | - final String effective = new SmartTime(Double.valueOf(100000000.0), true).toString(); |
141 | | - Assert.assertEquals("27777.78 h", effective); |
142 | | - } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void null_default() { |
| 26 | + final String effective = new SmartTime(null, false).toString(); |
| 27 | + Assert.assertEquals(null, effective); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void null_smart() { |
| 32 | + final String effective = new SmartTime(null, true).toString(); |
| 33 | + Assert.assertEquals(null, effective); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void ms_0_default() { |
| 38 | + final String effective = new SmartTime(0.0, false).toString(); |
| 39 | + Assert.assertEquals("0.000", effective); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void ms_0_smart() { |
| 44 | + final String effective = new SmartTime(0.0, true).toString(); |
| 45 | + Assert.assertEquals("0 ms", effective); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void ms_999_default() { |
| 50 | + final String effective = new SmartTime(0.999, false).toString(); |
| 51 | + Assert.assertEquals("0.999", effective); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void ms_999_smart() { |
| 56 | + final String effective = new SmartTime(0.999, true).toString(); |
| 57 | + Assert.assertEquals("999 ms", effective); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void s_1_default() { |
| 62 | + final String effective = new SmartTime(1.0, false).toString(); |
| 63 | + Assert.assertEquals("1.000", effective); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void s_1_smart() { |
| 68 | + final String effective = new SmartTime(1.0, true).toString(); |
| 69 | + Assert.assertEquals("1.000 s", effective); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void s_59_default() { |
| 74 | + final String effective = new SmartTime(59.999, false).toString(); |
| 75 | + Assert.assertEquals("59.999", effective); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void s_59_smart() { |
| 80 | + final String effective = new SmartTime(59.999, true).toString(); |
| 81 | + Assert.assertEquals("59.999 s", effective); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void min_1_default() { |
| 86 | + final String effective = new SmartTime(60.0, false).toString(); |
| 87 | + Assert.assertEquals("60.000", effective); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void min_1_smart() { |
| 92 | + final String effective = new SmartTime(60.0, true).toString(); |
| 93 | + Assert.assertEquals("1.00 min", effective); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void min_59_default() { |
| 98 | + final String effective = new SmartTime(3599.999, false).toString(); |
| 99 | + Assert.assertEquals("3,599.999", effective); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void min_59_smart_and_rounded() { |
| 104 | + final String effective = new SmartTime(3599.999, true).toString(); |
| 105 | + Assert.assertEquals("60.00 min", effective); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void h_1_default() { |
| 110 | + final String effective = new SmartTime(3600.0, false).toString(); |
| 111 | + Assert.assertEquals("3,600.000", effective); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void h_1_smart() { |
| 116 | + final String effective = new SmartTime(3600.0, true).toString(); |
| 117 | + Assert.assertEquals("1.00 h", effective); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void h_max_default() { |
| 122 | + final String effective = new SmartTime(99999.999, false).toString(); |
| 123 | + Assert.assertEquals("99,999.999", effective); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void h_max_smart() { |
| 128 | + final String effective = new SmartTime(99999.999, true).toString(); |
| 129 | + Assert.assertEquals("27.78 h", effective); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void h_higher_than_max_default() { |
| 134 | + // larger than format mask |
| 135 | + // grouping separator applied, even if not specified in format mask |
| 136 | + final String effective = new SmartTime(100000000.0, false).toString(); |
| 137 | + Assert.assertEquals("100,000,000.000", effective); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void h_higher_than_max_smart() { |
| 142 | + // larger than format mask |
| 143 | + // no grouping separator applied (that's ok) |
| 144 | + final String effective = new SmartTime(100000000.0, true).toString(); |
| 145 | + Assert.assertEquals("27777.78 h", effective); |
| 146 | + } |
143 | 147 | } |
0 commit comments