31
31
*/
32
32
package org .threeten .bp
33
33
34
- import org .testng .Assert .assertEquals
35
- import org .testng .annotations .Test
34
+ import org .scalatest .FunSuite
36
35
37
36
/** Test OffsetDateTime creation. */
38
37
object TestOffsetDateTime_instants {
@@ -41,17 +40,21 @@ object TestOffsetDateTime_instants {
41
40
private val OFFSET_MIN : ZoneOffset = ZoneOffset .ofHours(- 18 )
42
41
}
43
42
44
- @ Test class TestOffsetDateTime_instants {
45
- @ Test (expectedExceptions = Array (classOf [NullPointerException ])) def factory_ofInstant_nullInstant (): Unit = {
46
- OffsetDateTime .ofInstant(null .asInstanceOf [Instant ], TestOffsetDateTime_instants .OFFSET_PONE )
43
+ class TestOffsetDateTime_instants extends FunSuite with AssertionsHelper {
44
+ test(" factory_ofInstant_nullInstant" ) {
45
+ assertThrows[NullPointerException ] {
46
+ OffsetDateTime .ofInstant(null .asInstanceOf [Instant ], TestOffsetDateTime_instants .OFFSET_PONE )
47
+ }
47
48
}
48
49
49
- @ Test (expectedExceptions = Array (classOf [NullPointerException ])) def factory_ofInstant_nullOffset (): Unit = {
50
- val instant : Instant = Instant .ofEpochSecond(0L )
51
- OffsetDateTime .ofInstant(instant, null .asInstanceOf [ZoneOffset ])
50
+ test(" factory_ofInstant_nullOffset" ) {
51
+ assertThrows[NullPointerException ] {
52
+ val instant : Instant = Instant .ofEpochSecond(0L )
53
+ OffsetDateTime .ofInstant(instant, null .asInstanceOf [ZoneOffset ])
54
+ }
52
55
}
53
56
54
- def factory_ofInstant_allSecsInDay () : Unit = {
57
+ test( " factory_ofInstant_allSecsInDay " ) {
55
58
{
56
59
var i : Int = 0
57
60
while (i < (24 * 60 * 60 )) {
@@ -73,7 +76,7 @@ object TestOffsetDateTime_instants {
73
76
}
74
77
}
75
78
76
- def factory_ofInstant_allDaysInCycle () : Unit = {
79
+ test( " factory_ofInstant_allDaysInCycle " ) {
77
80
var expected : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 1 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
78
81
79
82
{
@@ -93,35 +96,39 @@ object TestOffsetDateTime_instants {
93
96
}
94
97
}
95
98
96
- def factory_ofInstant_history () : Unit = {
99
+ test( " factory_ofInstant_history " ) {
97
100
doTest_factory_ofInstant_all(- 2820 , 2820 )
98
101
}
99
102
100
- def factory_ofInstant_minYear () : Unit = {
103
+ test( " factory_ofInstant_minYear " ) {
101
104
doTest_factory_ofInstant_all(Year .MIN_VALUE , Year .MIN_VALUE + 420 )
102
105
}
103
106
104
- @ Test (expectedExceptions = Array (classOf [DateTimeException ])) def factory_ofInstant_tooLow (): Unit = {
105
- val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
106
- val year : Int = Year .MIN_VALUE - 1
107
- val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
108
- val instant : Instant = Instant .ofEpochSecond(days * 24L * 60L * 60L )
109
- OffsetDateTime .ofInstant(instant, ZoneOffset .UTC )
107
+ test(" factory_ofInstant_tooLow" ) {
108
+ assertThrows[DateTimeException ] {
109
+ val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
110
+ val year : Int = Year .MIN_VALUE - 1
111
+ val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
112
+ val instant : Instant = Instant .ofEpochSecond(days * 24L * 60L * 60L )
113
+ OffsetDateTime .ofInstant(instant, ZoneOffset .UTC )
114
+ }
110
115
}
111
116
112
- def factory_ofInstant_maxYear () : Unit = {
117
+ test( " factory_ofInstant_maxYear " ) {
113
118
doTest_factory_ofInstant_all(Year .MAX_VALUE - 420 , Year .MAX_VALUE )
114
119
}
115
120
116
- @ Test (expectedExceptions = Array (classOf [DateTimeException ])) def factory_ofInstant_tooBig (): Unit = {
117
- val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
118
- val year : Long = Year .MAX_VALUE + 1L
119
- val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
120
- val instant : Instant = Instant .ofEpochSecond(days * 24L * 60L * 60L )
121
- OffsetDateTime .ofInstant(instant, ZoneOffset .UTC )
121
+ test(" factory_ofInstant_tooBig" ) {
122
+ assertThrows[DateTimeException ] {
123
+ val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
124
+ val year : Long = Year .MAX_VALUE + 1L
125
+ val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
126
+ val instant : Instant = Instant .ofEpochSecond(days * 24L * 60L * 60L )
127
+ OffsetDateTime .ofInstant(instant, ZoneOffset .UTC )
128
+ }
122
129
}
123
130
124
- def factory_ofInstant_minWithMinOffset () : Unit = {
131
+ test( " factory_ofInstant_minWithMinOffset " ) {
125
132
val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
126
133
val year : Int = Year .MIN_VALUE
127
134
val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
@@ -137,7 +144,7 @@ object TestOffsetDateTime_instants {
137
144
assertEquals(test.getNano, 0 )
138
145
}
139
146
140
- def factory_ofInstant_minWithMaxOffset () : Unit = {
147
+ test( " factory_ofInstant_minWithMaxOffset " ) {
141
148
val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
142
149
val year : Int = Year .MIN_VALUE
143
150
val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) - days_0000_to_1970
@@ -153,7 +160,7 @@ object TestOffsetDateTime_instants {
153
160
assertEquals(test.getNano, 0 )
154
161
}
155
162
156
- def factory_ofInstant_maxWithMinOffset () : Unit = {
163
+ test( " factory_ofInstant_maxWithMinOffset " ) {
157
164
val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
158
165
val year : Int = Year .MAX_VALUE
159
166
val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) + 365 - days_0000_to_1970
@@ -169,7 +176,7 @@ object TestOffsetDateTime_instants {
169
176
assertEquals(test.getNano, 0 )
170
177
}
171
178
172
- def factory_ofInstant_maxWithMaxOffset () : Unit = {
179
+ test( " factory_ofInstant_maxWithMaxOffset " ) {
173
180
val days_0000_to_1970 : Long = (146097 * 5 ) - (30 * 365 + 7 )
174
181
val year : Int = Year .MAX_VALUE
175
182
val days : Long = (year * 365L + (year / 4 - year / 100 + year / 400 )) + 365 - days_0000_to_1970
@@ -185,14 +192,18 @@ object TestOffsetDateTime_instants {
185
192
assertEquals(test.getNano, 0 )
186
193
}
187
194
188
- @ Test (expectedExceptions = Array (classOf [DateTimeException ])) def factory_ofInstant_maxInstantWithMaxOffset (): Unit = {
189
- val instant : Instant = Instant .ofEpochSecond(Long .MaxValue )
190
- OffsetDateTime .ofInstant(instant, TestOffsetDateTime_instants .OFFSET_MAX )
195
+ test(" factory_ofInstant_maxInstantWithMaxOffset" ) {
196
+ assertThrows[DateTimeException ] {
197
+ val instant : Instant = Instant .ofEpochSecond(Long .MaxValue )
198
+ OffsetDateTime .ofInstant(instant, TestOffsetDateTime_instants .OFFSET_MAX )
199
+ }
191
200
}
192
201
193
- @ Test (expectedExceptions = Array (classOf [DateTimeException ])) def factory_ofInstant_maxInstantWithMinOffset (): Unit = {
194
- val instant : Instant = Instant .ofEpochSecond(Long .MaxValue )
195
- OffsetDateTime .ofInstant(instant, TestOffsetDateTime_instants .OFFSET_MIN )
202
+ test(" factory_ofInstant_maxInstantWithMinOffset" ) {
203
+ assertThrows[DateTimeException ] {
204
+ val instant : Instant = Instant .ofEpochSecond(Long .MaxValue )
205
+ OffsetDateTime .ofInstant(instant, TestOffsetDateTime_instants .OFFSET_MIN )
206
+ }
196
207
}
197
208
198
209
private def doTest_factory_ofInstant_all (minYear : Long , maxYear : Long ): Unit = {
@@ -233,62 +244,62 @@ object TestOffsetDateTime_instants {
233
244
}
234
245
}
235
246
236
- def test_toInstant_19700101 () : Unit = {
247
+ test( " toInstant_19700101 " ) {
237
248
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 1 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
238
249
val test : Instant = dt.toInstant
239
250
assertEquals(test.getEpochSecond, 0 )
240
251
assertEquals(test.getNano, 0 )
241
252
}
242
253
243
- def test_toInstant_19700101_oneNano () : Unit = {
254
+ test( " toInstant_19700101_oneNano " ) {
244
255
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 1 ), LocalTime .of(0 , 0 , 0 , 1 ), ZoneOffset .UTC )
245
256
val test : Instant = dt.toInstant
246
257
assertEquals(test.getEpochSecond, 0 )
247
258
assertEquals(test.getNano, 1 )
248
259
}
249
260
250
- def test_toInstant_19700101_minusOneNano () : Unit = {
261
+ test( " toInstant_19700101_minusOneNano " ) {
251
262
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1969 , 12 , 31 ), LocalTime .of(23 , 59 , 59 , 999999999 ), ZoneOffset .UTC )
252
263
val test : Instant = dt.toInstant
253
264
assertEquals(test.getEpochSecond, - 1 )
254
265
assertEquals(test.getNano, 999999999 )
255
266
}
256
267
257
- def test_toInstant_19700102 () : Unit = {
268
+ test( " toInstant_19700102 " ) {
258
269
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 2 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
259
270
val test : Instant = dt.toInstant
260
271
assertEquals(test.getEpochSecond, 24L * 60L * 60L )
261
272
assertEquals(test.getNano, 0 )
262
273
}
263
274
264
- def test_toInstant_19691231 () : Unit = {
275
+ test( " toInstant_19691231 " ) {
265
276
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1969 , 12 , 31 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
266
277
val test : Instant = dt.toInstant
267
278
assertEquals(test.getEpochSecond, - 24L * 60L * 60L )
268
279
assertEquals(test.getNano, 0 )
269
280
}
270
281
271
- def test_toEpochSecond_19700101 () : Unit = {
282
+ test( " toEpochSecond_19700101 " ) {
272
283
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 1 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
273
284
assertEquals(dt.toEpochSecond, 0 )
274
285
}
275
286
276
- def test_toEpochSecond_19700101_oneNano () : Unit = {
287
+ test( " toEpochSecond_19700101_oneNano " ) {
277
288
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 1 ), LocalTime .of(0 , 0 , 0 , 1 ), ZoneOffset .UTC )
278
289
assertEquals(dt.toEpochSecond, 0 )
279
290
}
280
291
281
- def test_toEpochSecond_19700101_minusOneNano () : Unit = {
292
+ test( " toEpochSecond_19700101_minusOneNano " ) {
282
293
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1969 , 12 , 31 ), LocalTime .of(23 , 59 , 59 , 999999999 ), ZoneOffset .UTC )
283
294
assertEquals(dt.toEpochSecond, - 1 )
284
295
}
285
296
286
- def test_toEpochSecond_19700102 () : Unit = {
297
+ test( " toEpochSecond_19700102 " ) {
287
298
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1970 , 1 , 2 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
288
299
assertEquals(dt.toEpochSecond, 24L * 60L * 60L )
289
300
}
290
301
291
- def test_toEpochSecond_19691231 () : Unit = {
302
+ test( " toEpochSecond_19691231 " ) {
292
303
val dt : OffsetDateTime = OffsetDateTime .of(LocalDate .of(1969 , 12 , 31 ), LocalTime .of(0 , 0 , 0 , 0 ), ZoneOffset .UTC )
293
304
assertEquals(dt.toEpochSecond, - 24L * 60L * 60L )
294
305
}
0 commit comments