DATAMONGO-2321 - Polishing.

Reduce AtTest(expected = …) and ExpectedException with the corresponding AssertJ assertThatExceptionOfType(…) and assertThatIllegalArgumentException().isThrownBy(…).
This commit is contained in:
Mark Paluch
2019-07-11 12:06:27 +02:00
parent fad18341fa
commit 945d3b0085
81 changed files with 523 additions and 688 deletions

View File

@@ -25,9 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -55,8 +53,6 @@ import com.mongodb.MongoClient;
*/
public class AbstractMongoConfigurationUnitTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Test // DATAMONGO-496
public void usesConfigClassPackageAsBaseMappingPackage() throws ClassNotFoundException {
@@ -84,9 +80,8 @@ public class AbstractMongoConfigurationUnitTests {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
assertThat(context.getBean(MongoDbFactory.class)).isNotNull();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> context.getBean(MongoClient.class));
exception.expect(NoSuchBeanDefinitionException.class);
context.getBean(MongoClient.class);
context.close();
}

View File

@@ -25,9 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -55,8 +53,6 @@ import com.mongodb.reactivestreams.client.MongoClients;
*/
public class AbstractReactiveMongoConfigurationUnitTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Test // DATAMONGO-1444
public void usesConfigClassPackageAsBaseMappingPackage() throws ClassNotFoundException {
@@ -84,14 +80,9 @@ public class AbstractReactiveMongoConfigurationUnitTests {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
assertThat(context.getBean(SimpleReactiveMongoDatabaseFactory.class)).isNotNull();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> context.getBean(Mongo.class));
exception.expect(NoSuchBeanDefinitionException.class);
try {
context.getBean(Mongo.class);
} finally {
context.close();
}
context.close();
}
@Test // DATAMONGO-1444

View File

@@ -21,9 +21,7 @@ import java.util.Collections;
import java.util.Set;
import org.bson.Document;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanReference;
@@ -53,8 +51,6 @@ import org.springframework.stereotype.Component;
*/
public class MappingMongoConverterParserIntegrationTests {
@Rule public ExpectedException exception = ExpectedException.none();
DefaultListableBeanFactory factory;
@Test // DATAMONGO-243
@@ -99,22 +95,20 @@ public class MappingMongoConverterParserIntegrationTests {
@Test // DATAMONGO-866
public void rejectsInvalidFieldNamingStrategyConfiguration() {
exception.expect(BeanDefinitionParsingException.class);
exception.expectMessage("abbreviation");
exception.expectMessage("field-naming-strategy-ref");
BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-invalid.xml"));
assertThatExceptionOfType(BeanDefinitionParsingException.class)
.isThrownBy(() -> reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-invalid.xml")))
.withMessageContaining("abbreviation").withMessageContaining("field-naming-strategy-ref");
}
@Test // DATAMONGO-892
public void shouldThrowBeanDefinitionParsingExceptionIfConverterDefinedAsNestedBean() {
exception.expect(BeanDefinitionParsingException.class);
exception.expectMessage("Mongo Converter must not be defined as nested bean.");
assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(this::loadNestedBeanConfiguration)
.withMessageContaining("Mongo Converter must not be defined as nested bean.");
loadNestedBeanConfiguration();
}
@Test // DATAMONGO-925, DATAMONGO-928

View File

@@ -15,15 +15,18 @@
*/
package org.springframework.data.mongodb.config;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.type.AnnotationMetadata;
/**
* Unit tests for {@link JpaAuditingRegistrar}.
* Unit tests for {@link MongoAuditingRegistrar}.
*
* @author Oliver Gierke
*/
@@ -35,13 +38,13 @@ public class MongoAuditingRegistrarUnitTests {
@Mock AnnotationMetadata metadata;
@Mock BeanDefinitionRegistry registry;
@Test(expected = IllegalArgumentException.class) // DATAMONGO-792
@Test // DATAMONGO-792
public void rejectsNullAnnotationMetadata() {
registrar.registerBeanDefinitions(null, registry);
assertThatIllegalArgumentException().isThrownBy(() -> registrar.registerBeanDefinitions(null, registry));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-792
@Test // DATAMONGO-792
public void rejectsNullBeanDefinitionRegistry() {
registrar.registerBeanDefinitions(metadata, null);
assertThatIllegalArgumentException().isThrownBy(() -> registrar.registerBeanDefinitions(metadata, null));
}
}

View File

@@ -137,14 +137,15 @@ public class MongoCredentialPropertyEditorUnitTests {
assertThat(getValue()).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1158
@Test // DATAMONGO-1158
public void shouldThrowExceptionForMalformatedCredentialsString() {
editor.setAsText("tyrion");
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("tyrion"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1158
@Test // DATAMONGO-1158
public void shouldThrowExceptionForMalformatedAuthMechanism() {
editor.setAsText(USER_2_AUTH_STRING + "?uri.authMechanism=Targaryen");
assertThatIllegalArgumentException()
.isThrownBy(() -> editor.setAsText(USER_2_AUTH_STRING + "?uri.authMechanism=Targaryen"));
}
@Test // DATAMONGO-1158
@@ -283,10 +284,10 @@ public class MongoCredentialPropertyEditorUnitTests {
assertThat(getValue()).contains(SCRAM_SHA_256_CREDENTIALS);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-2016
@Test // DATAMONGO-2016
@SuppressWarnings("unchecked")
public void failsGracefullyOnEmptyQueryArgument() {
editor.setAsText(USER_5_AUTH_STRING_WITH_QUERY_ARGS);
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(USER_5_AUTH_STRING_WITH_QUERY_ARGS));
}
@SuppressWarnings("unchecked")

View File

@@ -44,8 +44,9 @@ public class MongoDbFactoryNoDatabaseRunningTests {
assertThat(mongoTemplate.getClass().getName()).isEqualTo("org.springframework.data.mongodb.core.MongoTemplate");
}
@Test(expected = DataAccessResourceFailureException.class)
@Test
public void failsDataAccessWithoutADatabaseRunning() {
mongoTemplate.getCollectionNames();
assertThatExceptionOfType(DataAccessResourceFailureException.class)
.isThrownBy(() -> mongoTemplate.getCollectionNames());
}
}

View File

@@ -18,9 +18,7 @@ package org.springframework.data.mongodb.config;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.mongodb.ReadPreference;
@@ -31,8 +29,6 @@ import com.mongodb.ReadPreference;
*/
public class ReadPreferencePropertyEditorUnitTests {
@Rule public ExpectedException expectedException = ExpectedException.none();
ReadPreferencePropertyEditor editor;
@Before
@@ -43,11 +39,8 @@ public class ReadPreferencePropertyEditorUnitTests {
@Test // DATAMONGO-1158
public void shouldThrowExceptionOnUndefinedPreferenceString() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("ReadPreference");
expectedException.expectMessage("foo");
editor.setAsText("foo");
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("foo")).withMessageContaining("foo")
.withMessageContaining("ReadPreference");
}
@Test // DATAMONGO-1158

View File

@@ -24,9 +24,7 @@ import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.mongodb.ServerAddress;
@@ -38,8 +36,6 @@ import com.mongodb.ServerAddress;
*/
public class ServerAddressPropertyEditorUnitTests {
@Rule public ExpectedException expectedException = ExpectedException.none();
ServerAddressPropertyEditor editor;
@Before
@@ -123,13 +119,11 @@ public class ServerAddressPropertyEditorUnitTests {
* We can't tell whether the last part of the hostAddress represents a port or not.
*/
@Test // DATAMONGO-808
public void shouldFailToHandleAmbiguousIPv6HostaddressLongWithoutPortAndWithoutBrackets()
throws UnknownHostException {
expectedException.expect(IllegalArgumentException.class);
public void shouldFailToHandleAmbiguousIPv6HostaddressLongWithoutPortAndWithoutBrackets() {
String hostAddress = "0000:0000:0000:0000:0000:0000:0000:128";
editor.setAsText(hostAddress);
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(hostAddress));
}
@Test // DATAMONGO-808

View File

@@ -69,22 +69,22 @@ public class DefaultBulkOperationsIntegrationTests {
this.collection.deleteMany(new Document());
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-934
@Test // DATAMONGO-934
public void rejectsNullMongoOperations() {
new DefaultBulkOperations(null, COLLECTION_NAME,
new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null));
assertThatIllegalArgumentException().isThrownBy(() -> new DefaultBulkOperations(null, COLLECTION_NAME,
new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null)));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-934
@Test // DATAMONGO-934
public void rejectsNullCollectionName() {
new DefaultBulkOperations(operations, null,
new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null));
assertThatIllegalArgumentException().isThrownBy(() -> new DefaultBulkOperations(operations, null,
new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null)));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-934
@Test // DATAMONGO-934
public void rejectsEmptyCollectionName() {
new DefaultBulkOperations(operations, "", new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null));
assertThatIllegalArgumentException().isThrownBy(() -> new DefaultBulkOperations(operations, "",
new BulkOperationContext(BulkMode.ORDERED, Optional.empty(), null, null, null, null)));
}
@Test // DATAMONGO-934

View File

@@ -146,9 +146,9 @@ public class DefaultScriptOperationsTests {
assertThat(result).isEqualTo((Object) 10D);
}
@Test(expected = UncategorizedDataAccessException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void callShouldThrowExceptionWhenCallingScriptThatDoesNotExist() {
scriptOps.call(SCRIPT_NAME, 10);
assertThatExceptionOfType(UncategorizedDataAccessException.class).isThrownBy(() -> scriptOps.call(SCRIPT_NAME, 10));
}
@Test // DATAMONGO-479

View File

@@ -46,14 +46,14 @@ public class DefaultScriptOperationsUnitTests {
this.scriptOps = new DefaultScriptOperations(mongoOperations);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void rejectsNullExecutableMongoScript() {
scriptOps.register((ExecutableMongoScript) null);
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.register((ExecutableMongoScript) null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void rejectsNullNamedMongoScript() {
scriptOps.register((NamedMongoScript) null);
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.register((NamedMongoScript) null));
}
@Test // DATAMONGO-479
@@ -75,28 +75,28 @@ public class DefaultScriptOperationsUnitTests {
assertThat(captor.getValue().getName()).isNotNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void executeShouldThrowExceptionWhenScriptIsNull() {
scriptOps.execute(null);
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.execute(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void existsShouldThrowExceptionWhenScriptNameIsNull() {
scriptOps.exists(null);
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.exists(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void existsShouldThrowExceptionWhenScriptNameIsEmpty() {
scriptOps.exists("");
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.exists(""));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void callShouldThrowExceptionWhenScriptNameIsNull() {
scriptOps.call(null);
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.call(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void callShouldThrowExceptionWhenScriptNameIsEmpty() {
scriptOps.call("");
assertThatIllegalArgumentException().isThrownBy(() -> scriptOps.call(""));
}
}

View File

@@ -44,24 +44,25 @@ public class ExecutableAggregationOperationSupportUnitTests {
opSupport = new ExecutableAggregationOperationSupport(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void throwsExceptionOnNullDomainType() {
opSupport.aggregateAndReturn(null);
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void throwsExceptionOnNullCollectionWhenUsed() {
opSupport.aggregateAndReturn(Person.class).inCollection(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).inCollection(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void throwsExceptionOnEmptyCollectionWhenUsed() {
opSupport.aggregateAndReturn(Person.class).inCollection("");
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).inCollection(""));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void throwsExceptionOnNullAggregation() {
opSupport.aggregateAndReturn(Person.class).by(null);
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).by(null));
}
@Test // DATAMONGO-1563

View File

@@ -78,19 +78,19 @@ public class ExecutableFindOperationSupportTests {
initPlanets();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void domainTypeIsRequired() {
template.query(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void returnTypeIsRequiredOnSet() {
template.query(Person.class).as(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(Person.class).as(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void collectionIsRequiredOnSet() {
template.query(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(Person.class).inCollection(null));
}
@Test // DATAMONGO-1563
@@ -164,9 +164,10 @@ public class ExecutableFindOperationSupportTests {
assertThat(template.query(Person.class).matching(query(where("firstname").is("spock"))).one()).isEmpty();
}
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void findByTooManyResults() {
template.query(Person.class).matching(query(where("firstname").in("han", "luke"))).one();
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> template.query(Person.class).matching(query(where("firstname").in("han", "luke"))).one());
}
@Test // DATAMONGO-1726
@@ -174,9 +175,10 @@ public class ExecutableFindOperationSupportTests {
assertThat(template.query(Person.class).matching(query(where("firstname").is("luke"))).oneValue()).isEqualTo(luke);
}
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1726
@Test // DATAMONGO-1726
public void findByReturningOneValueButTooManyResults() {
template.query(Person.class).matching(query(where("firstname").in("han", "luke"))).oneValue();
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(
() -> template.query(Person.class).matching(query(where("firstname").in("han", "luke"))).oneValue());
}
@Test // DATAMONGO-1726
@@ -513,9 +515,10 @@ public class ExecutableFindOperationSupportTests {
assertThat(template.query(Person.class).distinct("father").all()).containsExactlyInAnyOrder(expected);
}
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-1761
@Test // DATAMONGO-1761
public void distinctThrowsExceptionWhenExplicitMappingTypeCannotBeApplied() {
template.query(Person.class).distinct("firstname").as(Long.class).all();
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> template.query(Person.class).distinct("firstname").as(Long.class).all());
}
interface Contact {}

View File

@@ -68,15 +68,14 @@ public class ExecutableInsertOperationSupportUnitTests {
han.id = "id-2";
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void nullCollectionShouldThrowException() {
ops.insert(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> ops.insert(Person.class).inCollection(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void nullBulkModeShouldThrowException() {
ops.insert(Person.class).withBulkMode(null);
assertThatIllegalArgumentException().isThrownBy(() -> ops.insert(Person.class).withBulkMode(null));
}
@Test // DATAMONGO-1563

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.mongodb.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
@@ -58,14 +59,14 @@ public class ExecutableMapReduceOperationSupportUnitTests {
mapReduceOpsSupport = new ExecutableMapReduceOperationSupport(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1929
@Test // DATAMONGO-1929
public void throwsExceptionOnNullTemplate() {
new ExecutableMapReduceOperationSupport(null);
assertThatIllegalArgumentException().isThrownBy(() -> new ExecutableMapReduceOperationSupport(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1929
@Test // DATAMONGO-1929
public void throwsExceptionOnNullDomainType() {
mapReduceOpsSupport.mapReduce(null);
assertThatIllegalArgumentException().isThrownBy(() -> mapReduceOpsSupport.mapReduce(null));
}
@Test // DATAMONGO-1929

View File

@@ -66,24 +66,25 @@ public class ExecutableUpdateOperationSupportTests {
template.save(luke);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void domainTypeIsRequired() {
template.update(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void updateIsRequired() {
template.update(Person.class).apply(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(Person.class).apply(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void collectionIsRequiredOnSet() {
template.update(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(Person.class).inCollection(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1563
@Test // DATAMONGO-1563
public void findAndModifyOptionsAreRequiredOnSet() {
template.update(Person.class).apply(new Update()).withOptions(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> template.update(Person.class).apply(new Update()).withOptions(null));
}
@Test // DATAMONGO-1563

View File

@@ -28,9 +28,9 @@ import org.junit.Test;
*/
public class GeoCommandStatisticsUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1361
@Test // DATAMONGO-1361
public void rejectsNullCommandResult() {
GeoCommandStatistics.from(null);
assertThatIllegalArgumentException().isThrownBy(() -> GeoCommandStatistics.from(null));
}
@Test // DATAMONGO-1361

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.core;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
@@ -95,23 +95,23 @@ public abstract class MongoOperationsUnitTests {
};
}
@Test(expected = IllegalArgumentException.class)
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void rejectsNullForCollectionCallback() {
getOperations().execute("test", (CollectionCallback) null);
assertThatIllegalArgumentException().isThrownBy(() -> getOperations().execute("test", (CollectionCallback) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void rejectsNullForCollectionCallback2() {
getOperations().execute("collection", (CollectionCallback) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> getOperations().execute("collection", (CollectionCallback) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void rejectsNullForDbCallback() {
getOperations().execute((DbCallback) null);
assertThatIllegalArgumentException().isThrownBy(() -> getOperations().execute((DbCallback) null));
}
@Test
@@ -350,12 +350,7 @@ public abstract class MongoOperationsUnitTests {
public void assertException(Class<? extends Exception> exception) {
try {
doWith(getOperationsForExceptionHandling());
fail("Expected " + exception + " but completed without any!");
} catch (Exception e) {
assertTrue("Expected " + exception + " but got " + e, exception.isInstance(e));
}
assertThatThrownBy(() -> doWith(getOperationsForExceptionHandling())).isInstanceOf(exception);
}
public abstract void doWith(MongoOperations operations);

View File

@@ -19,10 +19,9 @@ import static org.assertj.core.api.Assertions.*;
import org.bson.Document;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
@@ -47,8 +46,6 @@ public class MongoTemplateMappingTests {
@Autowired @Qualifier("mongoTemplate2") MongoTemplate template2;
@Rule public ExpectedException thrown = ExpectedException.none();
@Before
public void setUp() {
template1.dropCollection(template1.getCollectionName(Person.class));

View File

@@ -43,7 +43,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -138,7 +137,6 @@ public class MongoTemplateTests {
ConfigurableApplicationContext context;
MongoTemplate mappingTemplate;
@Rule public ExpectedException thrown = ExpectedException.none();
@Rule public MongoVersionRule mongoVersion = MongoVersionRule.any();
@Autowired
@@ -160,8 +158,8 @@ public class MongoTemplateTests {
Arrays.asList(DateToDateTimeConverter.INSTANCE, DateTimeToDateConverter.INSTANCE));
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setInitialEntitySet(new HashSet<Class<?>>(
Arrays.asList(PersonWith_idPropertyOfTypeObjectId.class, PersonWith_idPropertyOfTypeString.class,
mappingContext.setInitialEntitySet(
new HashSet<>(Arrays.asList(PersonWith_idPropertyOfTypeObjectId.class, PersonWith_idPropertyOfTypeString.class,
PersonWithIdPropertyOfTypeObjectId.class, PersonWithIdPropertyOfTypeString.class,
PersonWithIdPropertyOfTypeInteger.class, PersonWithIdPropertyOfTypeBigInteger.class,
PersonWithIdPropertyOfPrimitiveInt.class, PersonWithIdPropertyOfTypeLong.class,
@@ -293,14 +291,12 @@ public class MongoTemplateTests {
template.insert(person);
thrown.expect(DataIntegrityViolationException.class);
thrown.expectMessage("array");
thrown.expectMessage("age");
// thrown.expectMessage("failed");
Query query = new Query(Criteria.where("firstName").is("Amol"));
Update upd = new Update().push("age", 29);
template.updateFirst(query, upd, Person.class);
assertThatExceptionOfType(DataIntegrityViolationException.class)
.isThrownBy(() -> template.updateFirst(query, upd, Person.class)).withMessageContaining("array")
.withMessageContaining("age");
}
@Test // DATAMONGO-480
@@ -329,9 +325,6 @@ public class MongoTemplateTests {
@Test // DATAMONGO-480
public void rejectsDuplicateIdInInsertAll() {
thrown.expect(DataIntegrityViolationException.class);
thrown.expectMessage("E11000 duplicate key error");
MongoTemplate template = new MongoTemplate(factory);
template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
@@ -339,11 +332,12 @@ public class MongoTemplateTests {
Person person = new Person(id, "Amol");
person.setAge(28);
List<Person> records = new ArrayList<Person>();
List<Person> records = new ArrayList<>();
records.add(person);
records.add(person);
template.insertAll(records);
assertThatExceptionOfType(DataIntegrityViolationException.class).isThrownBy(() -> template.insertAll(records))
.withMessageContaining("E11000 duplicate key error");
}
@Test // DATAMONGO-1687
@@ -379,7 +373,7 @@ public class MongoTemplateTests {
template.indexOps(Person.class).ensureIndex(new Index().on("age", Direction.DESC).unique());
MongoCollection<org.bson.Document> coll = template.getCollection(template.getCollectionName(Person.class));
List<org.bson.Document> indexInfo = new ArrayList<org.bson.Document>();
List<org.bson.Document> indexInfo = new ArrayList<>();
coll.listIndexes().into(indexInfo);
assertThat(indexInfo.size()).isEqualTo(2);
@@ -1015,7 +1009,7 @@ public class MongoTemplateTests {
p4.setAge(41);
template.insert(p4);
List<Integer> l1 = new ArrayList<Integer>();
List<Integer> l1 = new ArrayList<>();
l1.add(11);
l1.add(21);
l1.add(41);
@@ -1026,7 +1020,7 @@ public class MongoTemplateTests {
assertThat(results1.size()).isEqualTo(3);
assertThat(results2.size()).isEqualTo(3);
try {
List<Integer> l2 = new ArrayList<Integer>();
List<Integer> l2 = new ArrayList<>();
l2.add(31);
Query q3 = new Query(Criteria.where("age").in(l1, l2));
template.find(q3, PersonWithIdPropertyOfTypeObjectId.class);
@@ -1238,9 +1232,9 @@ public class MongoTemplateTests {
});
}
@Test(expected = IllegalArgumentException.class) // DATADOC-166, DATAMONGO-1762
@Test // DATADOC-166, DATAMONGO-1762
public void removingNullIsANoOp() {
template.remove((Object) null);
assertThatIllegalArgumentException().isThrownBy(() -> template.remove((Object) null));
}
@Test // DATADOC-240, DATADOC-212
@@ -1321,7 +1315,7 @@ public class MongoTemplateTests {
template.insert(new Person("Tom"));
template.insert(new Person("Dick"));
template.insert(new Person("Harry"));
final List<String> names = new ArrayList<String>();
final List<String> names = new ArrayList<>();
template.executeQuery(new Query(), template.getCollectionName(Person.class), new DocumentCallbackHandler() {
public void processDocument(org.bson.Document document) {
String name = (String) document.get("firstName");
@@ -1339,7 +1333,7 @@ public class MongoTemplateTests {
template.insert(new Person("Tom"));
template.insert(new Person("Dick"));
template.insert(new Person("Harry"));
final List<String> names = new ArrayList<String>();
final List<String> names = new ArrayList<>();
template.executeQuery(new Query(), template.getCollectionName(Person.class), new DocumentCallbackHandler() {
public void processDocument(org.bson.Document document) {
String name = (String) document.get("firstName");
@@ -1374,19 +1368,19 @@ public class MongoTemplateTests {
assertThat(template.count(query(where("firstName").is("Carter")), Person.class)).isEqualTo(1L);
}
@Test(expected = IllegalArgumentException.class) // DATADOC-183
@Test // DATADOC-183
public void countRejectsNullEntityClass() {
template.count(null, (Class<?>) null);
assertThatIllegalArgumentException().isThrownBy(() -> template.count(null, (Class<?>) null));
}
@Test(expected = IllegalArgumentException.class) // DATADOC-183
@Test // DATADOC-183
public void countRejectsEmptyCollectionName() {
template.count(null, "");
assertThatIllegalArgumentException().isThrownBy(() -> template.count(null, ""));
}
@Test(expected = IllegalArgumentException.class) // DATADOC-183
@Test // DATADOC-183
public void countRejectsNullCollectionName() {
template.count(null, (String) null);
assertThatIllegalArgumentException().isThrownBy(() -> template.count(null, (String) null));
}
@Test
@@ -1574,20 +1568,20 @@ public class MongoTemplateTests {
// DATAMONGO-549
public void savesMapCorrectly() {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
map.put("key", "value");
template.save(map, "maps");
}
@Test(expected = MappingException.class) // DATAMONGO-549, DATAMONGO-1730
@Test // DATAMONGO-549, DATAMONGO-1730
public void savesMongoPrimitiveObjectCorrectly() {
template.save(new Object(), "collection");
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> template.save(new Object(), "collection"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-549
@Test // DATAMONGO-549
public void rejectsNullObjectToBeSaved() {
template.save(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.save(null));
}
@Test // DATAMONGO-550
@@ -1624,9 +1618,9 @@ public class MongoTemplateTests {
template.save("{ 'foo' : 'bar' }", "collection");
}
@Test(expected = MappingException.class) // DATAMONGO-551
@Test // DATAMONGO-551
public void rejectsNonJsonStringForSave() {
template.save("Foobar!", "collection");
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> template.save("Foobar!", "collection"));
}
@Test // DATAMONGO-588
@@ -1684,9 +1678,10 @@ public class MongoTemplateTests {
assertThat(saved.version).isEqualTo(0L);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-568, DATAMONGO-1762
@Test // DATAMONGO-568, DATAMONGO-1762
public void queryCantBeNull() {
template.find(null, PersonWithIdPropertyOfTypeObjectId.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> template.find(null, PersonWithIdPropertyOfTypeObjectId.class));
}
@Test // DATAMONGO-620
@@ -2224,7 +2219,7 @@ public class MongoTemplateTests {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection();
Map<String, Model> entry = new HashMap<String, Model>();
Map<String, Model> entry = new HashMap<>();
entry.put("key1", new ModelA("value1"));
doc.models.add(entry);
@@ -2258,7 +2253,7 @@ public class MongoTemplateTests {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection();
Map<String, Model> entry = new HashMap<String, Model>();
Map<String, Model> entry = new HashMap<>();
entry.put("key1", new ModelA("value1"));
doc.models.add(entry);
@@ -2292,7 +2287,7 @@ public class MongoTemplateTests {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection();
Map<String, Model> entry = new HashMap<String, Model>();
Map<String, Model> entry = new HashMap<>();
entry.put("key1", new ModelA("value1"));
doc.models.add(entry);
@@ -2324,7 +2319,7 @@ public class MongoTemplateTests {
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollectionWhenUpdatingPositionedElement()
throws Exception {
List<Model> models = new ArrayList<Model>();
List<Model> models = new ArrayList<>();
models.add(new ModelA("value1"));
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection(
@@ -2351,7 +2346,7 @@ public class MongoTemplateTests {
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollectionWhenUpdatingSecondElement()
throws Exception {
List<Model> models = new ArrayList<Model>();
List<Model> models = new ArrayList<>();
models.add(new ModelA("value1"));
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection(
@@ -2407,7 +2402,7 @@ public class MongoTemplateTests {
DocumentWithNestedList doc = new DocumentWithNestedList();
List<Model> entry = new ArrayList<Model>();
List<Model> entry = new ArrayList<>();
entry.add(new ModelA("value1"));
doc.models.add(entry);
@@ -2453,30 +2448,27 @@ public class MongoTemplateTests {
@MongoVersion(asOf = "3.6")
public void findAndReplaceShouldErrorOnIdPresent() {
thrown.expect(InvalidDataAccessApiUsageException.class);
template.save(new MyPerson("Walter"));
MyPerson replacement = new MyPerson("Heisenberg");
replacement.id = "invalid-id";
template.findAndReplace(query(where("name").is("Walter")), replacement);
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> template.findAndReplace(query(where("name").is("Walter")), replacement));
}
@Test // DATAMONGO-1827
public void findAndReplaceShouldErrorOnSkip() {
thrown.expect(IllegalArgumentException.class);
template.findAndReplace(query(where("name").is("Walter")).skip(10), new MyPerson("Heisenberg"));
assertThatIllegalArgumentException().isThrownBy(
() -> template.findAndReplace(query(where("name").is("Walter")).skip(10), new MyPerson("Heisenberg")));
}
@Test // DATAMONGO-1827
public void findAndReplaceShouldErrorOnLimit() {
thrown.expect(IllegalArgumentException.class);
template.findAndReplace(query(where("name").is("Walter")).limit(10), new MyPerson("Heisenberg"));
assertThatIllegalArgumentException().isThrownBy(
() -> template.findAndReplace(query(where("name").is("Walter")).limit(10), new MyPerson("Heisenberg")));
}
@Test // DATAMONGO-1827
@@ -3432,7 +3424,7 @@ public class MongoTemplateTests {
template.save(two);
DocumentWithDBRefCollection source = new DocumentWithDBRefCollection();
source.lazyDbRefAnnotatedMap = new LinkedHashMap<String, Sample>();
source.lazyDbRefAnnotatedMap = new LinkedHashMap<>();
source.lazyDbRefAnnotatedMap.put("tyrion", two);
source.lazyDbRefAnnotatedMap.put("jon", one);
template.save(source);
@@ -3865,12 +3857,12 @@ public class MongoTemplateTests {
static class DocumentWithNestedCollection {
@Id String id;
List<Map<String, Model>> models = new ArrayList<Map<String, Model>>();
List<Map<String, Model>> models = new ArrayList<>();
}
static class DocumentWithNestedList {
@Id String id;
List<List<Model>> models = new ArrayList<List<Model>>();
List<List<Model>> models = new ArrayList<>();
}
static class DocumentWithEmbeddedDocumentWithCollection {

View File

@@ -190,19 +190,20 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
this.template = new MongoTemplate(factory, converter);
}
@Test(expected = IllegalArgumentException.class)
public void rejectsNullDatabaseName() throws Exception {
new MongoTemplate(mongo, null);
@Test
public void rejectsNullDatabaseName() {
assertThatIllegalArgumentException().isThrownBy(() -> new MongoTemplate(mongo, null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1968
@Test // DATAMONGO-1968
public void rejectsNullMongo() {
new MongoTemplate((MongoClient) null, "database");
assertThatIllegalArgumentException().isThrownBy(() -> new MongoTemplate((MongoClient) null, "database"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1968
@Test // DATAMONGO-1968
public void rejectsNullMongoClient() {
new MongoTemplate((com.mongodb.client.MongoClient) null, "database");
assertThatIllegalArgumentException()
.isThrownBy(() -> new MongoTemplate((com.mongodb.client.MongoClient) null, "database"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1870

View File

@@ -16,8 +16,7 @@
package org.springframework.data.mongodb.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
@@ -27,6 +26,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
/**
@@ -45,24 +45,25 @@ public class ReactiveAggregationOperationSupportUnitTests {
opSupport = new ReactiveAggregationOperationSupport(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void throwsExceptionOnNullDomainType() {
opSupport.aggregateAndReturn(null);
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void throwsExceptionOnNullCollectionWhenUsed() {
opSupport.aggregateAndReturn(Person.class).inCollection(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).inCollection(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void throwsExceptionOnEmptyCollectionWhenUsed() {
opSupport.aggregateAndReturn(Person.class).inCollection("");
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).inCollection(""));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void throwsExceptionOnNullAggregation() {
opSupport.aggregateAndReturn(Person.class).by(null);
assertThatIllegalArgumentException().isThrownBy(() -> opSupport.aggregateAndReturn(Person.class).by(null));
}
@Test // DATAMONGO-1719

View File

@@ -106,19 +106,19 @@ public class ReactiveFindOperationSupportTests {
blocking.createCollection(STAR_WARS, options);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void domainTypeIsRequired() {
template.query(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void returnTypeIsRequiredOnSet() {
template.query(Person.class).as(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(Person.class).as(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void collectionIsRequiredOnSet() {
template.query(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.query(Person.class).inCollection(null));
}
@Test // DATAMONGO-1719

View File

@@ -16,8 +16,7 @@
package org.springframework.data.mongodb.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyList;
@@ -31,6 +30,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
/**
@@ -65,9 +65,9 @@ public class ReactiveInsertOperationSupportUnitTests {
han.id = "id-2";
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void nullCollectionShouldThrowException() {
ops.insert(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> ops.insert(Person.class).inCollection(null));
}
@Test // DATAMONGO-1719

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.data.mongodb.core;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
@@ -29,6 +28,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
@@ -60,14 +60,14 @@ public class ReactiveMapReduceOperationSupportUnitTests {
mapReduceOpsSupport = new ReactiveMapReduceOperationSupport(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1929
@Test // DATAMONGO-1929
public void throwsExceptionOnNullTemplate() {
new ExecutableMapReduceOperationSupport(null);
assertThatIllegalArgumentException().isThrownBy(() -> new ExecutableMapReduceOperationSupport(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1929
@Test // DATAMONGO-1929
public void throwsExceptionOnNullDomainType() {
mapReduceOpsSupport.mapReduce(null);
assertThatIllegalArgumentException().isThrownBy(() -> mapReduceOpsSupport.mapReduce(null));
}
@Test // DATAMONGO-1929

View File

@@ -24,9 +24,7 @@ import reactor.test.StepVerifier;
import org.bson.Document;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,8 +50,6 @@ public class ReactiveMongoTemplateExecuteTests {
private static final Version THREE = Version.parse("3.0");
@Rule public ExpectedException thrown = ExpectedException.none();
@Autowired SimpleReactiveMongoDatabaseFactory factory;
@Autowired ReactiveMongoOperations operations;

View File

@@ -30,10 +30,9 @@ import java.util.concurrent.TimeUnit;
import org.bson.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.annotation.Id;
@@ -60,8 +59,6 @@ import com.mongodb.reactivestreams.client.MongoClient;
@ContextConfiguration("classpath:reactive-infrastructure.xml")
public class ReactiveMongoTemplateIndexTests {
@Rule public ExpectedException thrown = ExpectedException.none();
@Autowired SimpleReactiveMongoDatabaseFactory factory;
@Autowired ReactiveMongoTemplate template;
@Autowired MongoClient client;

View File

@@ -43,7 +43,6 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.Assumptions;
import org.bson.BsonDocument;
import org.bson.BsonTimestamp;
@@ -51,10 +50,9 @@ import org.bson.Document;
import org.bson.types.ObjectId;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.dao.DataIntegrityViolationException;
@@ -97,8 +95,6 @@ import com.mongodb.WriteConcern;
@ContextConfiguration("classpath:reactive-infrastructure.xml")
public class ReactiveMongoTemplateTests {
@Rule public ExpectedException thrown = ExpectedException.none();
@Autowired SimpleReactiveMongoDatabaseFactory factory;
@Autowired ReactiveMongoTemplate template;
@Autowired ConfigurableApplicationContext context;
@@ -195,21 +191,19 @@ public class ReactiveMongoTemplateTests {
@Test // DATAMONGO-1444
public void simpleInsertDoesNotAllowArrays() {
thrown.expect(IllegalArgumentException.class);
Person person = new Person("Mark");
person.setAge(35);
template.insert(new Person[] { person });
assertThatIllegalArgumentException().isThrownBy(() -> template.insert(new Person[] { person }));
}
@Test // DATAMONGO-1444
public void simpleInsertDoesNotAllowCollections() {
thrown.expect(IllegalArgumentException.class);
Person person = new Person("Mark");
person.setAge(35);
template.insert(Collections.singletonList(person));
assertThatIllegalArgumentException().isThrownBy(() -> template.insert(Collections.singletonList(person)));
}
@Test // DATAMONGO-1444
@@ -563,17 +557,15 @@ public class ReactiveMongoTemplateTests {
@Test // DATAMONGO-1827
public void findAndReplaceShouldErrorOnSkip() {
thrown.expect(IllegalArgumentException.class);
template.findAndReplace(query(where("name").is("Walter")).skip(10), new MyPerson("Heisenberg")).subscribe();
assertThatIllegalArgumentException().isThrownBy(() -> template
.findAndReplace(query(where("name").is("Walter")).skip(10), new MyPerson("Heisenberg")).subscribe());
}
@Test // DATAMONGO-1827
public void findAndReplaceShouldErrorOnLimit() {
thrown.expect(IllegalArgumentException.class);
template.findAndReplace(query(where("name").is("Walter")).limit(10), new MyPerson("Heisenberg")).subscribe();
assertThatIllegalArgumentException().isThrownBy(() -> template
.findAndReplace(query(where("name").is("Walter")).limit(10), new MyPerson("Heisenberg")).subscribe());
}
@Test // DATAMONGO-1827
@@ -755,9 +747,9 @@ public class ReactiveMongoTemplateTests {
.verifyComplete();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1774
@Test // DATAMONGO-1774
public void removeWithNullShouldThrowError() {
template.remove((Object) null).subscribe();
assertThatIllegalArgumentException().isThrownBy(() -> template.remove((Object) null).subscribe());
}
@Test // DATAMONGO-1774
@@ -936,9 +928,10 @@ public class ReactiveMongoTemplateTests {
.verifyComplete();
}
@Test(expected = MappingException.class) // DATAMONGO-1444, DATAMONGO-1730, DATAMONGO-2150
@Test
// DATAMONGO-1444, DATAMONGO-1730, DATAMONGO-2150
public void savesMongoPrimitiveObjectCorrectly() {
template.save(new Object(), "collection");
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> template.save(new Object(), "collection"));
}
@Test // DATAMONGO-1444
@@ -1027,9 +1020,9 @@ public class ReactiveMongoTemplateTests {
.verifyComplete();
}
@Test(expected = MappingException.class) // DATAMONGO-1444, DATAMONGO-2150
@Test // DATAMONGO-1444, DATAMONGO-2150
public void rejectsNonJsonStringForSave() {
template.save("Foobar!", "collection");
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> template.save("Foobar!", "collection"));
}
@Test // DATAMONGO-1444
@@ -1381,7 +1374,6 @@ public class ReactiveMongoTemplateTests {
Person person2 = new Person("Data", 39);
Person person3 = new Person("MongoDB", 37);
Flux.merge(template.insert(person1), template.insert(person2), template.insert(person3)) //
.as(StepVerifier::create) //
.expectNextCount(3) //
@@ -1482,7 +1474,6 @@ public class ReactiveMongoTemplateTests {
Person person1 = new Person("Spring", 38);
Person person2 = new Person("Data", 37);
Flux.merge(template.insert(person1), template.insert(person2)) //
.as(StepVerifier::create) //
.expectNextCount(2) //

View File

@@ -153,14 +153,14 @@ public class ReactiveMongoTemplateUnitTests {
this.template = new ReactiveMongoTemplate(factory, converter);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1444
public void rejectsNullDatabaseName() throws Exception {
new ReactiveMongoTemplate(mongoClient, null);
@Test // DATAMONGO-1444
public void rejectsNullDatabaseName() {
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMongoTemplate(mongoClient, null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1444
public void rejectsNullMongo() throws Exception {
new ReactiveMongoTemplate(null, "database");
@Test // DATAMONGO-1444
public void rejectsNullMongo() {
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMongoTemplate(null, "database"));
}
@Test // DATAMONGO-1444

View File

@@ -67,24 +67,25 @@ public class ReactiveUpdateOperationSupportTests {
template = new ReactiveMongoTemplate(MongoClients.create(), "ExecutableUpdateOperationSupportTests");
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void domainTypeIsRequired() {
template.update(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void updateIsRequired() {
template.update(Person.class).apply(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(Person.class).apply(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void collectionIsRequiredOnSet() {
template.update(Person.class).inCollection(null);
assertThatIllegalArgumentException().isThrownBy(() -> template.update(Person.class).inCollection(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1719
@Test // DATAMONGO-1719
public void findAndModifyOptionsAreRequiredOnSet() {
template.update(Person.class).apply(new Update()).withOptions(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> template.update(Person.class).apply(new Update()).withOptions(null));
}
@Test // DATAMONGO-1719

View File

@@ -16,8 +16,7 @@
package org.springframework.data.mongodb.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.mongodb.core.query.Criteria.*;
import static org.springframework.data.mongodb.core.query.Query.*;
@@ -41,11 +40,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;
import org.mockito.Mockito;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.dao.DataAccessException;
@@ -88,8 +86,6 @@ public class SessionBoundMongoTemplateTests {
public static @ClassRule MongoVersionRule REQUIRES_AT_LEAST_3_6_0 = MongoVersionRule.atLeast(Version.parse("3.6.0"));
public static @ClassRule TestRule replSet = ReplicaSet.required();
public @Rule ExpectedException exception = ExpectedException.none();
MongoClient client;
MongoTemplate template;
SessionBoundMongoTemplate sessionBoundTemplate;
@@ -211,8 +207,6 @@ public class SessionBoundMongoTemplateTests {
@Test // DATAMONGO-1880
public void shouldErrorOnLoadDbRefWhenSessionIsClosed() {
exception.expect(ClientSessionException.class);
Person person = new Person("Kylar Stern");
template.save(person);
@@ -225,7 +219,8 @@ public class SessionBoundMongoTemplateTests {
session.close();
sessionBoundTemplate.findById(wdr.id, WithDbRef.class);
assertThatExceptionOfType(ClientSessionException.class)
.isThrownBy(() -> sessionBoundTemplate.findById(wdr.id, WithDbRef.class));
}
@Test // DATAMONGO-1880
@@ -249,9 +244,6 @@ public class SessionBoundMongoTemplateTests {
@Test // DATAMONGO-1880
public void shouldErrorOnLoadLazyDbRefWhenSessionIsClosed() {
exception.expect(LazyLoadingException.class);
exception.expectMessage("Invalid session state");
Person person = new Person("Kylar Stern");
template.save(person);
@@ -262,16 +254,11 @@ public class SessionBoundMongoTemplateTests {
template.save(wdr);
WithLazyDbRef result = null;
try {
result = sessionBoundTemplate.findById(wdr.id, WithLazyDbRef.class);
} catch (Exception e) {
fail("Someting went wrong, seems the session was already closed when reading.", e);
}
WithLazyDbRef result = sessionBoundTemplate.findById(wdr.id, WithLazyDbRef.class);
session.close(); // now close the session
assertThat(result.getPersonRef()).isEqualTo(person); // resolve the lazy loading proxy
assertThatExceptionOfType(LazyLoadingException.class).isThrownBy(() -> result.getPersonRef().toString());
}
@Test // DATAMONGO-2001

View File

@@ -22,9 +22,7 @@ import static org.springframework.test.util.ReflectionTestUtils.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -48,7 +46,6 @@ import com.mongodb.client.MongoDatabase;
@RunWith(MockitoJUnitRunner.class)
public class SimpleMongoDbFactoryUnitTests {
public @Rule ExpectedException expectedException = ExpectedException.none();
@Mock MongoClient mongo;
@Mock ClientSession clientSession;
@Mock MongoDatabase database;

View File

@@ -42,7 +42,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -103,7 +102,6 @@ public class AggregationTests {
@Autowired MongoTemplate mongoTemplate;
@Rule public ExpectedException exception = ExpectedException.none();
@Rule public MongoVersionRule mongoVersion = MongoVersionRule.any();
@Before
@@ -184,19 +182,22 @@ public class AggregationTests {
}
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
@Test // DATAMONGO-586
public void shouldHandleMissingInputCollection() {
mongoTemplate.aggregate(newAggregation(), (String) null, TagCount.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> mongoTemplate.aggregate(newAggregation(), (String) null, TagCount.class));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
@Test // DATAMONGO-586
public void shouldHandleMissingAggregationPipeline() {
mongoTemplate.aggregate(null, INPUT_COLLECTION, TagCount.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> mongoTemplate.aggregate(null, INPUT_COLLECTION, TagCount.class));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
@Test // DATAMONGO-586
public void shouldHandleMissingEntityClass() {
mongoTemplate.aggregate(newAggregation(), INPUT_COLLECTION, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> mongoTemplate.aggregate(newAggregation(), INPUT_COLLECTION, null));
}
@Test // DATAMONGO-586
@@ -1656,13 +1657,12 @@ public class AggregationTests {
mongoTemplate.save(new Person("Leoniv", "Yakubov", 55, Person.Sex.MALE));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1418
@Test // DATAMONGO-1418
public void outShouldOutBeTheLastOperation() {
newAggregation(match(new Criteria()), //
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation(match(new Criteria()), //
group("field1").count().as("totalCount"), //
out("collection1"), //
skip(100L));
skip(100L)));
}
@Test // DATAMONGO-1325

View File

@@ -25,9 +25,8 @@ import java.util.Arrays;
import java.util.List;
import org.bson.Document;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
import org.springframework.data.mongodb.core.query.Criteria;
@@ -42,40 +41,36 @@ import org.springframework.data.mongodb.core.query.Criteria;
*/
public class AggregationUnitTests {
public @Rule ExpectedException exception = ExpectedException.none();
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullAggregationOperation() {
newAggregation((AggregationOperation[]) null);
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation((AggregationOperation[]) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullTypedAggregationOperation() {
newAggregation(String.class, (AggregationOperation[]) null);
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation(String.class, (AggregationOperation[]) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNoAggregationOperation() {
newAggregation(new AggregationOperation[0]);
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation(new AggregationOperation[0]));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNoTypedAggregationOperation() {
newAggregation(String.class, new AggregationOperation[0]);
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation(String.class, new AggregationOperation[0]));
}
@Test // DATAMONGO-753
public void checkForCorrectFieldScopeTransfer() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Invalid reference");
exception.expectMessage("'b'");
newAggregation( //
project("a", "b"), //
group("a").count().as("cnt"), // a was introduced to the context by the project operation
project("cnt", "b") // b was removed from the context by the group operation
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); // -> triggers IllegalArgumentException
assertThatIllegalArgumentException().isThrownBy(() -> {
newAggregation( //
project("a", "b"), //
group("a").count().as("cnt"), // a was introduced to the context by the project operation
project("cnt", "b") // b was removed from the context by the group operation
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); // -> triggers IllegalArgumentException
});
}
@Test // DATAMONGO-753

View File

@@ -31,14 +31,14 @@ import org.springframework.data.mongodb.core.aggregation.BucketAutoOperation.Gra
*/
public class BucketAutoOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1552
@Test // DATAMONGO-1552
public void rejectsNullFields() {
new BucketAutoOperation((Field) null, 0);
assertThatIllegalArgumentException().isThrownBy(() -> new BucketAutoOperation((Field) null, 0));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1552
@Test // DATAMONGO-1552
public void rejectsNonPositiveIntegerNullFields() {
new BucketAutoOperation(Fields.field("field"), 0);
assertThatIllegalArgumentException().isThrownBy(() -> new BucketAutoOperation(Fields.field("field"), 0));
}
@Test // DATAMONGO-1552
@@ -53,9 +53,9 @@ public class BucketAutoOperationUnitTests {
"{ \"grossSalesPrice\" : { \"$multiply\" : [ { \"$add\" : [ \"$netPrice\" , \"$surCharge\"]} , \"$taxrate\" , 2]} , \"titles\" : { $push: \"$title\" } }}"));
}
@Test(expected = IllegalStateException.class) // DATAMONGO-1552
@Test // DATAMONGO-1552
public void shouldRenderEmptyAggregationExpression() {
bucket("groupby").andOutput("field").as("alias");
assertThatIllegalStateException().isThrownBy(() -> bucket("groupby").andOutput("field").as("alias"));
}
@Test // DATAMONGO-1552

View File

@@ -28,9 +28,9 @@ import org.junit.Test;
*/
public class BucketOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1552
@Test // DATAMONGO-1552
public void rejectsNullFields() {
new BucketOperation((Field) null);
assertThatIllegalArgumentException().isThrownBy(() -> new BucketOperation((Field) null));
}
@Test // DATAMONGO-1552
@@ -45,9 +45,9 @@ public class BucketOperationUnitTests {
"{ \"grossSalesPrice\" : { \"$multiply\" : [ { \"$add\" : [ \"$netPrice\" , \"$surCharge\"]} , \"$taxrate\" , 2]} , \"titles\" : { $push: \"$title\" } }}"));
}
@Test(expected = IllegalStateException.class) // DATAMONGO-1552
@Test // DATAMONGO-1552
public void shouldRenderEmptyAggregationExpression() {
bucket("groupby").andOutput("field").as("alias");
assertThatIllegalStateException().isThrownBy(() -> bucket("groupby").andOutput("field").as("alias"));
}
@Test // DATAMONGO-1552

View File

@@ -33,24 +33,25 @@ import org.springframework.data.mongodb.core.query.Criteria;
*/
public class CondExpressionUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-861
@Test // DATAMONGO-861
public void builderRejectsEmptyFieldName() {
newBuilder().when("");
assertThatIllegalArgumentException().isThrownBy(() -> newBuilder().when(""));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-861
@Test // DATAMONGO-861
public void builderRejectsNullFieldName() {
newBuilder().when((Document) null);
assertThatIllegalArgumentException().isThrownBy(() -> newBuilder().when((Document) null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-861
@Test // DATAMONGO-861
public void builderRejectsNullCriteriaName() {
newBuilder().when((Criteria) null);
assertThatIllegalArgumentException().isThrownBy(() -> newBuilder().when((Criteria) null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-861
@Test // DATAMONGO-861
public void builderRejectsBuilderAsThenValue() {
newBuilder().when("isYellow").then(newBuilder().when("field").then("then-value")).otherwise("otherwise");
assertThatIllegalArgumentException().isThrownBy(
() -> newBuilder().when("isYellow").then(newBuilder().when("field").then("then-value")).otherwise("otherwise"));
}
@Test // DATAMONGO-861, DATAMONGO-1542

View File

@@ -27,9 +27,9 @@ import org.junit.Test;
*/
public class CountOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1549
@Test // DATAMONGO-1549
public void rejectsEmptyFieldName() {
new CountOperation("");
assertThatIllegalArgumentException().isThrownBy(() -> new CountOperation(""));
}
@Test // DATAMONGO-1549

View File

@@ -29,19 +29,19 @@ import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedFi
*/
public class ExposedFieldsUnitTests {
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFields() {
ExposedFields.from((ExposedField) null);
assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.from((ExposedField) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldsForSynthetics() {
ExposedFields.synthetic(null);
assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.synthetic(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldsForNonSynthetics() {
ExposedFields.nonSynthetic(null);
assertThatIllegalArgumentException().isThrownBy(() -> ExposedFields.nonSynthetic(null));
}
@Test

View File

@@ -18,9 +18,7 @@ package org.springframework.data.mongodb.core.aggregation;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.mongodb.core.aggregation.Fields.*;
@@ -32,16 +30,14 @@ import org.springframework.data.mongodb.core.aggregation.Fields.*;
*/
public class FieldsUnitTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldVarArgs() {
Fields.from((Field[]) null);
assertThatIllegalArgumentException().isThrownBy(() -> Fields.from((Field[]) null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldNameVarArgs() {
Fields.fields((String[]) null);
assertThatIllegalArgumentException().isThrownBy(() -> Fields.fields((String[]) null));
}
@Test
@@ -54,19 +50,19 @@ public class FieldsUnitTests {
verify(Fields.field("foo", "bar"), "foo", "bar");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldName() {
Fields.field(null);
assertThatIllegalArgumentException().isThrownBy(() -> Fields.field(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFieldNameIfTargetGiven() {
Fields.field(null, "foo");
assertThatIllegalArgumentException().isThrownBy(() -> Fields.field(null, "foo"));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsEmptyFieldName() {
Fields.field("");
assertThatIllegalArgumentException().isThrownBy(() -> Fields.field(""));
}
@Test
@@ -99,10 +95,7 @@ public class FieldsUnitTests {
@Test
public void rejectsAmbiguousFieldNames() {
exception.expect(IllegalArgumentException.class);
fields("b", "a.b");
assertThatIllegalArgumentException().isThrownBy(() -> fields("b", "a.b"));
}
@Test // DATAMONGO-774
@@ -112,9 +105,9 @@ public class FieldsUnitTests {
assertThat(Fields.field("$$$$name").getName()).isEqualTo("name");
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-774
@Test // DATAMONGO-774
public void rejectsNameConsistingOfDollarOnly() {
Fields.field("$");
assertThatIllegalArgumentException().isThrownBy(() -> Fields.field("$"));
}
@Test // DATAMONGO-774

View File

@@ -32,9 +32,9 @@ import org.springframework.data.mongodb.core.query.Criteria;
*/
public class GraphLookupOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1551
@Test // DATAMONGO-1551
public void rejectsNullFromCollection() {
GraphLookupOperation.builder().from(null);
assertThatIllegalArgumentException().isThrownBy(() -> GraphLookupOperation.builder().from(null));
}
@Test // DATAMONGO-1551
@@ -101,15 +101,14 @@ public class GraphLookupOperationUnitTests {
Arrays.asList("$reportsTo", new Document("$literal", "$boss")));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1551
@Test // DATAMONGO-1551
public void shouldRejectUnknownTypeInMixedArrayOfStartsWithCorrectly() {
GraphLookupOperation graphLookupOperation = GraphLookupOperation.builder() //
assertThatIllegalArgumentException().isThrownBy(() -> GraphLookupOperation.builder() //
.from("employees") //
.startWith("reportsTo", new Person()) //
.connectFrom("reportsTo") //
.connectTo("name") //
.as("reportingHierarchy");
.as("reportingHierarchy"));
}
@Test // DATAMONGO-1551

View File

@@ -36,9 +36,9 @@ import org.springframework.data.mongodb.core.query.Criteria;
*/
public class GroupOperationUnitTests {
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullFields() {
new GroupOperation((Fields) null);
assertThatIllegalArgumentException().isThrownBy(() -> new GroupOperation((Fields) null));
}
@Test // DATAMONGO-759
@@ -235,9 +235,10 @@ public class GroupOperationUnitTests {
new Document("if", new Document("$eq", Arrays.asList("$foo", "bar"))).append("then", 1).append("else", -1)));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1784
@Test // DATAMONGO-1784
public void sumWithNullExpressionShouldThrowException() {
Aggregation.group("username").sum((AggregationExpression) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> Aggregation.group("username").sum((AggregationExpression) null));
}
private Document extractDocumentFromGroupOperation(GroupOperation groupOperation) {

View File

@@ -31,24 +31,28 @@ import org.springframework.data.mongodb.core.DocumentTestUtils;
*/
public class LookupOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void rejectsNullForFrom() {
new LookupOperation(null, Fields.field("localField"), Fields.field("foreignField"), Fields.field("as"));
assertThatIllegalArgumentException().isThrownBy(
() -> new LookupOperation(null, Fields.field("localField"), Fields.field("foreignField"), Fields.field("as")));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void rejectsNullLocalFieldField() {
new LookupOperation(Fields.field("from"), null, Fields.field("foreignField"), Fields.field("as"));
assertThatIllegalArgumentException().isThrownBy(
() -> new LookupOperation(Fields.field("from"), null, Fields.field("foreignField"), Fields.field("as")));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void rejectsNullForeignField() {
new LookupOperation(Fields.field("from"), Fields.field("localField"), null, Fields.field("as"));
assertThatIllegalArgumentException().isThrownBy(
() -> new LookupOperation(Fields.field("from"), Fields.field("localField"), null, Fields.field("as")));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void rejectsNullForAs() {
new LookupOperation(Fields.field("from"), Fields.field("localField"), Fields.field("foreignField"), null);
assertThatIllegalArgumentException().isThrownBy(() -> new LookupOperation(Fields.field("from"),
Fields.field("localField"), Fields.field("foreignField"), null));
}
@Test // DATAMONGO-1326
@@ -81,24 +85,26 @@ public class LookupOperationUnitTests {
return lookupClause;
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void builderRejectsNullFromField() {
LookupOperation.newLookup().from(null);
assertThatIllegalArgumentException().isThrownBy(() -> LookupOperation.newLookup().from(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void builderRejectsNullLocalField() {
LookupOperation.newLookup().from("a").localField(null);
assertThatIllegalArgumentException().isThrownBy(() -> LookupOperation.newLookup().from("a").localField(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void builderRejectsNullForeignField() {
LookupOperation.newLookup().from("a").localField("b").foreignField(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> LookupOperation.newLookup().from("a").localField("b").foreignField(null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1326
@Test // DATAMONGO-1326
public void builderRejectsNullAsField() {
LookupOperation.newLookup().from("a").localField("b").foreignField("c").as(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> LookupOperation.newLookup().from("a").localField("b").foreignField("c").as(null));
}
@Test // DATAMONGO-1326

View File

@@ -32,9 +32,9 @@ import org.junit.Test;
*/
public class OutOperationUnitTest {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1418
@Test // DATAMONGO-1418
public void shouldCheckNPEInCreation() {
new OutOperation(null);
assertThatIllegalArgumentException().isThrownBy(() -> new OutOperation(null));
}
@Test // DATAMONGO-2259

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.core.aggregation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.aggregation.AggregationFunctionExpressions.*;
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
@@ -65,9 +65,9 @@ public class ProjectionOperationUnitTests {
static final String DIVIDE = "$divide";
static final String PROJECT = "$project";
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
@Test // DATAMONGO-586
public void rejectsNullFields() {
new ProjectionOperation((Fields) null);
assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation((Fields) null));
}
@Test // DATAMONGO-586
@@ -188,10 +188,9 @@ public class ProjectionOperationUnitTests {
assertThat(oper.get(DIVIDE)).isEqualTo(Arrays.<Object> asList("$a", 1));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
@Test // DATAMONGO-586
public void arithmeticProjectionOperationDivideByZeroException() {
new ProjectionOperation().and("a").divide(0);
assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation().and("a").divide(0));
}
@Test // DATAMONGO-586
@@ -267,10 +266,9 @@ public class ProjectionOperationUnitTests {
assertThat(projectClause.get("_id")).isEqualTo(0);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void arithmeticProjectionOperationModByZeroException() {
new ProjectionOperation().and("a").mod(0);
assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation().and("a").mod(0));
}
@Test // DATAMONGO-769

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.data.mongodb.core.aggregation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyList;
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
@@ -67,30 +68,30 @@ public class ReactiveAggregationUnitTests {
when(publisher.collation(any())).thenReturn(publisher);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1646
@Test // DATAMONGO-1646
public void shouldHandleMissingInputCollection() {
template.aggregate(newAggregation(), (String) null, TagCount.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> template.aggregate(newAggregation(), (String) null, TagCount.class));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1646
@Test // DATAMONGO-1646
public void shouldHandleMissingAggregationPipeline() {
template.aggregate(null, INPUT_COLLECTION, TagCount.class);
assertThatIllegalArgumentException().isThrownBy(() -> template.aggregate(null, INPUT_COLLECTION, TagCount.class));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1646
@Test // DATAMONGO-1646
public void shouldHandleMissingEntityClass() {
template.aggregate(newAggregation(), INPUT_COLLECTION, null);
assertThatIllegalArgumentException().isThrownBy(() -> template.aggregate(newAggregation(), INPUT_COLLECTION, null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1646
@Test // DATAMONGO-1646
public void errorsOnExplainUsage() {
template
assertThatIllegalArgumentException().isThrownBy(() -> template
.aggregate(newAggregation(Product.class, //
project("name", "netPrice")) //
.withOptions(AggregationOptions.builder().explain(true).build()),
INPUT_COLLECTION, TagCount.class)
.subscribe();
.subscribe());
}
@Test // DATAMONGO-1646, DATAMONGO-1311

View File

@@ -29,14 +29,14 @@ import org.springframework.data.mongodb.core.aggregation.ReplaceRootOperation.Re
*/
public class ReplaceRootOperationUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1550
@Test // DATAMONGO-1550
public void rejectsNullField() {
new ReplaceRootOperation((Field) null);
assertThatIllegalArgumentException().isThrownBy(() -> new ReplaceRootOperation((Field) null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1550
@Test // DATAMONGO-1550
public void rejectsNullExpression() {
new ReplaceRootOperation((AggregationExpression) null);
assertThatIllegalArgumentException().isThrownBy(() -> new ReplaceRootOperation((AggregationExpression) null));
}
@Test // DATAMONGO-1550

View File

@@ -30,14 +30,14 @@ public class SampleOperationUnitTests {
private static final String SIZE = "size";
private static final String OP = "$sample";
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1325
@Test // DATAMONGO-1325
public void rejectsNegativeSample() {
new SampleOperation(-1L);
assertThatIllegalArgumentException().isThrownBy(() -> new SampleOperation(-1L));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1325
@Test // DATAMONGO-1325
public void rejectsZeroSample() {
new SampleOperation(0L);
assertThatIllegalArgumentException().isThrownBy(() -> new SampleOperation(0L));
}
@Test // DATAMONGO-1325

View File

@@ -29,9 +29,9 @@ public class SkipOperationUnitTests {
static final String OP = "$skip";
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNegativeSkip() {
new SkipOperation(-1L);
assertThatIllegalArgumentException().isThrownBy(() -> new SkipOperation(-1L));
}
@Test

View File

@@ -18,13 +18,11 @@ package org.springframework.data.mongodb.core.aggregation;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
@@ -45,8 +43,6 @@ public class SpelExpressionTransformerIntegrationTests {
@Autowired MongoDbFactory mongoDbFactory;
@Rule public ExpectedException exception = ExpectedException.none();
SpelExpressionTransformer transformer;
DbRefResolver dbRefResolver;
@@ -69,12 +65,12 @@ public class SpelExpressionTransformerIntegrationTests {
@Test // DATAMONGO-774
public void shouldThrowExceptionIfNestedPropertyCannotBeFound() {
exception.expect(MappingException.class);
exception.expectMessage("value2");
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class,
new MongoMappingContext(), new QueryMapper(converter));
assertThat(transformer.transform("item.value2", ctxt, new Object[0]).toString()).isEqualTo("$item.value2");
assertThatExceptionOfType(InvalidPersistentPropertyPath.class).isThrownBy(() -> {
transformer.transform("item.value2", ctxt, new Object[0]).toString();
});
}
}

View File

@@ -70,9 +70,9 @@ public class SpelExpressionTransformerUnitTests {
assertThat(transform("a % b")).isEqualTo((Object) Document.parse("{ \"$mod\" : [ \"$a\" , \"$b\"]}"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-774
@Test // DATAMONGO-774
public void shouldThrowExceptionOnUnknownOperand() {
transform("a++");
assertThatIllegalArgumentException().isThrownBy(() -> transform("a++"));
}
@Test // DATAMONGO-774

View File

@@ -79,9 +79,9 @@ public class TypeBasedAggregationOperationContextUnitTests {
assertThat(getContext(Foo.class).getReference("bar")).isNotNull();
}
@Test(expected = MappingException.class)
@Test
public void rejectsInvalidFieldReference() {
getContext(Foo.class).getReference("foo");
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> getContext(Foo.class).getReference("foo"));
}
@Test // DATAMONGO-741

View File

@@ -68,14 +68,14 @@ public class DocumentAccessorUnitTests {
assertThat(accessor.get(fooProperty)).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-766
@Test // DATAMONGO-766
public void rejectsNonDocuments() {
new DocumentAccessor(new BsonDocument());
assertThatIllegalArgumentException().isThrownBy(() -> new DocumentAccessor(new BsonDocument()));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-766
@Test // DATAMONGO-766
public void rejectsNullDocument() {
new DocumentAccessor(null);
assertThatIllegalArgumentException().isThrownBy(() -> new DocumentAccessor(null));
}
@Test // DATAMONGO-1335

View File

@@ -20,9 +20,7 @@ import static org.springframework.data.mongodb.test.util.Assertions.*;
import java.util.Arrays;
import org.bson.Document;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -176,7 +174,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonPolygonConverterUnitTests {
DocumentToGeoJsonPolygonConverter converter = DocumentToGeoJsonPolygonConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -190,11 +187,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPolygon() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to Polygon");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
@Test // DATAMONGO-1399
@@ -210,7 +203,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonPointConverterUnitTests {
DocumentToGeoJsonPointConverter converter = DocumentToGeoJsonPointConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -225,10 +217,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPoint() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to Point");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
}
@@ -238,7 +227,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonLineStringConverterUnitTests {
DocumentToGeoJsonLineStringConverter converter = DocumentToGeoJsonLineStringConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -252,11 +240,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPoint() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to LineString");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
}
@@ -266,7 +250,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonMultiLineStringConverterUnitTests {
DocumentToGeoJsonMultiLineStringConverter converter = DocumentToGeoJsonMultiLineStringConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -280,11 +263,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPoint() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to MultiLineString");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
}
@@ -294,7 +273,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonMultiPointConverterUnitTests {
DocumentToGeoJsonMultiPointConverter converter = DocumentToGeoJsonMultiPointConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -308,11 +286,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPoint() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to MultiPoint");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
}
@@ -322,7 +296,6 @@ public class GeoJsonConverterUnitTests {
public static class DocumentToGeoJsonMultiPolygonConverterUnitTests {
DocumentToGeoJsonMultiPolygonConverter converter = DocumentToGeoJsonMultiPolygonConverter.INSTANCE;
public @Rule ExpectedException expectedException = ExpectedException.none();
@Test // DATAMONGO-1137
public void shouldConvertDboCorrectly() {
@@ -336,11 +309,7 @@ public class GeoJsonConverterUnitTests {
@Test // DATAMONGO-1137
public void shouldThrowExceptionWhenTypeDoesNotMatchPoint() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'YouDontKonwMe' to MultiPolygon");
converter.convert(new Document("type", "YouDontKonwMe"));
assertThatIllegalArgumentException().isThrownBy(() -> converter.convert(new Document("type", "YouDontKonwMe")));
}
}

View File

@@ -15,16 +15,14 @@
*/
package org.springframework.data.mongodb.core.convert;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
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.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.mongodb.LazyLoadingException;
@@ -41,8 +39,6 @@ import com.mongodb.DBRef;
@RunWith(MockitoJUnitRunner.class)
public class LazyLoadingInterceptorUnitTests {
public @Rule ExpectedException exception = ExpectedException.none();
@Mock MongoPersistentProperty propertyMock;
@Mock DBRef dbrefMock;
@Mock DbRefResolverCallback callbackMock;
@@ -53,11 +49,10 @@ public class LazyLoadingInterceptorUnitTests {
NullPointerException npe = new NullPointerException("Some Exception we did not think about.");
when(callbackMock.resolve(propertyMock)).thenThrow(npe);
exception.expect(LazyLoadingException.class);
exception.expectCause(is(equalTo(npe)));
new LazyLoadingInterceptor(propertyMock, dbrefMock, new NullExceptionTranslator(), callbackMock).intercept(null,
LazyLoadingProxy.class.getMethod("getTarget"), null, null);
assertThatExceptionOfType(LazyLoadingException.class).isThrownBy(() -> {
new LazyLoadingInterceptor(propertyMock, dbrefMock, new NullExceptionTranslator(), callbackMock).intercept(null,
LazyLoadingProxy.class.getMethod("getTarget"), null, null);
}).withCause(npe);
}
static class NullExceptionTranslator implements PersistenceExceptionTranslator {

View File

@@ -35,9 +35,7 @@ import org.bson.types.ObjectId;
import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -98,8 +96,6 @@ public class MappingMongoConverterUnitTests {
@Mock ApplicationContext context;
@Mock DbRefResolver resolver;
public @Rule ExpectedException exception = ExpectedException.none();
@Before
public void setUp() {
@@ -876,9 +872,10 @@ public class MappingMongoConverterUnitTests {
assertThat(values).contains("1", "2");
}
@Test(expected = MappingException.class) // DATAMONGO-380
@Test // DATAMONGO-380
public void rejectsMapWithKeyContainingDotsByDefault() {
converter.write(Collections.singletonMap("foo.bar", "foobar"), new org.bson.Document());
assertThatExceptionOfType(MappingException.class)
.isThrownBy(() -> converter.write(Collections.singletonMap("foo.bar", "foobar"), new org.bson.Document()));
}
@Test // DATAMONGO-380
@@ -992,7 +989,6 @@ public class MappingMongoConverterUnitTests {
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
assertThat(result.personMap.entrySet()).hasSize(1);
assertThat(result.personMap.values()).anyMatch(Person.class::isInstance);
}
@@ -1581,11 +1577,7 @@ public class MappingMongoConverterUnitTests {
org.bson.Document source = new org.bson.Document("attributes", outer);
exception.expect(MappingException.class);
exception.expectMessage(Item.class.getName());
exception.expectMessage(ArrayList.class.getName());
converter.read(Item.class, source);
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> converter.read(Item.class, source));
}
@Test // DATAMONGO-1058
@@ -1786,11 +1778,8 @@ public class MappingMongoConverterUnitTests {
org.bson.Document nested = new org.bson.Document("key", "value");
org.bson.Document source = new org.bson.Document("map", new org.bson.Document("key", nested));
exception.expect(MappingException.class);
exception.expectMessage(nested.toString());
exception.expectMessage(Long.class.getName());
converter.read(TypeWithMapOfLongValues.class, source);
assertThatExceptionOfType(MappingException.class)
.isThrownBy(() -> converter.read(TypeWithMapOfLongValues.class, source));
}
@Test // DATAMONGO-1831
@@ -2000,7 +1989,7 @@ public class MappingMongoConverterUnitTests {
@Override
void method() {
}
}
};
abstract void method();
@@ -2427,8 +2416,7 @@ public class MappingMongoConverterUnitTests {
@Field(targetType = FieldType.SCRIPT) //
List<String> scripts;
@Field(targetType = FieldType.DECIMAL128)
BigDecimal bigDecimal;
@Field(targetType = FieldType.DECIMAL128) BigDecimal bigDecimal;
}
}

View File

@@ -24,9 +24,8 @@ import java.util.List;
import org.bson.Document;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.schema.MongoJsonSchema;
@@ -38,8 +37,6 @@ import org.springframework.data.mongodb.core.schema.MongoJsonSchema;
*/
public class MongoJsonSchemaMapperUnitTests {
public @Rule ExpectedException exception = ExpectedException.none();
MongoJsonSchemaMapper mapper;
Document addressProperty = new Document("type", "object").append("required", Arrays.asList("street", "postCode"))
@@ -116,26 +113,20 @@ public class MongoJsonSchemaMapperUnitTests {
@Test // DATAMONGO-1835
public void noNullSchemaAllowed() {
exception.expect(IllegalArgumentException.class);
mapper.mapSchema(null, Object.class);
assertThatIllegalArgumentException().isThrownBy(() -> mapper.mapSchema(null, Object.class));
}
@Test // DATAMONGO-1835
public void noNullDomainTypeAllowed() {
exception.expect(IllegalArgumentException.class);
mapper.mapSchema(new Document("$jsonSchema", new Document()), null);
assertThatIllegalArgumentException()
.isThrownBy(() -> mapper.mapSchema(new Document("$jsonSchema", new Document()), null));
}
@Test // DATAMONGO-1835
public void schemaDocumentMustContain$jsonSchemaField() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("contain $jsonSchema");
mapper.mapSchema(new Document("foo", new Document()), Object.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> mapper.mapSchema(new Document("foo", new Document()), Object.class));
}
@Test // DATAMONGO-1835

View File

@@ -28,9 +28,7 @@ import java.util.Locale;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.annotation.Id;
@@ -54,8 +52,6 @@ public class BasicMongoPersistentPropertyUnitTests {
MongoPersistentEntity<Person> entity;
@Rule public ExpectedException exception = ExpectedException.none();
@Before
public void setup() {
entity = new BasicMongoPersistentEntity<Person>(ClassTypeInformation.from(Person.class));
@@ -124,11 +120,8 @@ public class BasicMongoPersistentPropertyUnitTests {
MongoPersistentProperty property = new BasicMongoPersistentProperty(Property.of(type, field), entity,
SimpleTypeHolder.DEFAULT, InvalidFieldNamingStrategy.INSTANCE);
exception.expect(MappingException.class);
exception.expectMessage(InvalidFieldNamingStrategy.class.getName());
exception.expectMessage(property.toString());
property.getFieldName();
assertThatExceptionOfType(MappingException.class).isThrownBy(property::getFieldName)
.withMessageContaining(InvalidFieldNamingStrategy.class.getName()).withMessageContaining(property.toString());
}
@Test // DATAMONGO-937
@@ -139,7 +132,7 @@ public class BasicMongoPersistentPropertyUnitTests {
}
@Test // DATAMONGO-937
public void shouldDetectIplicitLanguagePropertyCorrectly() {
public void shouldDetectImplicitLanguagePropertyCorrectly() {
MongoPersistentProperty property = getPropertyFor(DocumentWithImplicitLanguageProperty.class, "language");
assertThat(property.isLanguageProperty()).isTrue();

View File

@@ -22,17 +22,16 @@ import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mapping.MappingException;
import com.mongodb.DBRef;
@@ -49,8 +48,6 @@ public class MongoMappingContextUnitTests {
@Mock ApplicationContext applicationContext;
@Rule public ExpectedException exception = ExpectedException.none();
@Test
public void addsSelfReferencingPersistentEntityCorrectly() throws Exception {
@@ -93,15 +90,12 @@ public class MongoMappingContextUnitTests {
@Test // DATAMONGO-607
public void rejectsClassWithAmbiguousFieldMappings() {
exception.expect(MappingException.class);
exception.expectMessage("firstname");
exception.expectMessage("lastname");
exception.expectMessage("foo");
exception.expectMessage("@Field");
MongoMappingContext context = new MongoMappingContext();
context.setApplicationContext(applicationContext);
context.getPersistentEntity(InvalidPerson.class);
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> context.getPersistentEntity(InvalidPerson.class))
.withMessageContaining("firstname").withMessageContaining("lastname").withMessageContaining("foo")
.withMessageContaining("@Field");
}
@Test // DATAMONGO-694
@@ -157,13 +151,11 @@ public class MongoMappingContextUnitTests {
@Test // DATAMONGO-976
public void shouldRejectClassWithInvalidTextScoreProperty() {
exception.expect(MappingException.class);
exception.expectMessage("score");
exception.expectMessage("Float");
exception.expectMessage("Double");
MongoMappingContext context = new MongoMappingContext();
context.getPersistentEntity(ClassWithInvalidTextScoreProperty.class);
assertThatExceptionOfType(MappingException.class)
.isThrownBy(() -> context.getPersistentEntity(ClassWithInvalidTextScoreProperty.class))
.withMessageContaining("score").withMessageContaining("Float").withMessageContaining("Double");
}
public class SampleClass {

View File

@@ -66,9 +66,9 @@ public class AuditingEntityCallbackUnitTests {
callback = new AuditingEntityCallback(() -> handler);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-2261
@Test // DATAMONGO-2261
public void rejectsNullAuditingHandler() {
new AuditingEntityCallback(null);
assertThatIllegalArgumentException().isThrownBy(() -> new AuditingEntityCallback(null));
}
@Test // DATAMONGO-2261

View File

@@ -67,9 +67,9 @@ public class AuditingEventListenerUnitTests {
listener = new AuditingEventListener(() -> handler);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-577
@Test // DATAMONGO-577
public void rejectsNullAuditingHandler() {
new AuditingEventListener(null);
assertThatIllegalArgumentException().isThrownBy(() -> new AuditingEventListener(null));
}
@Test // DATAMONGO-577

View File

@@ -49,9 +49,9 @@ public class DefaultMessageListenerContainerUnitTests {
container = new DefaultMessageListenerContainer(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1803
@Test // DATAMONGO-1803
public void throwsErrorOnNullTemplate() {
new DefaultMessageListenerContainer(null);
assertThatIllegalArgumentException().isThrownBy(() -> new DefaultMessageListenerContainer(null));
}
@Test // DATAMONGO-1803

View File

@@ -52,9 +52,9 @@ public class TaskFactoryUnitTests {
factory = new TaskFactory(template);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1803
@Test // DATAMONGO-1803
public void requestMustNotBeNull() {
factory.forRequest(null, Object.class, errorHandler);
assertThatIllegalArgumentException().isThrownBy(() -> factory.forRequest(null, Object.class, errorHandler));
}
@Test // DATAMONGO-1803

View File

@@ -80,28 +80,25 @@ public class CriteriaUnitTests {
assertThat(right).isNotEqualTo(left);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-507
@Test // DATAMONGO-507
public void shouldThrowExceptionWhenTryingToNegateAndOperation() {
new Criteria() //
assertThatIllegalArgumentException().isThrownBy(() -> new Criteria() //
.not() //
.andOperator(Criteria.where("delete").is(true).and("_id").is(42)); //
.andOperator(Criteria.where("delete").is(true).and("_id").is(42)));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-507
@Test // DATAMONGO-507
public void shouldThrowExceptionWhenTryingToNegateOrOperation() {
new Criteria() //
assertThatIllegalArgumentException().isThrownBy(() -> new Criteria() //
.not() //
.orOperator(Criteria.where("delete").is(true).and("_id").is(42)); //
.orOperator(Criteria.where("delete").is(true).and("_id").is(42)));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-507
@Test // DATAMONGO-507
public void shouldThrowExceptionWhenTryingToNegateNorOperation() {
new Criteria() //
assertThatIllegalArgumentException().isThrownBy(() -> new Criteria() //
.not() //
.norOperator(Criteria.where("delete").is(true).and("_id").is(42)); //
.norOperator(Criteria.where("delete").is(true).and("_id").is(42)));
}
@Test // DATAMONGO-507
@@ -204,9 +201,9 @@ public class CriteriaUnitTests {
assertThat(document).containsEntry("foo.$nearSphere.$maxDistance", 100D);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1134
@Test // DATAMONGO-1134
public void intersectsShouldThrowExceptionWhenCalledWihtNullValue() {
new Criteria("foo").intersects(null);
assertThatIllegalArgumentException().isThrownBy(() -> new Criteria("foo").intersects(null));
}
@Test // DATAMONGO-1134

View File

@@ -43,9 +43,9 @@ public class NearQueryUnitTests {
private static final Distance ONE_FIFTY_KILOMETERS = new Distance(150, Metrics.KILOMETERS);
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullPoint() {
NearQuery.near(null);
assertThatIllegalArgumentException().isThrownBy(() -> NearQuery.near(null));
}
@Test
@@ -130,9 +130,9 @@ public class NearQueryUnitTests {
assertThat(query.toDocument().get("num")).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONOGO-829
@Test // DATAMONOGO-829
public void nearQueryShouldThrowExceptionWhenGivenANullQuery() {
NearQuery.near(new Point(1, 2)).query(null);
assertThatIllegalArgumentException().isThrownBy(() -> NearQuery.near(new Point(1, 2)).query(null));
}
@Test // DATAMONGO-829

View File

@@ -55,9 +55,10 @@ public class UntypedExampleMatcherUnitTests {
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.IGNORE);
}
@Test(expected = UnsupportedOperationException.class) // DATAMONGO-1768
public void ignoredPathsIsNotModifiable() throws Exception {
matcher.getIgnoredPaths().add("¯\\_(ツ)_/¯");
@Test // DATAMONGO-1768
public void ignoredPathsIsNotModifiable() {
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> matcher.getIgnoredPaths().add("¯\\_(ツ)_/¯"));
}
@Test // DATAMONGO-1768

View File

@@ -238,19 +238,21 @@ public class UpdateTests {
assertThat(clone.modifies("oof")).isFalse();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-853
@Test // DATAMONGO-853
public void testAddingMultiFieldOperationThrowsExceptionWhenCalledWithNullKey() {
new Update().addMultiFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
assertThatIllegalArgumentException().isThrownBy(
() -> new Update().addMultiFieldOperation("$op", null, "exprected to throw IllegalArgumentException."));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-853
@Test // DATAMONGO-853
public void testAddingSingleFieldOperationThrowsExceptionWhenCalledWithNullKey() {
new Update().addFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
assertThatIllegalArgumentException()
.isThrownBy(() -> new Update().addFieldOperation("$op", null, "exprected to throw IllegalArgumentException."));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-853
@Test // DATAMONGO-853
public void testCreatingUpdateWithNullKeyThrowsException() {
Update.update(null, "value");
assertThatIllegalArgumentException().isThrownBy(() -> Update.update(null, "value"));
}
@Test // DATAMONGO-953
@@ -350,9 +352,9 @@ public class UpdateTests {
assertThat(update.toString()).isNotNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1097
@Test // DATAMONGO-1097
public void multiplyShouldThrowExceptionForNullMultiplier() {
new Update().multiply("key", null);
assertThatIllegalArgumentException().isThrownBy(() -> new Update().multiply("key", null));
}
@Test // DATAMONGO-1097
@@ -405,14 +407,14 @@ public class UpdateTests {
assertThat(pullAll.get("field2")).isNotNull();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1404
@Test // DATAMONGO-1404
public void maxShouldThrowExceptionForNullMultiplier() {
new Update().max("key", null);
assertThatIllegalArgumentException().isThrownBy(() -> new Update().max("key", null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1404
@Test // DATAMONGO-1404
public void minShouldThrowExceptionForNullMultiplier() {
new Update().min("key", null);
assertThatIllegalArgumentException().isThrownBy(() -> new Update().min("key", null));
}
@Test // DATAMONGO-1404

View File

@@ -71,13 +71,13 @@ public class MongoJsonSchemaUnitTests {
new Document("lastname", new Document("type", "string")))));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1835
@Test // DATAMONGO-1835
public void throwsExceptionOnNullRoot() {
MongoJsonSchema.of((JsonSchemaObject) null);
assertThatIllegalArgumentException().isThrownBy(() -> MongoJsonSchema.of((JsonSchemaObject) null));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1835
@Test // DATAMONGO-1835
public void throwsExceptionOnNullDocument() {
MongoJsonSchema.of((Document) null);
assertThatIllegalArgumentException().isThrownBy(() -> MongoJsonSchema.of((Document) null));
}
}

View File

@@ -28,19 +28,19 @@ import org.junit.Test;
*/
public class NamedMongoScriptUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void shouldThrowExceptionWhenScriptNameIsNull() {
new NamedMongoScript(null, "return 1;");
assertThatIllegalArgumentException().isThrownBy(() -> new NamedMongoScript(null, "return 1;"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void shouldThrowExceptionWhenScriptNameIsEmptyString() {
new NamedMongoScript("", "return 1");
assertThatIllegalArgumentException().isThrownBy(() -> new NamedMongoScript("", "return 1"));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-479
@Test // DATAMONGO-479
public void shouldThrowExceptionWhenRawScriptIsEmptyString() {
new NamedMongoScript("foo", "");
assertThatIllegalArgumentException().isThrownBy(() -> new NamedMongoScript("foo", ""));
}
@Test // DATAMONGO-479

View File

@@ -40,8 +40,8 @@ public class CriteriaValidatorUnitTests {
.isEqualTo(new Document("$type", 16).append("$gte", 0).append("$lte", 122));
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1322
@Test // DATAMONGO-1322
public void testFailOnNull() {
CriteriaValidator.of(null);
assertThatIllegalArgumentException().isThrownBy(() -> CriteriaValidator.of(null));
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.data.mongodb.gridfs;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Criteria.*;
import static org.springframework.data.mongodb.core.query.Query.*;
import static org.springframework.data.mongodb.gridfs.GridFsCriteria.*;
@@ -33,6 +33,7 @@ import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -177,9 +178,9 @@ public class GridFsTemplateIntegrationTests {
assertThat(files).hasSize(1).extracting(it -> ((BsonObjectId) it.getId()).getValue()).containsExactly(reference);
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1762
@Test // DATAMONGO-1762
public void queryingWithNullQueryThrowsException() {
operations.find(null);
assertThatIllegalArgumentException().isThrownBy(() -> operations.find(null));
}
@Test // DATAMONGO-813, DATAMONGO-1914

View File

@@ -33,9 +33,7 @@ import java.util.stream.Stream;
import org.bson.Document;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -81,8 +79,6 @@ import org.springframework.test.util.ReflectionTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class AbstractPersonRepositoryIntegrationTests {
public @Rule ExpectedException expectedException = ExpectedException.none();
@Autowired protected PersonRepository repository;
@Autowired MongoOperations operations;
@@ -178,10 +174,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-1608
public void findByFirstnameLikeWithNull() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("property 'firstname'");
repository.findByFirstnameLike(null);
assertThatIllegalArgumentException().isThrownBy(() -> repository.findByFirstnameLike(null));
}
@Test
@@ -649,10 +642,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test // DATAMONGO-1608
public void findByFirstNameIgnoreCaseWithNull() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("property 'firstname'");
repository.findByFirstnameIgnoreCase(null);
assertThatIllegalArgumentException().isThrownBy(() -> repository.findByFirstnameIgnoreCase(null));
}
@Test // DATAMONGO-770
@@ -1164,14 +1154,16 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
assertThat(repository.findFirstBy()).isNotNull();
}
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1865
@Test // DATAMONGO-1865
public void findSingleEntityThrowsErrorWhenNotUnique() {
repository.findPersonByLastnameLike(dave.getLastname());
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> repository.findPersonByLastnameLike(dave.getLastname()));
}
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1865
@Test // DATAMONGO-1865
public void findOptionalSingleEntityThrowsErrorWhenNotUnique() {
repository.findOptionalPersonByLastnameLike(dave.getLastname());
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> repository.findOptionalPersonByLastnameLike(dave.getLastname()));
}
@Test // DATAMONGO-1979

View File

@@ -26,11 +26,10 @@ import org.bson.Document;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -93,8 +92,6 @@ public class PersonRepositoryTransactionalTests {
}
}
public @Rule ExpectedException expectedException = ExpectedException.none();
@Autowired MongoClient client;
@Autowired PersonRepository repository;
@Autowired MongoTemplate template;

View File

@@ -63,14 +63,14 @@ public class ConvertingParameterAccessorUnitTests {
this.converter = new MappingMongoConverter(resolver, context);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullDbRefResolver() {
new MappingMongoConverter((DbRefResolver) null, context);
assertThatIllegalArgumentException().isThrownBy(() -> new MappingMongoConverter((DbRefResolver) null, context));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullContext() {
new MappingMongoConverter(resolver, null);
assertThatIllegalArgumentException().isThrownBy(() -> new MappingMongoConverter(resolver, null));
}
@Test

View File

@@ -28,9 +28,8 @@ import java.util.regex.Pattern;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.geo.Distance;
@@ -74,8 +73,6 @@ public class MongoQueryCreatorUnitTests {
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> context;
MongoConverter converter;
@Rule public ExpectedException expection = ExpectedException.none();
@Before
public void setUp() {
@@ -324,13 +321,11 @@ public class MongoQueryCreatorUnitTests {
@Test // DATAMONGO-770
public void shouldThrowExceptionForQueryWithFindByIgnoreCaseOnNonStringProperty() {
expection.expect(IllegalArgumentException.class);
expection.expectMessage("must be of type String");
PartTree tree = new PartTree("findByFirstNameAndAgeIgnoreCase", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "foo", 42), context);
creator.createQuery();
assertThatIllegalArgumentException().isThrownBy(creator::createQuery)
.withMessageContaining("must be of type String");
}
@Test // DATAMONGO-770
@@ -620,14 +615,12 @@ public class MongoQueryCreatorUnitTests {
@Test // DATAMONGO-1588
public void queryShouldThrowExceptionWhenArgumentDoesNotMatchDeclaration() {
expection.expect(IllegalArgumentException.class);
expection.expectMessage("Expected parameter type of " + Point.class);
PartTree tree = new PartTree("findByLocationNear", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter,
new GeoJsonLineString(new Point(-74.044502D, 40.689247D), new Point(-73.997330D, 40.730824D)));
new MongoQueryCreator(tree, accessor, context).createQuery();
assertThatIllegalArgumentException().isThrownBy(() -> new MongoQueryCreator(tree, accessor, context).createQuery())
.withMessageContaining("Expected parameter type of " + Point.class);
}
@Test // DATAMONGO-2003

View File

@@ -100,9 +100,10 @@ public class MongoQueryMethodUnitTests {
.isTrue();
}
@Test(expected = IllegalArgumentException.class)
public void rejectsGeoPageQueryWithoutPageable() throws Exception {
queryMethod(PersonRepository.class, "findByLocationNear", Point.class, Distance.class);
@Test
public void rejectsGeoPageQueryWithoutPageable() {
assertThatIllegalArgumentException()
.isThrownBy(() -> queryMethod(PersonRepository.class, "findByLocationNear", Point.class, Distance.class));
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -25,9 +25,7 @@ import java.util.List;
import org.bson.Document;
import org.bson.json.JsonParseException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -68,8 +66,6 @@ public class PartTreeMongoQueryUnitTests {
MongoMappingContext mappingContext;
public @Rule ExpectedException exception = ExpectedException.none();
@Before
public void setUp() {
@@ -84,10 +80,8 @@ public class PartTreeMongoQueryUnitTests {
@Test // DATAMOGO-952
public void rejectsInvalidFieldSpecification() {
exception.expect(IllegalStateException.class);
exception.expectMessage("findByLastname");
deriveQueryFromMethod("findByLastname", "foo");
assertThatIllegalStateException().isThrownBy(() -> deriveQueryFromMethod("findByLastname", "foo"))
.withMessageContaining("findByLastname");
}
@Test // DATAMOGO-952

View File

@@ -110,9 +110,10 @@ public class ReactiveMongoQueryMethodUnitTests {
new SpelAwareProxyProjectionFactory(), null);
}
@Test(expected = IllegalStateException.class) // DATAMONGO-1444
public void rejectsMonoPageableResult() throws Exception {
queryMethod(PersonRepository.class, "findMonoByLastname", String.class, Pageable.class);
@Test // DATAMONGO-1444
public void rejectsMonoPageableResult() {
assertThatIllegalStateException()
.isThrownBy(() -> queryMethod(PersonRepository.class, "findMonoByLastname", String.class, Pageable.class));
}
@Test // DATAMONGO-1444
@@ -138,14 +139,16 @@ public class ReactiveMongoQueryMethodUnitTests {
assertThat(method.getQueryMetaAttributes().getMaxTimeMsec()).isEqualTo(100L);
}
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-1444
public void throwsExceptionOnWrappedPage() throws Exception {
queryMethod(PersonRepository.class, "findMonoPageByLastname", String.class, Pageable.class);
@Test // DATAMONGO-1444
public void throwsExceptionOnWrappedPage() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> queryMethod(PersonRepository.class, "findMonoPageByLastname", String.class, Pageable.class));
}
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-1444
public void throwsExceptionOnWrappedSlice() throws Exception {
queryMethod(PersonRepository.class, "findMonoSliceByLastname", String.class, Pageable.class);
@Test // DATAMONGO-1444
public void throwsExceptionOnWrappedSlice() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> queryMethod(PersonRepository.class, "findMonoSliceByLastname", String.class, Pageable.class));
}
@Test // DATAMONGO-1444

View File

@@ -115,9 +115,9 @@ public class ReactiveStringBasedMongoQueryUnitTests {
assertThat(mongoQuery.isDeleteQuery()).isTrue();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1444
public void preventsDeleteAndCountFlagAtTheSameTime() throws Exception {
createQueryForMethod("invalidMethod", String.class);
@Test // DATAMONGO-1444
public void preventsDeleteAndCountFlagAtTheSameTime() {
assertThatIllegalArgumentException().isThrownBy(() -> createQueryForMethod("invalidMethod", String.class));
}
@Test // DATAMONGO-2030

View File

@@ -16,7 +16,7 @@
package org.springframework.data.mongodb.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
@@ -36,6 +36,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.DocumentTestUtils;
import org.springframework.data.mongodb.core.ExecutableFindOperation.ExecutableFind;
import org.springframework.data.mongodb.core.MongoOperations;
@@ -162,9 +163,9 @@ public class StringBasedMongoQueryUnitTests {
assertThat(mongoQuery.isDeleteQuery()).isTrue();
}
@Test(expected = IllegalArgumentException.class) // DATAMONGO-566
@Test // DATAMONGO-566
public void preventsDeleteAndCountFlagAtTheSameTime() {
createQueryForMethod("invalidMethod", String.class);
assertThatIllegalArgumentException().isThrownBy(() -> createQueryForMethod("invalidMethod", String.class));
}
@Test // DATAMONGO-420
@@ -755,7 +756,8 @@ public class StringBasedMongoQueryUnitTests {
@Query("{ 'arg0' : '?0', 'arg1' : '?1s' }")
List<Person> findByWhenQuotedAndSomeStuffAppended(String arg0, String arg1);
@Query("{ 'lastname' : { '$regex' : '^(?0|John ?1|?1)'} }") // use spel or some regex string this is bad
@Query("{ 'lastname' : { '$regex' : '^(?0|John ?1|?1)'} }")
// use spel or some regex string this is bad
Person findByLastnameRegex(String lastname, String alternative);
@Query("{ arg0 : ?#{[0]} }")

View File

@@ -108,9 +108,10 @@ public class QuerydslMongoPredicateExecutorIntegrationTests {
assertThat(repository.findOne(person.firstname.eq("batman"))).isNotPresent();
}
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1690
@Test // DATAMONGO-1690
public void findOneWithPredicateThrowsExceptionForNonUniqueResults() {
repository.findOne(person.firstname.contains("e"));
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> repository.findOne(person.firstname.contains("e")));
}
@Test // DATAMONGO-1848
@@ -205,7 +206,8 @@ public class QuerydslMongoPredicateExecutorIntegrationTests {
assertThat(result).containsExactly(person2);
}
@Test(expected = PermissionDeniedDataAccessException.class) // DATAMONGO-1434, DATAMONGO-1848
@Test(expected = PermissionDeniedDataAccessException.class)
// DATAMONGO-1434, DATAMONGO-1848
public void translatesExceptionsCorrectly() {
MongoOperations ops = new MongoTemplate(dbFactory) {