DATACASS-674 - Migrate tests to AssertJ.
This commit is contained in:
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
@@ -39,8 +37,6 @@ import com.datastax.driver.core.Session;
|
||||
*/
|
||||
public class CassandraMappingBeanFactoryPostProcessorUnitTests {
|
||||
|
||||
@Rule public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test // DATACASS-290, DATACASS-401
|
||||
public void clusterRegistrationTriggersDefaultBeanRegistration() {
|
||||
|
||||
@@ -48,9 +44,9 @@ public class CassandraMappingBeanFactoryPostProcessorUnitTests {
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "cluster-and-mock-session.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class), hasItemInArray(DefaultBeanNames.DATA_TEMPLATE));
|
||||
assertThat(context.getBeanNamesForType(CassandraMappingContext.class), hasItemInArray(DefaultBeanNames.CONTEXT));
|
||||
assertThat(context.getBeanNamesForType(CassandraConverter.class), hasItemInArray(DefaultBeanNames.CONVERTER));
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class)).contains(DefaultBeanNames.DATA_TEMPLATE);
|
||||
assertThat(context.getBeanNamesForType(CassandraMappingContext.class)).contains(DefaultBeanNames.CONTEXT);
|
||||
assertThat(context.getBeanNamesForType(CassandraConverter.class)).contains(DefaultBeanNames.CONVERTER);
|
||||
}
|
||||
|
||||
@Test // DATACASS-290, DATACASS-401
|
||||
@@ -60,64 +56,58 @@ public class CassandraMappingBeanFactoryPostProcessorUnitTests {
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "mock-session-mapping-converter.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class), hasItemInArray(DefaultBeanNames.DATA_TEMPLATE));
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class)).contains(DefaultBeanNames.DATA_TEMPLATE);
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
public void converterRegistrationFailsDueToMissingCassandraMapping() {
|
||||
|
||||
expectedException.expect(BeanCreationException.class);
|
||||
expectedException.expectMessage(containsString("No bean named 'cassandraMapping'"));
|
||||
|
||||
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "mock-session-converter.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(context::refresh)
|
||||
.withMessageContaining("No bean named 'cassandraMapping'");
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
public void defaultBeanRegistrationShouldFailWithMultipleSessions() {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException.expectMessage(allOf(containsString("found 2 beans of type"), containsString("Session")));
|
||||
|
||||
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "multiple-sessions.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh).withMessageContaining("found 2 beans of type")
|
||||
.withMessageContaining("Session");
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
public void defaultBeanRegistrationShouldFailWithMultipleSessionFactories() {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException.expectMessage(allOf(containsString("found 2 beans of type"), containsString("Session")));
|
||||
|
||||
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "multiple-session-factories.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh).withMessageContaining("found 2 beans of type")
|
||||
.withMessageContaining("Session");
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
public void defaultBeanRegistrationShouldFailWithMultipleMappingContexts() {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException
|
||||
.expectMessage(allOf(containsString("found 2 beans of type"), containsString("CassandraMappingContext")));
|
||||
|
||||
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "multiple-mapping-contexts.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh).withMessageContaining("found 2 beans of type")
|
||||
.withMessageContaining("CassandraMappingContext");
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
public void defaultBeanRegistrationShouldFailWithMultipleConvertersContexts() {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException
|
||||
.expectMessage(allOf(containsString("found 2 beans of type"), containsString("CassandraConverter")));
|
||||
|
||||
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "multiple-converters.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh).withMessageContaining("found 2 beans of type")
|
||||
.withMessageContaining("CassandraConverter");
|
||||
}
|
||||
|
||||
@Test // DATACASS-290
|
||||
@@ -127,9 +117,9 @@ public class CassandraMappingBeanFactoryPostProcessorUnitTests {
|
||||
context.load(CassandraMappingBeanFactoryPostProcessorUnitTests.class, "two-keyspaces-namespace.xml");
|
||||
context.refresh();
|
||||
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class), arrayContaining("c-1", "c-2"));
|
||||
assertThat(context.getBeanNamesForType(CassandraMappingContext.class), arrayContaining("mapping-1", "mapping-2"));
|
||||
assertThat(context.getBeanNamesForType(CassandraConverter.class), arrayContaining("converter-1", "converter-2"));
|
||||
assertThat(context.getBeanNamesForType(CassandraOperations.class)).containsExactly("c-1", "c-2");
|
||||
assertThat(context.getBeanNamesForType(CassandraMappingContext.class)).containsExactly("mapping-1", "mapping-2");
|
||||
assertThat(context.getBeanNamesForType(CassandraConverter.class)).containsExactly("converter-1", "converter-2");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping.event;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -99,8 +96,8 @@ public class AuditingEntityCallbackUnitTests {
|
||||
@Test // DATACASS-4
|
||||
public void hasExplicitOrder() {
|
||||
|
||||
assertThat(callback, is(instanceOf(Ordered.class)));
|
||||
assertThat(callback.getOrder(), is(100));
|
||||
assertThat(callback).isInstanceOf(Ordered.class);
|
||||
assertThat(callback.getOrder()).isEqualTo(100);
|
||||
}
|
||||
|
||||
@Test // DATACASS-4
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping.event;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -99,8 +96,8 @@ public class ReactiveAuditingEntityCallbackUnitTests {
|
||||
@Test // DATACASS-4
|
||||
public void hasExplicitOrder() {
|
||||
|
||||
assertThat(callback, is(instanceOf(Ordered.class)));
|
||||
assertThat(callback.getOrder(), is(100));
|
||||
assertThat(callback).isInstanceOf(Ordered.class);
|
||||
assertThat(callback.getOrder()).isEqualTo(100);
|
||||
}
|
||||
|
||||
@Test // DATACASS-4
|
||||
|
||||
Reference in New Issue
Block a user