Skip to content

Commit dfb061a

Browse files
committed
Use assertFailsWith
1 parent 5ea5c47 commit dfb061a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/common/test/format/DateTimeComponentsFormatTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ class DateTimeComponentsFormatTest {
236236
offset(UtcOffset.Formats.ISO)
237237
}
238238
for (index in fields.indices) {
239-
try {
239+
val propertyName = fields[index].property.name
240+
assertFailsWith<IllegalStateException>("No error if the field $propertyName is unset") {
240241
formatWithEverything.format {
241242
for (i in fields.indices) {
242243
if (i != index) fields[i].set(this)
243244
}
244245
}
245-
fail("No error if the field ${fields[index].property.name} is unset")
246-
} catch (e: IllegalStateException) {
247-
assertTrue(e.message!!.contains(fields[index].property.name), "Error message '$e' does not contain ${fields[index].property.name}")
246+
}.let {
247+
assertTrue(it.message!!.contains(fields[index].property.name), "Error message '$e' does not contain $propertyName")
248248
}
249249
}
250250
}

0 commit comments

Comments
 (0)