Skip to content

Scalatest port #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sbt._
import io.github.soc.testng.{TestNGPlugin, TestNGScalaJSPlugin}
import TZDBTasks._

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

lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
.jvmConfigure(_.enablePlugins(TestNGPlugin))
.jsConfigure(_.enablePlugins(TestNGScalaJSPlugin))
.settings(commonSettings: _*)
.jvmSettings(
resolvers += Resolver.sbtPluginRepo("releases"),
Expand All @@ -138,8 +135,7 @@ lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
baseDirectory in Test := baseDirectory.value.getParentFile,
// Use CLDR provider for locales
// https://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
javaOptions in Test ++= Seq("-Duser.language=en", "-Duser.country=US", "-Djava.locale.providers=CLDR"),
TestNGPlugin.testNGSuites := Seq(((resourceDirectory in Test).value / "testng.xml").absolutePath)
javaOptions in Test ++= Seq("-Duser.language=en", "-Duser.country=US", "-Djava.locale.providers=CLDR")
).jsSettings(
tzDbSettings: _*
).jsSettings(
Expand Down
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<body>
<!-- types are add, fix, remove, update -->
<release version="2.0.0-M11" date="2017-04-16" description="v2.0.0-M11">
<action dev="cquiroz" type="update" >
Port all tests to scalatest
</action>
<action dev="alonsodomin" type="update" >
Support localized timezone names
</action>
Expand Down
1 change: 1 addition & 0 deletions js/src/test/scala/org/threeten/bp/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.threeten.bp
object Platform {
type NPE = scala.scalajs.js.JavaScriptException
type DFE = scala.scalajs.runtime.UndefinedBehaviorError
type CCE = scala.scalajs.runtime.UndefinedBehaviorError

/** Returns `true` if and only if the code is executing on a JVM.
* Note: Returns `false` when executing on any JS VM.
Expand Down
8 changes: 0 additions & 8 deletions jvm/src/test/resources/testng.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
*/
package org.threeten.bp

import org.testng.Assert.assertEquals
import org.testng.Assert.assertSame
import org.testng.Assert.assertTrue
import org.scalatest.FunSuite
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.DataInputStream
Expand All @@ -47,33 +45,19 @@ import java.lang.reflect.Field
import java.lang.reflect.Modifier

/** Base test class. */
object AbstractTest {
trait AbstractTest extends FunSuite with AssertionsHelper {
private val SERIALISATION_DATA_FOLDER: String = "jvm/src/test/resources/"

def isIsoLeap(year: Long): Boolean =
if (year % 4 != 0)
false
else if (year % 100 == 0 && year % 400 != 0)
false
else
true

@throws(classOf[IOException])
@throws(classOf[ClassNotFoundException])
def assertSerializable(o: AnyRef): Unit = {
val deserialisedObject: AnyRef = writeThenRead(o)
assertEquals(deserialisedObject, o)
}

@throws(classOf[IOException])
@throws(classOf[ClassNotFoundException])
def assertSerializableAndSame(o: AnyRef): Unit = {
val deserialisedObject: AnyRef = writeThenRead(o)
assertSame(deserialisedObject, o)
}

@throws(classOf[IOException])
@throws(classOf[ClassNotFoundException])
def writeThenRead(o: AnyRef): AnyRef = {
val baos: ByteArrayOutputStream = new ByteArrayOutputStream
var oos: ObjectOutputStream = null
Expand All @@ -96,14 +80,10 @@ object AbstractTest {
}
}

@throws(classOf[IOException])
@throws(classOf[ClassNotFoundException])
def assertEqualsSerialisedForm(objectSerialised: AnyRef): Unit = {
assertEqualsSerialisedForm(objectSerialised, objectSerialised.getClass)
}

@throws(classOf[IOException])
@throws(classOf[ClassNotFoundException])
def assertEqualsSerialisedForm(objectSerialised: AnyRef, cls: Class[_]): Unit = {
val className: String = cls.getSimpleName
var in: ObjectInputStream = null
Expand All @@ -125,11 +105,11 @@ object AbstractTest {
for (field <- fields) {
if (!field.getName.contains("$")) {
if (Modifier.isStatic(field.getModifiers)) {
assertTrue(Modifier.isFinal(field.getModifiers), "Field:" + field.getName)
assertTrue(Modifier.isFinal(field.getModifiers))
}
else {
assertTrue(Modifier.isPrivate(field.getModifiers), "Field:" + field.getName)
assertTrue(Modifier.isFinal(field.getModifiers), "Field:" + field.getName)
assertTrue(Modifier.isPrivate(field.getModifiers))
assertTrue(Modifier.isFinal(field.getModifiers))
}
}
}
Expand All @@ -139,7 +119,6 @@ object AbstractTest {
}
}

@throws(classOf[Exception])
def assertSerializedBySer(`object`: AnyRef, expectedBytes: Array[Byte], matches: Array[Byte]*): Unit = {
val serClass: String = `object`.getClass.getPackage.getName + ".Ser"
val serCls: Class[_] = Class.forName(serClass)
Expand Down
5 changes: 1 addition & 4 deletions jvm/src/test/scala/org/threeten/bp/ClassLoaderChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ package org.threeten.bp
import java.io.DataInputStream
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.util.ArrayList
import java.util.Collections
import java.util.GregorianCalendar
import java.util.HashMap
import java.util.TreeMap
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.locks.ReentrantLock
import java.util.regex.Pattern
Expand Down Expand Up @@ -105,4 +102,4 @@ object ClassLoaderChecker {
ldt.atZone(ZoneId.of("Europe/Paris"))
System.out.println("************************************************************")
}
}
}
1 change: 1 addition & 0 deletions jvm/src/test/scala/org/threeten/bp/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.threeten.bp
object Platform {
type NPE = NullPointerException
type DFE = IndexOutOfBoundsException
type CCE = ClassCastException

/** Returns `true` if and only if the code is executing on a JVM.
* Note: Returns `false` when executing on any JS VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ package org.threeten.bp

import org.scalatest.FunSuite

class TestClock_FixedSerialization extends FunSuite with AssertionsHelper {
class TestClock_FixedSerialization extends FunSuite with AssertionsHelper with AbstractTest {
test("isSerializable") {
AbstractTest.assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, ZoneOffset.UTC))
AbstractTest.assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, TestClock_Fixed.PARIS))
assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, ZoneOffset.UTC))
assertSerializable(Clock.fixed(TestClock_Fixed.INSTANT, TestClock_Fixed.PARIS))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ package org.threeten.bp

import org.scalatest.FunSuite

class TestClock_OffsetSerialization extends FunSuite with AssertionsHelper {
class TestClock_OffsetSerialization extends FunSuite with AssertionsHelper with AbstractTest {
test("isSerializable") {
AbstractTest.assertSerializable(Clock.offset(Clock.system(TestClock_Offset.PARIS), TestClock_Offset.OFFSET))
assertSerializable(Clock.offset(Clock.system(TestClock_Offset.PARIS), TestClock_Offset.OFFSET))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ package org.threeten.bp

import org.scalatest.FunSuite

class TestClock_SystemSerialization extends FunSuite with AssertionsHelper {
class TestClock_SystemSerialization extends FunSuite with AssertionsHelper with AbstractTest {
test("isSerializable") {
AbstractTest.assertSerializable(Clock.systemUTC)
AbstractTest.assertSerializable(Clock.systemDefaultZone)
AbstractTest.assertSerializable(Clock.system(TestClock_System.PARIS))
assertSerializable(Clock.systemUTC)
assertSerializable(Clock.systemDefaultZone)
assertSerializable(Clock.system(TestClock_System.PARIS))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ package org.threeten.bp

import org.scalatest.FunSuite

class TestClock_TickSerialization extends FunSuite with AssertionsHelper {
class TestClock_TickSerialization extends FunSuite with AssertionsHelper with AbstractTest {
test("isSerializable") {
AbstractTest.assertSerializable(Clock.tickSeconds(TestClock_Tick.PARIS))
AbstractTest.assertSerializable(Clock.tickMinutes(TestClock_Tick.MOSCOW))
AbstractTest.assertSerializable(Clock.tick(Clock.fixed(TestClock_Tick.INSTANT, TestClock_Tick.PARIS), TestClock_Tick.AMOUNT))
assertSerializable(Clock.tickSeconds(TestClock_Tick.PARIS))
assertSerializable(Clock.tickMinutes(TestClock_Tick.MOSCOW))
assertSerializable(Clock.tick(Clock.fixed(TestClock_Tick.INSTANT, TestClock_Tick.PARIS), TestClock_Tick.AMOUNT))
}
}
35 changes: 17 additions & 18 deletions jvm/src/test/scala/org/threeten/bp/TestDateTimeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
*/
package org.threeten.bp

import org.testng.Assert.assertEquals
import org.testng.annotations.Test
import org.scalatest.FunSuite

import java.util.Calendar
import java.util.Date
Expand All @@ -48,26 +47,26 @@ object TestDateTimeUtils {
private val PARIS_TZ: TimeZone = TimeZone.getTimeZone("Europe/Paris")
}

@Test class TestDateTimeUtils {
def test_toInstant_Date(): Unit = {
class TestDateTimeUtils extends FunSuite with AssertionsHelper {
test("test_toInstant_Date") {
val date: Date = new Date(123456)
assertEquals(DateTimeUtils.toInstant(date), Instant.ofEpochMilli(123456))
}

def test_toDate_Instant(): Unit = {
test("test_toDate_Instant") {
val instant: Instant = Instant.ofEpochMilli(123456)
assertEquals(DateTimeUtils.toDate(instant), new Date(123456))
}

/*
def test_toInstant_Calendar(): Unit = {
test("test_toInstant_Calendar") {
val calendar: Calendar = Calendar.getInstance
calendar.setTimeInMillis(123456)
assertEquals(DateTimeUtils.toInstant(calendar), Instant.ofEpochMilli(123456))
}
*/

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

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

def test_toZoneId_TimeZone(): Unit = {
test("test_toZoneId_TimeZone") {
assertEquals(DateTimeUtils.toZoneId(TestDateTimeUtils.PARIS_TZ), TestDateTimeUtils.PARIS)
}

def test_toTimeZone_ZoneId(): Unit = {
test("test_toTimeZone_ZoneId") {
assertEquals(DateTimeUtils.toTimeZone(TestDateTimeUtils.PARIS), TestDateTimeUtils.PARIS_TZ)
}

/*
def test_toLocalDate_SqlDate(): Unit = {
test("test_toLocalDate_SqlDate") {
@SuppressWarnings(Array("deprecation")) val sqlDate: Date = new Date(2012 - 1900, 6 - 1, 30)
val localDate: LocalDate = LocalDate.of(2012, 6, 30)
assertEquals(DateTimeUtils.toLocalDate(sqlDate), localDate)
}
*/

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

def test_toLocalTime_SqlTime(): Unit = {
test("test_toLocalTime_SqlTime") {
@SuppressWarnings(Array("deprecation")) val sqlTime: Time = new Time(11, 30, 40)
val localTime: LocalTime = LocalTime.of(11, 30, 40)
assertEquals(DateTimeUtils.toLocalTime(sqlTime), localTime)
}

def test_toSqlTime_LocalTime(): Unit = {
test("test_toSqlTime_LocalTime") {
@SuppressWarnings(Array("deprecation")) val sqlTime: Time = new Time(11, 30, 40)
val localTime: LocalTime = LocalTime.of(11, 30, 40)
assertEquals(DateTimeUtils.toSqlTime(localTime), sqlTime)
}

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

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

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

def test_toSqlTimestamp_Instant(): Unit = {
test("test_toSqlTimestamp_Instant") {
val instant: Instant = Instant.ofEpochMilli(123456)
val sqlDateTime: Timestamp = new Timestamp(instant.toEpochMilli)
assertEquals(DateTimeUtils.toSqlTimestamp(instant), sqlDateTime)
Expand Down
Loading