31
31
*/
32
32
package org .threeten .bp .temporal
33
33
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
43
36
44
37
/** 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 {
61
39
62
- def test_of_longlong () : Unit = {
40
+ test( " of_longlong " ) {
63
41
val test : ValueRange = ValueRange .of(1 , 12 )
64
42
assertEquals(test.getMinimum, 1 )
65
43
assertEquals(test.getLargestMinimum, 1 )
@@ -69,7 +47,7 @@ import org.threeten.bp.AbstractTest
69
47
assertEquals(test.isIntValue, true )
70
48
}
71
49
72
- def test_of_longlong_big () : Unit = {
50
+ test( " of_longlong_big " ) {
73
51
val test : ValueRange = ValueRange .of(1 , 123456789012345L )
74
52
assertEquals(test.getMinimum, 1 )
75
53
assertEquals(test.getLargestMinimum, 1 )
@@ -79,11 +57,13 @@ import org.threeten.bp.AbstractTest
79
57
assertEquals(test.isIntValue, false )
80
58
}
81
59
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
+ }
84
64
}
85
65
86
- def test_of_longlonglong () : Unit = {
66
+ test( " of_longlonglong " ) {
87
67
val test : ValueRange = ValueRange .of(1 , 28 , 31 )
88
68
assertEquals(test.getMinimum, 1 )
89
69
assertEquals(test.getLargestMinimum, 1 )
@@ -93,37 +73,69 @@ import org.threeten.bp.AbstractTest
93
73
assertEquals(test.isIntValue, true )
94
74
}
95
75
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" ) {
127
139
val test : ValueRange = ValueRange .of(1 , 28 , 31 )
128
140
assertEquals(test.isValidValue(0 ), false )
129
141
assertEquals(test.isValidValue(1 ), true )
@@ -133,23 +145,23 @@ import org.threeten.bp.AbstractTest
133
145
assertEquals(test.isValidValue(32 ), false )
134
146
}
135
147
136
- def test_isValidValue_long_int () : Unit = {
148
+ test( " isValidValue_long_int " ) {
137
149
val test : ValueRange = ValueRange .of(1 , 28 , 31 )
138
150
assertEquals(test.isValidValue(0 ), false )
139
151
assertEquals(test.isValidValue(1 ), true )
140
152
assertEquals(test.isValidValue(31 ), true )
141
153
assertEquals(test.isValidValue(32 ), false )
142
154
}
143
155
144
- def test_isValidValue_long_long () : Unit = {
156
+ test( " isValidValue_long_long " ) {
145
157
val test : ValueRange = ValueRange .of(1 , 28 , Int .MaxValue + 1L )
146
158
assertEquals(test.isValidIntValue(0 ), false )
147
159
assertEquals(test.isValidIntValue(1 ), false )
148
160
assertEquals(test.isValidIntValue(31 ), false )
149
161
assertEquals(test.isValidIntValue(32 ), false )
150
162
}
151
163
152
- def test_equals1 () : Unit = {
164
+ test( " equals1 " ) {
153
165
val a : ValueRange = ValueRange .of(1 , 2 , 3 , 4 )
154
166
val b : ValueRange = ValueRange .of(1 , 2 , 3 , 4 )
155
167
assertEquals(a == a, true )
@@ -159,25 +171,25 @@ import org.threeten.bp.AbstractTest
159
171
assertEquals(a.hashCode == b.hashCode, true )
160
172
}
161
173
162
- def test_equals2 () : Unit = {
174
+ test( " equals2 " ) {
163
175
val a : ValueRange = ValueRange .of(1 , 2 , 3 , 4 )
164
176
assertEquals(a == ValueRange .of(0 , 2 , 3 , 4 ), false )
165
177
assertEquals(a == ValueRange .of(1 , 3 , 3 , 4 ), false )
166
178
assertEquals(a == ValueRange .of(1 , 2 , 4 , 4 ), false )
167
179
assertEquals(a == ValueRange .of(1 , 2 , 3 , 5 ), false )
168
180
}
169
181
170
- def test_equals_otherType () : Unit = {
182
+ test( " equals_otherType " ) {
171
183
val a : ValueRange = ValueRange .of(1 , 12 )
172
- assertEquals(a == " Rubbish" , false )
184
+ assertNotEquals(a, " Rubbish" )
173
185
}
174
186
175
- def test_equals_null () : Unit = {
187
+ test( " equals_null " ) {
176
188
val a : ValueRange = ValueRange .of(1 , 12 )
177
189
assertEquals(a == null , false )
178
190
}
179
191
180
- def test_toString () : Unit = {
192
+ test( " toString " ) {
181
193
assertEquals(ValueRange .of(1 , 1 , 4 , 4 ).toString, " 1 - 4" )
182
194
assertEquals(ValueRange .of(1 , 1 , 3 , 4 ).toString, " 1 - 3/4" )
183
195
assertEquals(ValueRange .of(1 , 2 , 3 , 4 ).toString, " 1/2 - 3/4" )
0 commit comments