31
31
*/
32
32
package org .threeten .bp .format
33
33
34
- import org .testng .Assert .assertEquals
35
- import org .threeten .bp .temporal .ChronoField .DAY_OF_MONTH
36
- import org .threeten .bp .temporal .ChronoField .DAY_OF_WEEK
37
- import org .threeten .bp .temporal .ChronoField .MONTH_OF_YEAR
38
34
import java .util .Locale
39
- import org .testng .annotations .BeforeMethod
40
- import org .testng .annotations .DataProvider
41
- import org .testng .annotations .Test
42
- import org .threeten .bp .LocalDateTime
43
- import org .threeten .bp .Month
35
+
36
+ import org .scalatest .{BeforeAndAfter , FunSuite }
37
+ import org .threeten .bp .{AssertionsHelper , LocalDateTime , Month }
38
+ import org .threeten .bp .temporal .ChronoField .{DAY_OF_MONTH , DAY_OF_WEEK , MONTH_OF_YEAR }
44
39
import org .threeten .bp .temporal .TemporalField
45
40
46
41
/** Test text printing. */
47
- @ Test class TestDateTimeTextPrinting {
42
+ class TestDateTimeTextPrinting extends FunSuite with AssertionsHelper with BeforeAndAfter {
48
43
private var builder : DateTimeFormatterBuilder = null
49
44
50
- @ BeforeMethod def setUp () : Unit = {
45
+ before {
51
46
builder = new DateTimeFormatterBuilder
52
47
}
53
48
54
- @ DataProvider (name = " printText" ) private [format] def data_text : Array [Array [Any ]] = {
55
- Array[Array[Any]](Array(DAY_OF_WEEK, TextStyle.FULL, 1, "Monday"), Array(DAY_OF_WEEK, TextStyle.FULL, 2, "Tuesday"), Array(DAY_OF_WEEK, TextStyle.FULL, 3, "Wednesday"), Array(DAY_OF_WEEK, TextStyle.FULL, 4, "Thursday"), Array(DAY_OF_WEEK, TextStyle.FULL, 5, "Friday"), Array(DAY_OF_WEEK, TextStyle.FULL, 6, "Saturday"), Array(DAY_OF_WEEK, TextStyle.FULL, 7, "Sunday"), Array(DAY_OF_WEEK, TextStyle.SHORT, 1, "Mon"), Array(DAY_OF_WEEK, TextStyle.SHORT, 2, "Tue"), Array(DAY_OF_WEEK, TextStyle.SHORT, 3, "Wed"), Array(DAY_OF_WEEK, TextStyle.SHORT, 4, "Thu"), Array(DAY_OF_WEEK, TextStyle.SHORT, 5, "Fri"), Array(DAY_OF_WEEK, TextStyle.SHORT, 6, "Sat"), Array(DAY_OF_WEEK, TextStyle.SHORT, 7, "Sun"), Array(DAY_OF_MONTH, TextStyle.FULL, 1, "1"), Array(DAY_OF_MONTH, TextStyle.FULL, 2, "2"), Array(DAY_OF_MONTH, TextStyle.FULL, 3, "3"), Array(DAY_OF_MONTH, TextStyle.FULL, 28, "28"), Array(DAY_OF_MONTH, TextStyle.FULL, 29, "29"), Array(DAY_OF_MONTH, TextStyle.FULL, 30, "30"), Array(DAY_OF_MONTH, TextStyle.FULL, 31, "31"), Array(DAY_OF_MONTH, TextStyle.SHORT, 1, "1"), Array(DAY_OF_MONTH, TextStyle.SHORT, 2, "2"), Array(DAY_OF_MONTH, TextStyle.SHORT, 3, "3"), Array(DAY_OF_MONTH, TextStyle.SHORT, 28, "28"), Array(DAY_OF_MONTH, TextStyle.SHORT, 29, "29"), Array(DAY_OF_MONTH, TextStyle.SHORT, 30, "30"), Array(DAY_OF_MONTH, TextStyle.SHORT, 31, "31"), Array(MONTH_OF_YEAR, TextStyle.FULL, 1, "January"), Array(MONTH_OF_YEAR, TextStyle.FULL, 12, "December"), Array(MONTH_OF_YEAR, TextStyle.SHORT, 1, "Jan"), Array(MONTH_OF_YEAR, TextStyle.SHORT, 12, "Dec"))
49
+ def data_text : List [List [Any ]] = {
50
+ List (
51
+ List (DAY_OF_WEEK , TextStyle .FULL , 1 , " Monday" ),
52
+ List (DAY_OF_WEEK , TextStyle .FULL , 2 , " Tuesday" ),
53
+ List (DAY_OF_WEEK , TextStyle .FULL , 3 , " Wednesday" ),
54
+ List (DAY_OF_WEEK , TextStyle .FULL , 4 , " Thursday" ),
55
+ List (DAY_OF_WEEK , TextStyle .FULL , 5 , " Friday" ),
56
+ List (DAY_OF_WEEK , TextStyle .FULL , 6 , " Saturday" ),
57
+ List (DAY_OF_WEEK , TextStyle .FULL , 7 , " Sunday" ),
58
+ List (DAY_OF_WEEK , TextStyle .SHORT , 1 , " Mon" ),
59
+ List (DAY_OF_WEEK , TextStyle .SHORT , 2 , " Tue" ),
60
+ List (DAY_OF_WEEK , TextStyle .SHORT , 3 , " Wed" ),
61
+ List (DAY_OF_WEEK , TextStyle .SHORT , 4 , " Thu" ),
62
+ List (DAY_OF_WEEK , TextStyle .SHORT , 5 , " Fri" ),
63
+ List (DAY_OF_WEEK , TextStyle .SHORT , 6 , " Sat" ),
64
+ List (DAY_OF_WEEK , TextStyle .SHORT , 7 , " Sun" ),
65
+ List (DAY_OF_MONTH , TextStyle .FULL , 1 , " 1" ),
66
+ List (DAY_OF_MONTH , TextStyle .FULL , 2 , " 2" ),
67
+ List (DAY_OF_MONTH , TextStyle .FULL , 3 , " 3" ),
68
+ List (DAY_OF_MONTH , TextStyle .FULL , 28 , " 28" ),
69
+ List (DAY_OF_MONTH , TextStyle .FULL , 29 , " 29" ),
70
+ List (DAY_OF_MONTH , TextStyle .FULL , 30 , " 30" ),
71
+ List (DAY_OF_MONTH , TextStyle .FULL , 31 , " 31" ),
72
+ List (DAY_OF_MONTH , TextStyle .SHORT , 1 , " 1" ),
73
+ List (DAY_OF_MONTH , TextStyle .SHORT , 2 , " 2" ),
74
+ List (DAY_OF_MONTH , TextStyle .SHORT , 3 , " 3" ),
75
+ List (DAY_OF_MONTH , TextStyle .SHORT , 28 , " 28" ),
76
+ List (DAY_OF_MONTH , TextStyle .SHORT , 29 , " 29" ),
77
+ List (DAY_OF_MONTH , TextStyle .SHORT , 30 , " 30" ),
78
+ List (DAY_OF_MONTH , TextStyle .SHORT , 31 , " 31" ),
79
+ List (MONTH_OF_YEAR , TextStyle .FULL , 1 , " January" ),
80
+ List (MONTH_OF_YEAR , TextStyle .FULL , 12 , " December" ),
81
+ List (MONTH_OF_YEAR , TextStyle .SHORT , 1 , " Jan" ),
82
+ List (MONTH_OF_YEAR , TextStyle .SHORT , 12 , " Dec" ))
56
83
}
57
84
58
- @ Test (dataProvider = " printText" )
59
- @ throws(classOf [Exception ])
60
- def test_appendText2arg_print (field : TemporalField , style : TextStyle , value : Int , expected : String ): Unit = {
61
- val f : DateTimeFormatter = builder.appendText(field, style).toFormatter(Locale .ENGLISH )
62
- var dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
63
- dt = dt.`with`(field, value)
64
- val text : String = f.format(dt)
65
- assertEquals(text, expected)
85
+ test(" appendText2arg_print" ) {
86
+ data_text.foreach {
87
+ case (field : TemporalField ) :: (style : TextStyle ) :: (value : Int ) :: (expected : String ) :: Nil =>
88
+ val builder = new DateTimeFormatterBuilder
89
+ val f : DateTimeFormatter = builder.appendText(field, style).toFormatter(Locale .ENGLISH )
90
+ var dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
91
+ dt = dt.`with`(field, value)
92
+ val text : String = f.format(dt)
93
+ println(text)
94
+ assertEquals(text, expected)
95
+ case _ =>
96
+ fail()
97
+ }
66
98
}
67
99
68
- @ Test (dataProvider = " printText" )
69
- @ throws(classOf [Exception ])
70
- def test_appendText1arg_print (field : TemporalField , style : TextStyle , value : Int , expected : String ): Unit = {
71
- if (style eq TextStyle .FULL ) {
72
- val f : DateTimeFormatter = builder.appendText(field).toFormatter(Locale .ENGLISH )
73
- var dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
74
- dt = dt.`with`(field, value)
75
- val text : String = f.format(dt)
76
- assertEquals(text, expected)
100
+ test(" appendText1arg_print" ) {
101
+ data_text.foreach {
102
+ case (field : TemporalField ) :: (style : TextStyle ) :: (value : Int ) :: (expected : String ) :: Nil =>
103
+ if (style eq TextStyle .FULL ) {
104
+ val builder = new DateTimeFormatterBuilder
105
+ val f : DateTimeFormatter = builder.appendText(field).toFormatter(Locale .ENGLISH )
106
+ var dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
107
+ dt = dt.`with`(field, value)
108
+ val text : String = f.format(dt)
109
+ assertEquals(text, expected)
110
+ }
111
+ case _ =>
112
+ fail()
77
113
}
78
114
}
79
115
80
- @ Test
81
- @ throws(classOf [Exception ])
82
- def test_print_appendText2arg_french_long (): Unit = {
116
+ test(" print_appendText2arg_french_long" ) {
83
117
val f : DateTimeFormatter = builder.appendText(MONTH_OF_YEAR , TextStyle .FULL ).toFormatter(Locale .FRENCH )
84
118
val dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
85
119
val text : String = f.format(dt)
86
120
assertEquals(text, " janvier" )
87
121
}
88
122
89
- @ Test
90
- @ throws(classOf [Exception ])
91
- def test_print_appendText2arg_french_short (): Unit = {
123
+ test(" print_appendText2arg_french_short" ) {
92
124
val f : DateTimeFormatter = builder.appendText(MONTH_OF_YEAR , TextStyle .SHORT ).toFormatter(Locale .FRENCH )
93
125
val dt : LocalDateTime = LocalDateTime .of(2010 , 1 , 1 , 0 , 0 )
94
126
val text : String = f.format(dt)
95
127
assertEquals(text, " janv." )
96
128
}
97
129
98
- @ Test
99
- @ throws(classOf [Exception ])
100
- def test_appendTextMap (): Unit = {
130
+ test(" appendTextMap" ) {
101
131
val map : java.util.Map [Long , String ] = new java.util.HashMap [Long , String ]
102
132
map.put(1L , " JNY" )
103
133
map.put(2L , " FBY" )
@@ -119,9 +149,7 @@ import org.threeten.bp.temporal.TemporalField
119
149
}
120
150
}
121
151
122
- @ Test
123
- @ throws(classOf [Exception ])
124
- def test_appendTextMap_DOM (): Unit = {
152
+ test(" appendTextMap_DOM" ) {
125
153
val map : java.util.Map [Long , String ] = new java.util.HashMap [Long , String ]
126
154
map.put(1L , " 1st" )
127
155
map.put(2L , " 2nd" )
@@ -134,9 +162,7 @@ import org.threeten.bp.temporal.TemporalField
134
162
assertEquals(f.format(dt.withDayOfMonth(3 )), " 3rd" )
135
163
}
136
164
137
- @ Test
138
- @ throws(classOf [Exception ])
139
- def test_appendTextMapIncomplete (): Unit = {
165
+ test(" appendTextMapIncomplete" ) {
140
166
val map : java.util.Map [Long , String ] = new java.util.HashMap [Long , String ]
141
167
map.put(1L , " JNY" )
142
168
builder.appendText(MONTH_OF_YEAR , map)
0 commit comments