Skip to content

Commit a768567

Browse files
committed
CAMEL-21196: modernize exception-based assertions in camel-tika
Replace try-catch-fail patterns with JUnit 5 assertThrows for modernized exception testing.
1 parent 3833f00 commit a768567

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

components/camel-tika/src/test/java/org/apache/camel/component/tika/TikaParseTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import static org.hamcrest.Matchers.equalTo;
4141
import static org.hamcrest.Matchers.instanceOf;
4242
import static org.hamcrest.Matchers.startsWith;
43-
import static org.junit.jupiter.api.Assertions.fail;
43+
import static org.junit.jupiter.api.Assertions.assertThrows;
4444

4545
public class TikaParseTest extends CamelTestSupport {
4646

@@ -58,13 +58,11 @@ public boolean matches(Exchange exchange) {
5858
assertThat(body, instanceOf(String.class));
5959

6060
Charset detectedCharset = null;
61-
try {
61+
assertThrows(IOException.class, () -> {
6262
InputStream bodyIs = new ByteArrayInputStream(body.getBytes());
6363
UniversalEncodingDetector encodingDetector = new UniversalEncodingDetector();
6464
detectedCharset = encodingDetector.detect(bodyIs, new Metadata());
65-
} catch (IOException e1) {
66-
fail();
67-
}
65+
});
6866

6967
assertThat(detectedCharset, equalTo(StandardCharsets.ISO_8859_1));
7068
assertThat(body, containsString("<body/>"));
@@ -89,13 +87,11 @@ public boolean matches(Exchange exchange) {
8987
assertThat(body, instanceOf(String.class));
9088

9189
Charset detectedCharset = null;
92-
try {
90+
assertThrows(IOException.class, () -> {
9391
InputStream bodyIs = new ByteArrayInputStream(((String) body).getBytes(StandardCharsets.UTF_16));
9492
UniversalEncodingDetector encodingDetector = new UniversalEncodingDetector();
9593
detectedCharset = encodingDetector.detect(bodyIs, new Metadata());
96-
} catch (IOException e1) {
97-
fail();
98-
}
94+
});
9995

10096
assertThat(detectedCharset.name(), startsWith(StandardCharsets.UTF_16.name()));
10197
assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/vnd.oasis.opendocument.text"));

0 commit comments

Comments
 (0)