Skip to content

Commit 88b3c59

Browse files
authored
Merge pull request #52 from cquiroz/scalatest_port
Scalatest port
2 parents 77b7691 + 8d843ea commit 88b3c59

File tree

64 files changed

+4156
-3552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4156
-3552
lines changed

build.sbt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sbt._
2-
import io.github.soc.testng.{TestNGPlugin, TestNGScalaJSPlugin}
32
import TZDBTasks._
43

54
enablePlugins(MicrositesPlugin)
@@ -128,8 +127,6 @@ def copyAndReplace(srcDirs: Seq[File], destinationDir: File): Seq[File] = {
128127
}
129128

130129
lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
131-
.jvmConfigure(_.enablePlugins(TestNGPlugin))
132-
.jsConfigure(_.enablePlugins(TestNGScalaJSPlugin))
133130
.settings(commonSettings: _*)
134131
.jvmSettings(
135132
resolvers += Resolver.sbtPluginRepo("releases"),
@@ -138,8 +135,7 @@ lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
138135
baseDirectory in Test := baseDirectory.value.getParentFile,
139136
// Use CLDR provider for locales
140137
// https://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
141-
javaOptions in Test ++= Seq("-Duser.language=en", "-Duser.country=US", "-Djava.locale.providers=CLDR"),
142-
TestNGPlugin.testNGSuites := Seq(((resourceDirectory in Test).value / "testng.xml").absolutePath)
138+
javaOptions in Test ++= Seq("-Duser.language=en", "-Duser.country=US", "-Djava.locale.providers=CLDR")
143139
).jsSettings(
144140
tzDbSettings: _*
145141
).jsSettings(

changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<body>
1111
<!-- types are add, fix, remove, update -->
1212
<release version="2.0.0-M11" date="2017-04-16" description="v2.0.0-M11">
13+
<action dev="cquiroz" type="update" >
14+
Port all tests to scalatest
15+
</action>
1316
<action dev="alonsodomin" type="update" >
1417
Support localized timezone names
1518
</action>

js/src/test/scala/org/threeten/bp/Platform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.threeten.bp
33
object Platform {
44
type NPE = scala.scalajs.js.JavaScriptException
55
type DFE = scala.scalajs.runtime.UndefinedBehaviorError
6+
type CCE = scala.scalajs.runtime.UndefinedBehaviorError
67

78
/** Returns `true` if and only if the code is executing on a JVM.
89
* Note: Returns `false` when executing on any JS VM.

jvm/src/test/resources/testng.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

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

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

34-
import org.testng.Assert.assertEquals
35-
import org.testng.Assert.assertSame
36-
import org.testng.Assert.assertTrue
34+
import org.scalatest.FunSuite
3735
import java.io.ByteArrayInputStream
3836
import java.io.ByteArrayOutputStream
3937
import java.io.DataInputStream
@@ -47,33 +45,19 @@ import java.lang.reflect.Field
4745
import java.lang.reflect.Modifier
4846

4947
/** Base test class. */
50-
object AbstractTest {
48+
trait AbstractTest extends FunSuite with AssertionsHelper {
5149
private val SERIALISATION_DATA_FOLDER: String = "jvm/src/test/resources/"
5250

53-
def isIsoLeap(year: Long): Boolean =
54-
if (year % 4 != 0)
55-
false
56-
else if (year % 100 == 0 && year % 400 != 0)
57-
false
58-
else
59-
true
60-
61-
@throws(classOf[IOException])
62-
@throws(classOf[ClassNotFoundException])
6351
def assertSerializable(o: AnyRef): Unit = {
6452
val deserialisedObject: AnyRef = writeThenRead(o)
6553
assertEquals(deserialisedObject, o)
6654
}
6755

68-
@throws(classOf[IOException])
69-
@throws(classOf[ClassNotFoundException])
7056
def assertSerializableAndSame(o: AnyRef): Unit = {
7157
val deserialisedObject: AnyRef = writeThenRead(o)
7258
assertSame(deserialisedObject, o)
7359
}
7460

75-
@throws(classOf[IOException])
76-
@throws(classOf[ClassNotFoundException])
7761
def writeThenRead(o: AnyRef): AnyRef = {
7862
val baos: ByteArrayOutputStream = new ByteArrayOutputStream
7963
var oos: ObjectOutputStream = null
@@ -96,14 +80,10 @@ object AbstractTest {
9680
}
9781
}
9882

99-
@throws(classOf[IOException])
100-
@throws(classOf[ClassNotFoundException])
10183
def assertEqualsSerialisedForm(objectSerialised: AnyRef): Unit = {
10284
assertEqualsSerialisedForm(objectSerialised, objectSerialised.getClass)
10385
}
10486

105-
@throws(classOf[IOException])
106-
@throws(classOf[ClassNotFoundException])
10787
def assertEqualsSerialisedForm(objectSerialised: AnyRef, cls: Class[_]): Unit = {
10888
val className: String = cls.getSimpleName
10989
var in: ObjectInputStream = null
@@ -125,11 +105,11 @@ object AbstractTest {
125105
for (field <- fields) {
126106
if (!field.getName.contains("$")) {
127107
if (Modifier.isStatic(field.getModifiers)) {
128-
assertTrue(Modifier.isFinal(field.getModifiers), "Field:" + field.getName)
108+
assertTrue(Modifier.isFinal(field.getModifiers))
129109
}
130110
else {
131-
assertTrue(Modifier.isPrivate(field.getModifiers), "Field:" + field.getName)
132-
assertTrue(Modifier.isFinal(field.getModifiers), "Field:" + field.getName)
111+
assertTrue(Modifier.isPrivate(field.getModifiers))
112+
assertTrue(Modifier.isFinal(field.getModifiers))
133113
}
134114
}
135115
}
@@ -139,7 +119,6 @@ object AbstractTest {
139119
}
140120
}
141121

142-
@throws(classOf[Exception])
143122
def assertSerializedBySer(`object`: AnyRef, expectedBytes: Array[Byte], matches: Array[Byte]*): Unit = {
144123
val serClass: String = `object`.getClass.getPackage.getName + ".Ser"
145124
val serCls: Class[_] = Class.forName(serClass)

jvm/src/test/scala/org/threeten/bp/ClassLoaderChecker.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ package org.threeten.bp
3434
import java.io.DataInputStream
3535
import java.io.FileInputStream
3636
import java.io.FileNotFoundException
37-
import java.util.ArrayList
3837
import java.util.Collections
3938
import java.util.GregorianCalendar
40-
import java.util.HashMap
41-
import java.util.TreeMap
4239
import java.util.concurrent.ConcurrentHashMap
4340
import java.util.concurrent.locks.ReentrantLock
4441
import java.util.regex.Pattern
@@ -105,4 +102,4 @@ object ClassLoaderChecker {
105102
ldt.atZone(ZoneId.of("Europe/Paris"))
106103
System.out.println("************************************************************")
107104
}
108-
}
105+
}

jvm/src/test/scala/org/threeten/bp/Platform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.threeten.bp
33
object Platform {
44
type NPE = NullPointerException
55
type DFE = IndexOutOfBoundsException
6+
type CCE = ClassCastException
67

78
/** Returns `true` if and only if the code is executing on a JVM.
89
* Note: Returns `false` when executing on any JS VM.

jvm/src/test/scala/org/threeten/bp/TestClock_FixedSerialization.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ package org.threeten.bp
3333

3434
import org.scalatest.FunSuite
3535

36-
class TestClock_FixedSerialization extends FunSuite with AssertionsHelper {
36+
class TestClock_FixedSerialization extends FunSuite with AssertionsHelper with AbstractTest {
3737
test("isSerializable") {
38-
AbstractTest.assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, ZoneOffset.UTC))
39-
AbstractTest.assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, TestClock_Fixed.PARIS))
38+
assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, ZoneOffset.UTC))
39+
assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, TestClock_Fixed.PARIS))
4040
}
4141
}

jvm/src/test/scala/org/threeten/bp/TestClock_OffsetSerialization.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ package org.threeten.bp
3333

3434
import org.scalatest.FunSuite
3535

36-
class TestClock_OffsetSerialization extends FunSuite with AssertionsHelper {
36+
class TestClock_OffsetSerialization extends FunSuite with AssertionsHelper with AbstractTest {
3737
test("isSerializable") {
38-
AbstractTest.assertSerializable(Clock.offset(Clock.system(TestClock_Offset.PARIS), TestClock_Offset.OFFSET))
38+
assertSerializable(Clock.offset(Clock.system(TestClock_Offset.PARIS), TestClock_Offset.OFFSET))
3939
}
4040
}

jvm/src/test/scala/org/threeten/bp/TestClock_SystemSerialization.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ package org.threeten.bp
3333

3434
import org.scalatest.FunSuite
3535

36-
class TestClock_SystemSerialization extends FunSuite with AssertionsHelper {
36+
class TestClock_SystemSerialization extends FunSuite with AssertionsHelper with AbstractTest {
3737
test("isSerializable") {
38-
AbstractTest.assertSerializable(Clock.systemUTC)
39-
AbstractTest.assertSerializable(Clock.systemDefaultZone)
40-
AbstractTest.assertSerializable(Clock.system(TestClock_System.PARIS))
38+
assertSerializable(Clock.systemUTC)
39+
assertSerializable(Clock.systemDefaultZone)
40+
assertSerializable(Clock.system(TestClock_System.PARIS))
4141
}
4242

4343
}

jvm/src/test/scala/org/threeten/bp/TestClock_TickSerialization.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ package org.threeten.bp
3333

3434
import org.scalatest.FunSuite
3535

36-
class TestClock_TickSerialization extends FunSuite with AssertionsHelper {
36+
class TestClock_TickSerialization extends FunSuite with AssertionsHelper with AbstractTest {
3737
test("isSerializable") {
38-
AbstractTest.assertSerializable(Clock.tickSeconds(TestClock_Tick.PARIS))
39-
AbstractTest.assertSerializable(Clock.tickMinutes(TestClock_Tick.MOSCOW))
40-
AbstractTest.assertSerializable(Clock.tick(Clock.fixed(TestClock_Tick.INSTANT, TestClock_Tick.PARIS), TestClock_Tick.AMOUNT))
38+
assertSerializable(Clock.tickSeconds(TestClock_Tick.PARIS))
39+
assertSerializable(Clock.tickMinutes(TestClock_Tick.MOSCOW))
40+
assertSerializable(Clock.tick(Clock.fixed(TestClock_Tick.INSTANT, TestClock_Tick.PARIS), TestClock_Tick.AMOUNT))
4141
}
4242
}

jvm/src/test/scala/org/threeten/bp/TestDateTimeUtils.scala

Lines changed: 17 additions & 18 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
import java.util.Calendar
3837
import java.util.Date
@@ -48,26 +47,26 @@ object TestDateTimeUtils {
4847
private val PARIS_TZ: TimeZone = TimeZone.getTimeZone("Europe/Paris")
4948
}
5049

51-
@Test class TestDateTimeUtils {
52-
def test_toInstant_Date(): Unit = {
50+
class TestDateTimeUtils extends FunSuite with AssertionsHelper {
51+
test("test_toInstant_Date") {
5352
val date: Date = new Date(123456)
5453
assertEquals(DateTimeUtils.toInstant(date), Instant.ofEpochMilli(123456))
5554
}
5655

57-
def test_toDate_Instant(): Unit = {
56+
test("test_toDate_Instant") {
5857
val instant: Instant = Instant.ofEpochMilli(123456)
5958
assertEquals(DateTimeUtils.toDate(instant), new Date(123456))
6059
}
6160

6261
/*
63-
def test_toInstant_Calendar(): Unit = {
62+
test("test_toInstant_Calendar") {
6463
val calendar: Calendar = Calendar.getInstance
6564
calendar.setTimeInMillis(123456)
6665
assertEquals(DateTimeUtils.toInstant(calendar), Instant.ofEpochMilli(123456))
6766
}
6867
*/
6968

70-
def test_toZDT_Calendar(): Unit = {
69+
test("test_toZDT_Calendar") {
7170
val zdt: ZonedDateTime = ZonedDateTime.of(2012, 6, 30, 11, 30, 40, 0, TestDateTimeUtils.PARIS)
7271
val calendar: Calendar = Calendar.getInstance(TestDateTimeUtils.PARIS_TZ)
7372
calendar.setFirstDayOfWeek(Calendar.MONDAY)
@@ -77,7 +76,7 @@ object TestDateTimeUtils {
7776
assertEquals(DateTimeUtils.toZonedDateTime(calendar), zdt)
7877
}
7978

80-
def test_toCalendar_ZDT(): Unit = {
79+
test("test_toCalendar_ZDT") {
8180
val zdt: ZonedDateTime = ZonedDateTime.of(2012, 6, 30, 11, 30, 40, 0, TestDateTimeUtils.PARIS)
8281
val calendar: GregorianCalendar = new GregorianCalendar(TestDateTimeUtils.PARIS_TZ)
8382
calendar.setFirstDayOfWeek(Calendar.MONDAY)
@@ -90,58 +89,58 @@ object TestDateTimeUtils {
9089
assertEquals(test, calendar)
9190
}
9291

93-
def test_toZoneId_TimeZone(): Unit = {
92+
test("test_toZoneId_TimeZone") {
9493
assertEquals(DateTimeUtils.toZoneId(TestDateTimeUtils.PARIS_TZ), TestDateTimeUtils.PARIS)
9594
}
9695

97-
def test_toTimeZone_ZoneId(): Unit = {
96+
test("test_toTimeZone_ZoneId") {
9897
assertEquals(DateTimeUtils.toTimeZone(TestDateTimeUtils.PARIS), TestDateTimeUtils.PARIS_TZ)
9998
}
10099

101100
/*
102-
def test_toLocalDate_SqlDate(): Unit = {
101+
test("test_toLocalDate_SqlDate") {
103102
@SuppressWarnings(Array("deprecation")) val sqlDate: Date = new Date(2012 - 1900, 6 - 1, 30)
104103
val localDate: LocalDate = LocalDate.of(2012, 6, 30)
105104
assertEquals(DateTimeUtils.toLocalDate(sqlDate), localDate)
106105
}
107106
*/
108107

109-
def test_toSqlDate_LocalDate(): Unit = {
108+
test("test_toSqlDate_LocalDate") {
110109
@SuppressWarnings(Array("deprecation")) val sqlDate: Date = new Date(2012 - 1900, 6 - 1, 30)
111110
val localDate: LocalDate = LocalDate.of(2012, 6, 30)
112111
assertEquals(DateTimeUtils.toSqlDate(localDate), sqlDate)
113112
}
114113

115-
def test_toLocalTime_SqlTime(): Unit = {
114+
test("test_toLocalTime_SqlTime") {
116115
@SuppressWarnings(Array("deprecation")) val sqlTime: Time = new Time(11, 30, 40)
117116
val localTime: LocalTime = LocalTime.of(11, 30, 40)
118117
assertEquals(DateTimeUtils.toLocalTime(sqlTime), localTime)
119118
}
120119

121-
def test_toSqlTime_LocalTime(): Unit = {
120+
test("test_toSqlTime_LocalTime") {
122121
@SuppressWarnings(Array("deprecation")) val sqlTime: Time = new Time(11, 30, 40)
123122
val localTime: LocalTime = LocalTime.of(11, 30, 40)
124123
assertEquals(DateTimeUtils.toSqlTime(localTime), sqlTime)
125124
}
126125

127-
def test_toLocalDateTime_SqlTimestamp(): Unit = {
126+
test("test_toLocalDateTime_SqlTimestamp") {
128127
@SuppressWarnings(Array("deprecation")) val sqlDateTime: Timestamp = new Timestamp(2012 - 1900, 6 - 1, 30, 11, 30, 40, 0)
129128
val localDateTime: LocalDateTime = LocalDateTime.of(2012, 6, 30, 11, 30, 40, 0)
130129
assertEquals(DateTimeUtils.toLocalDateTime(sqlDateTime), localDateTime)
131130
}
132131

133-
def test_toSqlTimestamp_LocalDateTime(): Unit = {
132+
test("test_toSqlTimestamp_LocalDateTime") {
134133
@SuppressWarnings(Array("deprecation")) val sqlDateTime: Timestamp = new Timestamp(2012 - 1900, 6 - 1, 30, 11, 30, 40, 0)
135134
val localDateTime: LocalDateTime = LocalDateTime.of(2012, 6, 30, 11, 30, 40, 0)
136135
assertEquals(DateTimeUtils.toSqlTimestamp(localDateTime), sqlDateTime)
137136
}
138137

139-
def test_toInstant_SqlTimestamp(): Unit = {
138+
test("test_toInstant_SqlTimestamp") {
140139
@SuppressWarnings(Array("deprecation")) val sqlDateTime: Timestamp = new Timestamp(2012 - 1900, 6 - 1, 30, 11, 30, 40, 0)
141140
assertEquals(DateTimeUtils.toInstant(sqlDateTime), Instant.ofEpochMilli(sqlDateTime.getTime))
142141
}
143142

144-
def test_toSqlTimestamp_Instant(): Unit = {
143+
test("test_toSqlTimestamp_Instant") {
145144
val instant: Instant = Instant.ofEpochMilli(123456)
146145
val sqlDateTime: Timestamp = new Timestamp(instant.toEpochMilli)
147146
assertEquals(DateTimeUtils.toSqlTimestamp(instant), sqlDateTime)

0 commit comments

Comments
 (0)