Skip to content

Commit 729487f

Browse files
committed
Port of TestOffsetDateTime_instants to scalatest
1 parent 970ca85 commit 729487f

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

jvm/src/test/scala/org/threeten/bp/TestOffsetDateTime_instants.scala renamed to shared/src/test/scala/org/threeten/bp/TestOffsetDateTime_instants.scala

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
*/
3232
package org.threeten.bp
3333

34-
import org.testng.Assert.assertEquals
35-
import org.testng.annotations.Test
34+
import org.scalatest.FunSuite
3635

3736
/** Test OffsetDateTime creation. */
3837
object TestOffsetDateTime_instants {
@@ -41,17 +40,21 @@ object TestOffsetDateTime_instants {
4140
private val OFFSET_MIN: ZoneOffset = ZoneOffset.ofHours(-18)
4241
}
4342

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+
}
4748
}
4849

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+
}
5255
}
5356

54-
def factory_ofInstant_allSecsInDay(): Unit = {
57+
test("factory_ofInstant_allSecsInDay") {
5558
{
5659
var i: Int = 0
5760
while (i < (24 * 60 * 60)) {
@@ -73,7 +76,7 @@ object TestOffsetDateTime_instants {
7376
}
7477
}
7578

76-
def factory_ofInstant_allDaysInCycle(): Unit = {
79+
test("factory_ofInstant_allDaysInCycle") {
7780
var expected: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
7881

7982
{
@@ -93,35 +96,39 @@ object TestOffsetDateTime_instants {
9396
}
9497
}
9598

96-
def factory_ofInstant_history(): Unit = {
99+
test("factory_ofInstant_history") {
97100
doTest_factory_ofInstant_all(-2820, 2820)
98101
}
99102

100-
def factory_ofInstant_minYear(): Unit = {
103+
test("factory_ofInstant_minYear") {
101104
doTest_factory_ofInstant_all(Year.MIN_VALUE, Year.MIN_VALUE + 420)
102105
}
103106

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+
}
110115
}
111116

112-
def factory_ofInstant_maxYear(): Unit = {
117+
test("factory_ofInstant_maxYear") {
113118
doTest_factory_ofInstant_all(Year.MAX_VALUE - 420, Year.MAX_VALUE)
114119
}
115120

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+
}
122129
}
123130

124-
def factory_ofInstant_minWithMinOffset(): Unit = {
131+
test("factory_ofInstant_minWithMinOffset") {
125132
val days_0000_to_1970: Long = (146097 * 5) - (30 * 365 + 7)
126133
val year: Int = Year.MIN_VALUE
127134
val days: Long = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970
@@ -137,7 +144,7 @@ object TestOffsetDateTime_instants {
137144
assertEquals(test.getNano, 0)
138145
}
139146

140-
def factory_ofInstant_minWithMaxOffset(): Unit = {
147+
test("factory_ofInstant_minWithMaxOffset") {
141148
val days_0000_to_1970: Long = (146097 * 5) - (30 * 365 + 7)
142149
val year: Int = Year.MIN_VALUE
143150
val days: Long = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970
@@ -153,7 +160,7 @@ object TestOffsetDateTime_instants {
153160
assertEquals(test.getNano, 0)
154161
}
155162

156-
def factory_ofInstant_maxWithMinOffset(): Unit = {
163+
test("factory_ofInstant_maxWithMinOffset") {
157164
val days_0000_to_1970: Long = (146097 * 5) - (30 * 365 + 7)
158165
val year: Int = Year.MAX_VALUE
159166
val days: Long = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970
@@ -169,7 +176,7 @@ object TestOffsetDateTime_instants {
169176
assertEquals(test.getNano, 0)
170177
}
171178

172-
def factory_ofInstant_maxWithMaxOffset(): Unit = {
179+
test("factory_ofInstant_maxWithMaxOffset") {
173180
val days_0000_to_1970: Long = (146097 * 5) - (30 * 365 + 7)
174181
val year: Int = Year.MAX_VALUE
175182
val days: Long = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970
@@ -185,14 +192,18 @@ object TestOffsetDateTime_instants {
185192
assertEquals(test.getNano, 0)
186193
}
187194

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+
}
191200
}
192201

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+
}
196207
}
197208

198209
private def doTest_factory_ofInstant_all(minYear: Long, maxYear: Long): Unit = {
@@ -233,62 +244,62 @@ object TestOffsetDateTime_instants {
233244
}
234245
}
235246

236-
def test_toInstant_19700101(): Unit = {
247+
test("toInstant_19700101") {
237248
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
238249
val test: Instant = dt.toInstant
239250
assertEquals(test.getEpochSecond, 0)
240251
assertEquals(test.getNano, 0)
241252
}
242253

243-
def test_toInstant_19700101_oneNano(): Unit = {
254+
test("toInstant_19700101_oneNano") {
244255
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 1), ZoneOffset.UTC)
245256
val test: Instant = dt.toInstant
246257
assertEquals(test.getEpochSecond, 0)
247258
assertEquals(test.getNano, 1)
248259
}
249260

250-
def test_toInstant_19700101_minusOneNano(): Unit = {
261+
test("toInstant_19700101_minusOneNano") {
251262
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1969, 12, 31), LocalTime.of(23, 59, 59, 999999999), ZoneOffset.UTC)
252263
val test: Instant = dt.toInstant
253264
assertEquals(test.getEpochSecond, -1)
254265
assertEquals(test.getNano, 999999999)
255266
}
256267

257-
def test_toInstant_19700102(): Unit = {
268+
test("toInstant_19700102") {
258269
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 2), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
259270
val test: Instant = dt.toInstant
260271
assertEquals(test.getEpochSecond, 24L * 60L * 60L)
261272
assertEquals(test.getNano, 0)
262273
}
263274

264-
def test_toInstant_19691231(): Unit = {
275+
test("toInstant_19691231") {
265276
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1969, 12, 31), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
266277
val test: Instant = dt.toInstant
267278
assertEquals(test.getEpochSecond, -24L * 60L * 60L)
268279
assertEquals(test.getNano, 0)
269280
}
270281

271-
def test_toEpochSecond_19700101(): Unit = {
282+
test("toEpochSecond_19700101") {
272283
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
273284
assertEquals(dt.toEpochSecond, 0)
274285
}
275286

276-
def test_toEpochSecond_19700101_oneNano(): Unit = {
287+
test("toEpochSecond_19700101_oneNano") {
277288
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 1), ZoneOffset.UTC)
278289
assertEquals(dt.toEpochSecond, 0)
279290
}
280291

281-
def test_toEpochSecond_19700101_minusOneNano(): Unit = {
292+
test("toEpochSecond_19700101_minusOneNano") {
282293
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1969, 12, 31), LocalTime.of(23, 59, 59, 999999999), ZoneOffset.UTC)
283294
assertEquals(dt.toEpochSecond, -1)
284295
}
285296

286-
def test_toEpochSecond_19700102(): Unit = {
297+
test("toEpochSecond_19700102") {
287298
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1970, 1, 2), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
288299
assertEquals(dt.toEpochSecond, 24L * 60L * 60L)
289300
}
290301

291-
def test_toEpochSecond_19691231(): Unit = {
302+
test("toEpochSecond_19691231") {
292303
val dt: OffsetDateTime = OffsetDateTime.of(LocalDate.of(1969, 12, 31), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC)
293304
assertEquals(dt.toEpochSecond, -24L * 60L * 60L)
294305
}

0 commit comments

Comments
 (0)