Skip to content

Commit 72fd594

Browse files
committed
[IO-619] Use assertThrows instead of try-fail-catch
1 parent 09315cf commit 72fd594

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

src/test/java/org/apache/commons/io/input/CharSequenceReaderTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.apache.commons.io.input;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021
import static org.junit.jupiter.api.Assertions.assertTrue;
21-
import static org.junit.jupiter.api.Assertions.fail;
2222

2323
import java.io.ByteArrayInputStream;
2424
import java.io.ByteArrayOutputStream;
@@ -214,18 +214,10 @@ private void checkArray(final char[] expected, final char[] actual) {
214214

215215
@Test
216216
public void testConstructor() {
217-
try {
218-
new CharSequenceReader("FooBar", -1, 6);
219-
fail("Expected exception not thrown for negative start.");
220-
} catch (IllegalArgumentException e) {
221-
// expected
222-
}
223-
try {
224-
new CharSequenceReader("FooBar", 1, 0);
225-
fail("Expected exception not thrown for end before start.");
226-
} catch (IllegalArgumentException e) {
227-
// expected
228-
}
217+
assertThrows(IllegalArgumentException.class, () -> new CharSequenceReader("FooBar", -1, 6),
218+
"Expected exception not thrown for negative start.");
219+
assertThrows(IllegalArgumentException.class, () -> new CharSequenceReader("FooBar", 1, 0),
220+
"Expected exception not thrown for end before start.");
229221
}
230222

231223
@Test
@@ -238,7 +230,7 @@ public void testToString() {
238230
public void testSerialization() throws IOException, ClassNotFoundException {
239231
/*
240232
* File CharSequenceReader.bin contains a CharSequenceReader that was serialized before
241-
* the start and end fields were added. Its CharSequecne is "FooBar".
233+
* the start and end fields were added. Its CharSequence is "FooBar".
242234
* This part of the test will test that adding the fields does not break any existing
243235
* serialized CharSequenceReaders.
244236
*/

0 commit comments

Comments
 (0)