Skip to content

Commit e696f2b

Browse files
committed
Integrate scalatest and port TestInstant
1 parent 492575f commit e696f2b

File tree

6 files changed

+1124
-718
lines changed

6 files changed

+1124
-718
lines changed

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ lazy val commonSettings = Seq(
2828
Some("releases" at nexus + "service/local/staging/deploy/maven2")
2929
},
3030
pomExtra := pomData,
31-
pomIncludeRepository := { _ => false }
31+
pomIncludeRepository := { _ => false },
32+
libraryDependencies ++= Seq(
33+
"org.scalatest" %%% "scalatest" % "3.0.1" % "test"
34+
)
3235
)
3336

3437
lazy val root = project.in(file("."))

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

Lines changed: 0 additions & 717 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of JSR-310 nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package org.threeten.bp
33+
34+
import org.scalatest.FunSuite
35+
36+
class TestInstantSerialization extends FunSuite with AssertionsHelper {
37+
38+
test("serialization") {
39+
AbstractTest.assertSerializable(Instant.ofEpochMilli(134l))
40+
}
41+
42+
test("serialization_format") {
43+
AbstractTest.assertEqualsSerialisedForm(Instant.ofEpochMilli(1347830279338l))
44+
}
45+
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.threeten.bp
2+
3+
import org.scalactic.{Prettifier, source}
4+
import org.scalatest.Assertion
5+
import org.scalatest.FunSuite
6+
7+
/**
8+
* Helper methods to avoid rewriting much of the TestNG tests
9+
*/
10+
trait AssertionsHelper { this: FunSuite =>
11+
def assertEquals[A, B](o1: A, o2: B, msg: String)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
12+
assertEquals(o1, o2)
13+
14+
def assertEquals[A, B](o1: A, o2: B)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
15+
assert(o1 == o2)
16+
17+
def assertNotEquals[A, B](o1: A, o2: B)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
18+
assert(o1 != o2)
19+
20+
def assertFalse(b: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
21+
assert(!b)
22+
23+
def assertTrue(b: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
24+
assert(b)
25+
26+
def assertNull[A](a: A)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
27+
assert(a == null)
28+
29+
def assertNotNull[A](a: A)(implicit prettifier: Prettifier, pos: source.Position): Assertion =
30+
assert(a != null)
31+
32+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of JSR-310 nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package org.threeten.bp
33+
34+
import org.scalatest.FunSuite
35+
import org.threeten.bp.temporal.{TemporalAccessor, TemporalField, TemporalQuery}
36+
37+
/** Base test class for {@code DateTime}. */
38+
trait GenDateTimeTest extends FunSuite with AssertionsHelper {
39+
/** Sample {@code DateTime} objects.
40+
*
41+
* @return the objects, not null
42+
*/
43+
protected def samples: java.util.List[TemporalAccessor]
44+
45+
/** List of valid supported fields.
46+
*
47+
* @return the fields, not null
48+
*/
49+
protected def validFields: java.util.List[TemporalField]
50+
51+
/** List of invalid unsupported fields.
52+
*
53+
* @return the fields, not null
54+
*/
55+
protected def invalidFields: java.util.List[TemporalField]
56+
57+
test("basicTest_isSupported_DateTimeField_supported") {
58+
import scala.collection.JavaConversions._
59+
for (sample <- samples) {
60+
import scala.collection.JavaConversions._
61+
for (field <- validFields) {
62+
assertEquals(sample.isSupported(field), true, "Failed on " + sample + " " + field)
63+
}
64+
}
65+
}
66+
67+
test("basicTest_isSupported_DateTimeField_unsupported") {
68+
import scala.collection.JavaConversions._
69+
for (sample <- samples) {
70+
import scala.collection.JavaConversions._
71+
for (field <- invalidFields) {
72+
assertEquals(sample.isSupported(field), false, "Failed on " + sample + " " + field)
73+
}
74+
}
75+
}
76+
77+
test("basicTest_isSupported_DateTimeField_null") {
78+
import scala.collection.JavaConversions._
79+
for (sample <- samples) {
80+
assertEquals(sample.isSupported(null), false, "Failed on " + sample)
81+
}
82+
}
83+
84+
test("basicTest_range_DateTimeField_unsupported") {
85+
import scala.collection.JavaConversions._
86+
for (sample <- samples) {
87+
import scala.collection.JavaConversions._
88+
for (field <- invalidFields) {
89+
try {
90+
sample.range(field)
91+
fail("Failed on " + sample + " " + field)
92+
}
93+
catch {
94+
case ex: DateTimeException =>
95+
}
96+
}
97+
}
98+
}
99+
100+
test("basicTest_range_DateTimeField_null") {
101+
import scala.collection.JavaConversions._
102+
for (sample <- samples) {
103+
try {
104+
sample.range(null)
105+
fail("Failed on " + sample)
106+
}
107+
catch {
108+
case ex: NullPointerException =>
109+
}
110+
}
111+
}
112+
113+
test("basicTest_get_DateTimeField_unsupported") {
114+
import scala.collection.JavaConversions._
115+
for (sample <- samples) {
116+
import scala.collection.JavaConversions._
117+
for (field <- invalidFields) {
118+
try {
119+
sample.get(field)
120+
fail("Failed on " + sample + " " + field)
121+
}
122+
catch {
123+
case ex: DateTimeException =>
124+
}
125+
}
126+
}
127+
}
128+
129+
test("basicTest_get_DateTimeField_null") {
130+
import scala.collection.JavaConversions._
131+
for (sample <- samples) {
132+
try {
133+
sample.get(null)
134+
fail("Failed on " + sample)
135+
}
136+
catch {
137+
case ex: NullPointerException =>
138+
}
139+
}
140+
}
141+
142+
test("basicTest_getLong_DateTimeField_unsupported") {
143+
import scala.collection.JavaConversions._
144+
for (sample <- samples) {
145+
import scala.collection.JavaConversions._
146+
for (field <- invalidFields) {
147+
try {
148+
sample.getLong(field)
149+
fail("Failed on " + sample + " " + field)
150+
}
151+
catch {
152+
case ex: DateTimeException =>
153+
}
154+
}
155+
}
156+
}
157+
158+
test("basicTest_getLong_DateTimeField_null") {
159+
import scala.collection.JavaConversions._
160+
for (sample <- samples) {
161+
try {
162+
sample.getLong(null)
163+
fail("Failed on " + sample)
164+
}
165+
catch {
166+
case ex: NullPointerException =>
167+
}
168+
}
169+
}
170+
171+
test("basicTest_query") {
172+
import scala.collection.JavaConversions._
173+
for (sample <- samples) {
174+
assertEquals(sample.query(new TemporalQuery[String] {
175+
override def queryFrom(temporal: TemporalAccessor): String = "foo"
176+
}), "foo")
177+
}
178+
}
179+
}

0 commit comments

Comments
 (0)