DATACMNS-1554 - Polishing.
Replace AtTest(expected = …) and ExpectedException with the corresponding AssertJ assertThatExceptionOfType(…) and assertThatIllegalArgumentException().isThrownBy(…).
This commit is contained in:
@@ -38,9 +38,9 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
|
||||
@Mock MethodInvocation invocation;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-630
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNullMap() {
|
||||
new MapAccessingMethodInterceptor(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new MapAccessingMethodInterceptor(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
@@ -94,11 +94,12 @@ public class MapAccessingMethodInterceptorUnitTests {
|
||||
assertThat(new MapAccessingMethodInterceptor(map).invoke(invocation)).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-630
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNonAccessorInvocation() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("someMethod"));
|
||||
new MapAccessingMethodInterceptor(Collections.emptyMap()).invoke(invocation);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MapAccessingMethodInterceptor(Collections.emptyMap()).invoke(invocation));
|
||||
}
|
||||
|
||||
interface Sample {
|
||||
|
||||
@@ -50,11 +50,12 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
assertThat(interceptor.invoke(invocation)).isEqualTo("Dave");
|
||||
}
|
||||
|
||||
@Test(expected = NotReadablePropertyException.class) // DATAREST-221
|
||||
@Test // DATAREST-221
|
||||
public void throwsAppropriateExceptionIfThePropertyCannotBeFound() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getLastname"));
|
||||
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
||||
assertThatExceptionOfType(NotReadablePropertyException.class)
|
||||
.isThrownBy(() -> new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation));
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
@@ -65,12 +66,13 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class) // DATACMNS-630
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsNonAccessorMethod() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("someGarbage"));
|
||||
|
||||
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-820
|
||||
@@ -87,7 +89,7 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
assertThat(source.firstname).isEqualTo("Carl");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class) // DATACMNS-820
|
||||
@Test // DATACMNS-820
|
||||
public void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
@@ -95,16 +97,18 @@ public class PropertyAccessingMethodInterceptorUnitTests {
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class));
|
||||
when(invocation.getArguments()).thenReturn(new Object[0]);
|
||||
|
||||
new PropertyAccessingMethodInterceptor(source).invoke(invocation);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new PropertyAccessingMethodInterceptor(source).invoke(invocation));
|
||||
}
|
||||
|
||||
@Test(expected = NotWritablePropertyException.class) // DATACMNS-820
|
||||
@Test // DATACMNS-820
|
||||
public void throwsAppropriateExceptionIfThePropertyCannotWritten() throws Throwable {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setGarbage", String.class));
|
||||
when(invocation.getArguments()).thenReturn(new Object[] { "Carl" });
|
||||
|
||||
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class)
|
||||
.isThrownBy(() -> new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation));
|
||||
}
|
||||
|
||||
static class Source {
|
||||
|
||||
@@ -39,16 +39,18 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
|
||||
ProjectionFactory factory = new ProxyProjectionFactory();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-630
|
||||
// DATACMNS-630
|
||||
public void rejectsNullProjectionType() {
|
||||
factory.createProjection(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-630
|
||||
// DATACMNS-630
|
||||
public void rejectsNullProjectionTypeWithSource() {
|
||||
factory.createProjection(null, new Object());
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(null, new Object()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
@@ -82,9 +84,9 @@ public class ProxyProjectionFactoryUnitTests {
|
||||
assertThat(((TargetClassAware) proxy).getTargetClass()).isEqualTo(HashMap.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221, DATACMNS-630
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
public void rejectsNonInterfacesAsProjectionTarget() {
|
||||
factory.createProjection(Object.class, new Object());
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.createProjection(Object.class, new Object()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
|
||||
@@ -21,9 +21,8 @@ import java.beans.PropertyDescriptor;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
@@ -36,8 +35,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
*/
|
||||
public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
SpelAwareProxyProjectionFactory factory;
|
||||
|
||||
@Before
|
||||
@@ -97,8 +94,7 @@ public class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
ProjectionWithNotWriteableProperty projection = factory.createProjection(ProjectionWithNotWriteableProperty.class,
|
||||
customer);
|
||||
|
||||
exception.expect(NotWritablePropertyException.class);
|
||||
projection.setFirstName("Carl");
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> projection.setFirstName("Carl"));
|
||||
}
|
||||
|
||||
static class Customer {
|
||||
|
||||
@@ -83,11 +83,10 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
verify(delegate).invoke(invocation);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class) // DATACMNS-630
|
||||
public void rejectsEmptySpelExpression() throws Throwable {
|
||||
|
||||
new SpelEvaluatingMethodInterceptor(delegate, new Target(), new DefaultListableBeanFactory(), parser,
|
||||
InvalidProjection.class);
|
||||
@Test // DATACMNS-630
|
||||
public void rejectsEmptySpelExpression() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new SpelEvaluatingMethodInterceptor(delegate, new Target(),
|
||||
new DefaultListableBeanFactory(), parser, InvalidProjection.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
|
||||
Reference in New Issue
Block a user