GH-2760: use assertThatExceptionOfType in tests

Fixes https://github.com/spring-projects/spring-integration/issues/2760

* The `assertThatExceptionOfType()` is more convenient,
than `assertThatThrownBy`, so, replace all the usages accordingly
* Fix JavaDoc typo in the `AbstractScriptExecutingMessageProcessor`
* Fix Sonar smells for `throws Exception` in `AbstractScriptExecutingMessageProcessor`
hierarchy and some code polishing for them
This commit is contained in:
Artem Bilan
2019-02-22 13:54:36 -05:00
parent 82ecd5a75d
commit 1d54f9663a
22 changed files with 187 additions and 159 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.integration.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.io.File;
import java.io.IOException;
@@ -117,8 +117,8 @@ public class DefaultXmlPayloadConverterTests {
@Test
public void testInvalidPayload() {
assertThatThrownBy(() -> converter.convertToSource(12))
.isExactlyInstanceOf(MessagingException.class);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> converter.convertToSource(12));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.integration.xml.source;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.io.StringReader;
@@ -74,8 +74,8 @@ public class DomSourceFactoryTests {
@Test
public void testWithUnsupportedPayload() {
assertThatThrownBy(() -> sourceFactory.createSource(12))
.isExactlyInstanceOf(MessagingException.class);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> sourceFactory.createSource(12));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.integration.xml.source;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.io.BufferedReader;
@@ -65,8 +65,8 @@ public class StringSourceTests {
public void testWithUnsupportedPayload() {
String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>";
StringBuffer buffer = new StringBuffer(docString);
assertThatThrownBy(() -> sourceFactory.createSource(buffer))
.isExactlyInstanceOf(MessagingException.class);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> sourceFactory.createSource(buffer));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.integration.xml.transformer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.Properties;
@@ -83,8 +83,8 @@ public class ResultToStringTransformerTests {
@Test
public void testWithUnsupportedSaxResult() {
assertThatThrownBy(() -> this.transformer.transformResult(new SAXResult()))
.isExactlyInstanceOf(MessagingException.class);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> this.transformer.transformResult(new SAXResult()));
}
}

View File

@@ -17,7 +17,8 @@
package org.springframework.integration.xml.transformer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import java.io.File;
import java.io.IOException;
@@ -163,21 +164,21 @@ public class XsltPayloadTransformerTests {
XsltPayloadTransformer transformer =
new XsltPayloadTransformer(getXslResourceThatOutputsText(), "foo.bar.Baz");
transformer.setBeanFactory(Mockito.mock(BeanFactory.class));
assertThatThrownBy(transformer::afterPropertiesSet)
.isExactlyInstanceOf(IllegalStateException.class)
.hasCauseExactlyInstanceOf(ClassNotFoundException.class);
assertThatIllegalStateException()
.isThrownBy(transformer::afterPropertiesSet)
.withCauseExactlyInstanceOf(ClassNotFoundException.class);
}
@Test
public void testNonXmlString() {
assertThatThrownBy(() -> this.transformer.doTransform(new GenericMessage<>("test")))
.isExactlyInstanceOf(TransformerException.class);
assertThatExceptionOfType(TransformerException.class)
.isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>("test")));
}
@Test
public void testUnsupportedPayloadType() {
assertThatThrownBy(() -> this.transformer.doTransform(new GenericMessage<>(12)))
.isExactlyInstanceOf(MessagingException.class);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>(12)));
}
@Test