Skip to content

Commit 10cf7fb

Browse files
committed
Port TestValueRange to scalatest
1 parent 6532404 commit 10cf7fb

File tree

2 files changed

+136
-69
lines changed

2 files changed

+136
-69
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.temporal
33+
34+
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}
35+
36+
import org.scalatest.FunSuite
37+
import org.threeten.bp.{AbstractTest, AssertionsHelper}
38+
39+
/** Test. */
40+
class TestValueRangeSerialization extends FunSuite with AssertionsHelper {
41+
ignore("immutable") {
42+
AbstractTest.assertImmutable(classOf[ValueRange])
43+
}
44+
45+
test("serialization") {
46+
val obj: AnyRef = ValueRange.of(1, 2, 3, 4)
47+
val baos: ByteArrayOutputStream = new ByteArrayOutputStream
48+
val oos: ObjectOutputStream = new ObjectOutputStream(baos)
49+
oos.writeObject(obj)
50+
oos.close()
51+
val ois: ObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray))
52+
assertEquals(ois.readObject, obj)
53+
}
54+
55+
}

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

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,13 @@
3131
*/
3232
package org.threeten.bp.temporal
3333

34-
import org.testng.Assert.assertEquals
35-
import java.io.ByteArrayInputStream
36-
import java.io.ByteArrayOutputStream
37-
import java.io.ObjectInputStream
38-
import java.io.ObjectOutputStream
39-
import org.testng.SkipException
40-
import org.testng.annotations.DataProvider
41-
import org.testng.annotations.Test
42-
import org.threeten.bp.AbstractTest
34+
import org.scalatest.FunSuite
35+
import org.threeten.bp.AssertionsHelper
4336

4437
/** Test. */
45-
@Test class TestValueRange {
46-
@Test def test_immutable(): Unit = {
47-
throw new SkipException("private constructor shows up public due to companion object")
48-
AbstractTest.assertImmutable(classOf[ValueRange])
49-
}
50-
51-
@throws(classOf[Exception])
52-
def test_serialization(): Unit = {
53-
val obj: AnyRef = ValueRange.of(1, 2, 3, 4)
54-
val baos: ByteArrayOutputStream = new ByteArrayOutputStream
55-
val oos: ObjectOutputStream = new ObjectOutputStream(baos)
56-
oos.writeObject(obj)
57-
oos.close()
58-
val ois: ObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray))
59-
assertEquals(ois.readObject, obj)
60-
}
38+
class TestValueRange extends FunSuite with AssertionsHelper {
6139

62-
def test_of_longlong(): Unit = {
40+
test("of_longlong") {
6341
val test: ValueRange = ValueRange.of(1, 12)
6442
assertEquals(test.getMinimum, 1)
6543
assertEquals(test.getLargestMinimum, 1)
@@ -69,7 +47,7 @@ import org.threeten.bp.AbstractTest
6947
assertEquals(test.isIntValue, true)
7048
}
7149

72-
def test_of_longlong_big(): Unit = {
50+
test("of_longlong_big") {
7351
val test: ValueRange = ValueRange.of(1, 123456789012345L)
7452
assertEquals(test.getMinimum, 1)
7553
assertEquals(test.getLargestMinimum, 1)
@@ -79,11 +57,13 @@ import org.threeten.bp.AbstractTest
7957
assertEquals(test.isIntValue, false)
8058
}
8159

82-
@Test(expectedExceptions = Array(classOf[IllegalArgumentException])) def test_of_longlong_minGtMax(): Unit = {
83-
ValueRange.of(12, 1)
60+
test("of_longlong_minGtMax") {
61+
assertThrows[IllegalArgumentException] {
62+
ValueRange.of(12, 1)
63+
}
8464
}
8565

86-
def test_of_longlonglong(): Unit = {
66+
test("of_longlonglong") {
8767
val test: ValueRange = ValueRange.of(1, 28, 31)
8868
assertEquals(test.getMinimum, 1)
8969
assertEquals(test.getLargestMinimum, 1)
@@ -93,37 +73,69 @@ import org.threeten.bp.AbstractTest
9373
assertEquals(test.isIntValue, true)
9474
}
9575

96-
@Test(expectedExceptions = Array(classOf[IllegalArgumentException])) def test_of_longlonglong_minGtMax(): Unit = {
97-
ValueRange.of(12, 1, 2)
98-
}
99-
100-
@Test(expectedExceptions = Array(classOf[IllegalArgumentException])) def test_of_longlonglong_smallestmaxminGtMax(): Unit = {
101-
ValueRange.of(1, 31, 28)
102-
}
103-
104-
@DataProvider(name = "valid") private[temporal] def data_valid: Array[Array[Any]] = {
105-
Array[Array[Any]](Array(1, 1, 1, 1), Array(1, 1, 1, 2), Array(1, 1, 2, 2), Array(1, 2, 3, 4), Array(1, 1, 28, 31), Array(1, 3, 31, 31), Array(-5, -4, -3, -2), Array(-5, -4, 3, 4), Array(1, 20, 10, 31))
106-
}
107-
108-
@Test(dataProvider = "valid") def test_of_longlonglonglong(sMin: Long, lMin: Long, sMax: Long, lMax: Long): Unit = {
109-
val test: ValueRange = ValueRange.of(sMin, lMin, sMax, lMax)
110-
assertEquals(test.getMinimum, sMin)
111-
assertEquals(test.getLargestMinimum, lMin)
112-
assertEquals(test.getSmallestMaximum, sMax)
113-
assertEquals(test.getMaximum, lMax)
114-
assertEquals(test.isFixed, sMin == lMin && sMax == lMax)
115-
assertEquals(test.isIntValue, true)
116-
}
117-
118-
@DataProvider(name = "invalid") private[temporal] def data_invalid: Array[Array[Any]] = {
119-
Array[Array[Any]](Array(1, 2, 31, 28), Array(1, 31, 2, 28), Array(31, 2, 1, 28), Array(31, 2, 3, 28), Array(2, 1, 28, 31), Array(2, 1, 31, 28), Array(12, 13, 1, 2))
120-
}
121-
122-
@Test(dataProvider = "invalid", expectedExceptions = Array(classOf[IllegalArgumentException])) def test_of_longlonglonglong_invalid(sMin: Long, lMin: Long, sMax: Long, lMax: Long): Unit = {
123-
ValueRange.of(sMin, lMin, sMax, lMax)
124-
}
125-
126-
def test_isValidValue_long(): Unit = {
76+
test("of_longlonglong_minGtMax") {
77+
assertThrows[IllegalArgumentException] {
78+
ValueRange.of(12, 1, 2)
79+
}
80+
}
81+
82+
test("of_longlonglong_smallestmaxminGtMax") {
83+
assertThrows[IllegalArgumentException] {
84+
ValueRange.of(1, 31, 28)
85+
}
86+
}
87+
88+
def data_valid: List[List[Int]] = {
89+
List(
90+
List(1, 1, 1, 1),
91+
List(1, 1, 1, 2),
92+
List(1, 1, 2, 2),
93+
List(1, 2, 3, 4),
94+
List(1, 1, 28, 31),
95+
List(1, 3, 31, 31),
96+
List(-5, -4, -3, -2),
97+
List(-5, -4, 3, 4),
98+
List(1, 20, 10, 31))
99+
}
100+
101+
test("of_longlonglonglong") {
102+
data_valid.foreach {
103+
case sMin :: lMin :: sMax :: lMax :: Nil =>
104+
val test: ValueRange = ValueRange.of(sMin, lMin, sMax, lMax)
105+
assertEquals(test.getMinimum, sMin)
106+
assertEquals(test.getLargestMinimum, lMin)
107+
assertEquals(test.getSmallestMaximum, sMax)
108+
assertEquals(test.getMaximum, lMax)
109+
assertEquals(test.isFixed, sMin == lMin && sMax == lMax)
110+
assertEquals(test.isIntValue, true)
111+
case _ =>
112+
fail()
113+
}
114+
}
115+
116+
def data_invalid: List[List[Int]] = {
117+
List(
118+
List(1, 2, 31, 28),
119+
List(1, 31, 2, 28),
120+
List(31, 2, 1, 28),
121+
List(31, 2, 3, 28),
122+
List(2, 1, 28, 31),
123+
List(2, 1, 31, 28),
124+
List(12, 13, 1, 2))
125+
}
126+
127+
test("of_longlonglonglong_invalid") {
128+
data_invalid.foreach {
129+
case sMin :: lMin :: sMax :: lMax :: Nil =>
130+
assertThrows[IllegalArgumentException] {
131+
ValueRange.of(sMin, lMin, sMax, lMax)
132+
}
133+
case _ =>
134+
fail()
135+
}
136+
}
137+
138+
test("isValidValue_long") {
127139
val test: ValueRange = ValueRange.of(1, 28, 31)
128140
assertEquals(test.isValidValue(0), false)
129141
assertEquals(test.isValidValue(1), true)
@@ -133,23 +145,23 @@ import org.threeten.bp.AbstractTest
133145
assertEquals(test.isValidValue(32), false)
134146
}
135147

136-
def test_isValidValue_long_int(): Unit = {
148+
test("isValidValue_long_int") {
137149
val test: ValueRange = ValueRange.of(1, 28, 31)
138150
assertEquals(test.isValidValue(0), false)
139151
assertEquals(test.isValidValue(1), true)
140152
assertEquals(test.isValidValue(31), true)
141153
assertEquals(test.isValidValue(32), false)
142154
}
143155

144-
def test_isValidValue_long_long(): Unit = {
156+
test("isValidValue_long_long") {
145157
val test: ValueRange = ValueRange.of(1, 28, Int.MaxValue + 1L)
146158
assertEquals(test.isValidIntValue(0), false)
147159
assertEquals(test.isValidIntValue(1), false)
148160
assertEquals(test.isValidIntValue(31), false)
149161
assertEquals(test.isValidIntValue(32), false)
150162
}
151163

152-
def test_equals1(): Unit = {
164+
test("equals1") {
153165
val a: ValueRange = ValueRange.of(1, 2, 3, 4)
154166
val b: ValueRange = ValueRange.of(1, 2, 3, 4)
155167
assertEquals(a == a, true)
@@ -159,25 +171,25 @@ import org.threeten.bp.AbstractTest
159171
assertEquals(a.hashCode == b.hashCode, true)
160172
}
161173

162-
def test_equals2(): Unit = {
174+
test("equals2") {
163175
val a: ValueRange = ValueRange.of(1, 2, 3, 4)
164176
assertEquals(a == ValueRange.of(0, 2, 3, 4), false)
165177
assertEquals(a == ValueRange.of(1, 3, 3, 4), false)
166178
assertEquals(a == ValueRange.of(1, 2, 4, 4), false)
167179
assertEquals(a == ValueRange.of(1, 2, 3, 5), false)
168180
}
169181

170-
def test_equals_otherType(): Unit = {
182+
test("equals_otherType") {
171183
val a: ValueRange = ValueRange.of(1, 12)
172-
assertEquals(a == "Rubbish", false)
184+
assertNotEquals(a, "Rubbish")
173185
}
174186

175-
def test_equals_null(): Unit = {
187+
test("equals_null") {
176188
val a: ValueRange = ValueRange.of(1, 12)
177189
assertEquals(a == null, false)
178190
}
179191

180-
def test_toString(): Unit = {
192+
test("toString") {
181193
assertEquals(ValueRange.of(1, 1, 4, 4).toString, "1 - 4")
182194
assertEquals(ValueRange.of(1, 1, 3, 4).toString, "1 - 3/4")
183195
assertEquals(ValueRange.of(1, 2, 3, 4).toString, "1/2 - 3/4")

0 commit comments

Comments
 (0)