DATACMNS-1554 - Polishing.

Replace AtTest(expected = …) and ExpectedException with the corresponding AssertJ assertThatExceptionOfType(…) and assertThatIllegalArgumentException().isThrownBy(…).
This commit is contained in:
Mark Paluch
2019-07-10 11:47:46 +02:00
parent 660006b8c9
commit 704913c866
79 changed files with 457 additions and 474 deletions

View File

@@ -19,9 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import java.lang.reflect.Field;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.util.ReflectionUtils;
@@ -39,8 +38,6 @@ public class AnnotationAuditingMetadataUnitTests {
static final Field lastModifiedByField = ReflectionUtils.findField(AnnotatedUser.class, "lastModifiedBy");
static final Field lastModifiedDateField = ReflectionUtils.findField(AnnotatedUser.class, "lastModifiedDate");
@Rule public ExpectedException exception = ExpectedException.none();
@Test
public void checkAnnotationDiscovery() {
@@ -82,11 +79,8 @@ public class AnnotationAuditingMetadataUnitTests {
@CreatedDate String field;
}
exception.expect(IllegalStateException.class);
exception.expectMessage(String.class.getName());
exception.expectMessage("field");
AnnotationAuditingMetadata.getMetadata(Sample.class);
assertThatIllegalStateException().isThrownBy(() -> AnnotationAuditingMetadata.getMetadata(Sample.class))
.withMessageContaining("field").withMessageContaining("String");
}
@SuppressWarnings("unused")

View File

@@ -26,6 +26,7 @@ import java.time.temporal.TemporalAccessor;
import java.util.Optional;
import org.junit.Test;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.AuditableInterfaceBeanWrapper;
@@ -43,9 +44,9 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
DefaultAuditableBeanWrapperFactory factory = new DefaultAuditableBeanWrapperFactory();
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullSource() {
factory.getBeanWrapperFor(null);
assertThatIllegalArgumentException().isThrownBy(() -> factory.getBeanWrapperFor(null));
}
@Test
@@ -85,7 +86,7 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
});
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-867
@Test // DATACMNS-867
public void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion() {
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
@@ -93,7 +94,10 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
Optional<AuditableBeanWrapper<Jsr310ThreeTenBpAuditedUser>> wrapper = factory.getBeanWrapperFor(user);
assertThat(wrapper).hasValueSatisfying(it -> it.setLastModifiedDate(zonedDateTime));
assertThat(wrapper).isNotEmpty();
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> wrapper.ifPresent(it -> it.setLastModifiedDate(zonedDateTime)));
}
@Test // DATACMNS-1259

View File

@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.mapping.context.SampleMappingContext;
@@ -74,9 +75,9 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
assertThat(user.modifiedDate).isNotNull();
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-365
@Test // DATACMNS-365
public void rejectsNullMappingContext() {
new IsNewAwareAuditingHandler((PersistentEntities) null);
assertThatIllegalArgumentException().isThrownBy(() -> new IsNewAwareAuditingHandler((PersistentEntities) null));
}
@Test // DATACMNS-365