Skip to content

Commit 7347457

Browse files
committed
Port of TestDateTimeTextPrinting to scalatest
1 parent b31f7f6 commit 7347457

File tree

1 file changed

+71
-45
lines changed

1 file changed

+71
-45
lines changed

jvm/src/test/scala/org/threeten/bp/format/TestDateTimeTextPrinting.scala renamed to shared/src/test/scala/org/threeten/bp/format/TestDateTimeTextPrinting.scala

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,73 +31,103 @@
3131
*/
3232
package org.threeten.bp.format
3333

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
3834
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}
4439
import org.threeten.bp.temporal.TemporalField
4540

4641
/** Test text printing. */
47-
@Test class TestDateTimeTextPrinting {
42+
class TestDateTimeTextPrinting extends FunSuite with AssertionsHelper with BeforeAndAfter {
4843
private var builder: DateTimeFormatterBuilder = null
4944

50-
@BeforeMethod def setUp(): Unit = {
45+
before {
5146
builder = new DateTimeFormatterBuilder
5247
}
5348

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"))
5683
}
5784

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+
}
6698
}
6799

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()
77113
}
78114
}
79115

80-
@Test
81-
@throws(classOf[Exception])
82-
def test_print_appendText2arg_french_long(): Unit = {
116+
test("print_appendText2arg_french_long") {
83117
val f: DateTimeFormatter = builder.appendText(MONTH_OF_YEAR, TextStyle.FULL).toFormatter(Locale.FRENCH)
84118
val dt: LocalDateTime = LocalDateTime.of(2010, 1, 1, 0, 0)
85119
val text: String = f.format(dt)
86120
assertEquals(text, "janvier")
87121
}
88122

89-
@Test
90-
@throws(classOf[Exception])
91-
def test_print_appendText2arg_french_short(): Unit = {
123+
test("print_appendText2arg_french_short") {
92124
val f: DateTimeFormatter = builder.appendText(MONTH_OF_YEAR, TextStyle.SHORT).toFormatter(Locale.FRENCH)
93125
val dt: LocalDateTime = LocalDateTime.of(2010, 1, 1, 0, 0)
94126
val text: String = f.format(dt)
95127
assertEquals(text, "janv.")
96128
}
97129

98-
@Test
99-
@throws(classOf[Exception])
100-
def test_appendTextMap(): Unit = {
130+
test("appendTextMap") {
101131
val map: java.util.Map[Long, String] = new java.util.HashMap[Long, String]
102132
map.put(1L, "JNY")
103133
map.put(2L, "FBY")
@@ -119,9 +149,7 @@ import org.threeten.bp.temporal.TemporalField
119149
}
120150
}
121151

122-
@Test
123-
@throws(classOf[Exception])
124-
def test_appendTextMap_DOM(): Unit = {
152+
test("appendTextMap_DOM") {
125153
val map: java.util.Map[Long, String] = new java.util.HashMap[Long, String]
126154
map.put(1L, "1st")
127155
map.put(2L, "2nd")
@@ -134,9 +162,7 @@ import org.threeten.bp.temporal.TemporalField
134162
assertEquals(f.format(dt.withDayOfMonth(3)), "3rd")
135163
}
136164

137-
@Test
138-
@throws(classOf[Exception])
139-
def test_appendTextMapIncomplete(): Unit = {
165+
test("appendTextMapIncomplete") {
140166
val map: java.util.Map[Long, String] = new java.util.HashMap[Long, String]
141167
map.put(1L, "JNY")
142168
builder.appendText(MONTH_OF_YEAR, map)

0 commit comments

Comments
 (0)