From 56e3a95b2a92f2ba0f1c8c9fb92ccfcd91a39acd Mon Sep 17 00:00:00 2001 From: Benedikt Waldvogel Date: Sun, 15 Nov 2026 22:49:15 +0100 Subject: [PATCH 1/2] Remove redundant throws declarations from tests Remove unnecessary checked-exception declarations from tests, shared fixtures and backend factories. Keep declarations required for I/O, SSL and asynchronous operations, and update the example test in the README. --- README.md | 2 +- .../bwaldvogel/mongo/ServerVersionTest.java | 2 +- .../backend/AbstractMongoCollectionTest.java | 6 +- .../mongo/backend/ArrayFiltersTest.java | 24 +- .../bwaldvogel/mongo/backend/AssertTest.java | 22 +- .../mongo/backend/CollectionUtilsTest.java | 14 +- .../backend/DefaultQueryMatcherTest.java | 120 ++++---- .../mongo/backend/DocumentComparatorTest.java | 2 +- .../mongo/backend/EmptyCursorTest.java | 2 +- .../mongo/backend/InMemoryCursorTest.java | 2 +- .../mongo/backend/KeyValueTest.java | 4 +- .../mongo/backend/LinkedTreeSetTest.java | 24 +- .../bwaldvogel/mongo/backend/MissingTest.java | 2 +- .../mongo/backend/ProjectionTest.java | 14 +- .../mongo/backend/StreamUtilsTest.java | 6 +- .../bwaldvogel/mongo/backend/UtilsTest.java | 38 +-- .../mongo/backend/ValueComparatorTest.java | 22 +- .../backend/aggregation/ExpressionTest.java | 154 +++++----- .../accumulator/MaxAccumulatorTest.java | 8 +- .../accumulator/MinAccumulatorTest.java | 8 +- .../aggregation/stage/AddFieldsStageTest.java | 4 +- .../aggregation/stage/LookupStageTest.java | 4 +- .../aggregation/stage/ProjectStageTest.java | 10 +- .../stage/ReplaceRootStageTest.java | 4 +- .../aggregation/stage/UnsetStageTest.java | 8 +- .../aggregation/stage/UnwindStageTest.java | 6 +- .../mongo/bson/BsonJavaScriptTest.java | 2 +- .../mongo/bson/BsonRegularExpressionTest.java | 8 +- .../mongo/bson/BsonTimestampTest.java | 4 +- .../bwaldvogel/mongo/bson/Decimal128Test.java | 14 +- .../bwaldvogel/mongo/bson/DocumentTest.java | 22 +- .../de/bwaldvogel/mongo/bson/JsonTest.java | 4 +- .../bwaldvogel/mongo/bson/LegacyUUIDTest.java | 4 +- .../bwaldvogel/mongo/bson/ObjectIdTest.java | 10 +- .../exception/MongoServerExceptionTest.java | 2 +- .../mongo/wire/MongoDatabaseHandlerTest.java | 10 +- .../wire/MongoWireMessageEncoderTest.java | 4 +- .../mongo/wire/MongoWireReplyEncoderTest.java | 4 +- .../mongo/wire/bson/BsonDecoderTest.java | 4 +- .../mongo/wire/bson/BsonEncoderTest.java | 4 +- examples/src/main/java/SimpleJUnit5Test.java | 2 +- .../mongo/H2BackendMongoServerTest.java | 2 +- .../mongo/H2BackendReadOnlyProxyTest.java | 2 +- .../mongo/backend/memory/H2BackendTest.java | 2 +- .../backend/memory/H2OnDiskBackendTest.java | 12 +- .../mongo/backend/memory/H2OplogTest.java | 2 +- .../bwaldvogel/mongo/backend/IndexTest.java | 14 +- .../memory/MemoryBackendAggregationTest.java | 2 +- .../memory/index/MemoryUniqueIndexTest.java | 10 +- .../postgresql/PostgresqlCollectionTest.java | 2 +- .../postgresql/PostgresqlUtilsTest.java | 4 +- .../index/PostgresUniqueIndexTest.java | 4 +- .../bwaldvogel/AbstractReadOnlyProxyTest.java | 30 +- .../de/bwaldvogel/mongo/MongoServerTest.java | 22 +- .../backend/AbstractAggregationTest.java | 262 +++++++++--------- .../AbstractBackendSpringDataTest.java | 12 +- .../mongo/backend/AbstractOplogTest.java | 4 +- .../backend/AbstractPerformanceTest.java | 2 +- .../mongo/backend/AbstractTest.java | 10 +- .../mongo/RealMongoAggregationTest.java | 6 +- .../mongo/RealMongoBackendTest.java | 4 +- .../bwaldvogel/mongo/RealMongoContainer.java | 4 +- .../mongo/RealMongoPerformanceTest.java | 6 +- 63 files changed, 514 insertions(+), 514 deletions(-) diff --git a/README.md b/README.md index 519d56b7c..ba6580b85 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ class SimpleTest { } @Test - void testSimpleInsertQuery() throws Exception { + void testSimpleInsertQuery() { assertThat(collection.countDocuments()).isZero(); // creates the database and collection in memory and insert the object diff --git a/core/src/test/java/de/bwaldvogel/mongo/ServerVersionTest.java b/core/src/test/java/de/bwaldvogel/mongo/ServerVersionTest.java index 0d9198cc0..1e72c12d8 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/ServerVersionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/ServerVersionTest.java @@ -7,7 +7,7 @@ class ServerVersionTest { @Test - void testToVersionString() throws Exception { + void testToVersionString() { assertThat(ServerVersion.MONGO_3_6.toVersionString()).isEqualTo("3.6.0"); assertThat(ServerVersion.MONGO_4_0.toVersionString()).isEqualTo("4.0.0"); assertThat(ServerVersion.MONGO_4_2.toVersionString()).isEqualTo("4.2.0"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/AbstractMongoCollectionTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/AbstractMongoCollectionTest.java index 8517e8903..1f5fb30df 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/AbstractMongoCollectionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/AbstractMongoCollectionTest.java @@ -79,7 +79,7 @@ void setUp() { } @Test - void testConvertSelector() throws Exception { + void testConvertSelector() { assertThat(collection.convertSelectorToDocument(json(""))) .isEqualTo(json("")); @@ -97,7 +97,7 @@ void testConvertSelector() throws Exception { } @Test - void testDeriveDocumentId() throws Exception { + void testDeriveDocumentId() { assertThat(collection.deriveDocumentId(json(""))).isInstanceOf(ObjectId.class); assertThat(collection.deriveDocumentId(json("a: 1"))).isInstanceOf(ObjectId.class); assertThat(collection.deriveDocumentId(json("_id: 1"))).isEqualTo(1); @@ -106,7 +106,7 @@ void testDeriveDocumentId() throws Exception { } @Test - void testValidateUpdateQuery() throws Exception { + void testValidateUpdateQuery() { AbstractMongoCollection.validateUpdateQuery(new Document()); AbstractMongoCollection.validateUpdateQuery(json("$set: {a: 1, b: 1}")); AbstractMongoCollection.validateUpdateQuery(json("$set: {a: 1, b: 1}, $inc: {c: 1}")); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/ArrayFiltersTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/ArrayFiltersTest.java index 0274d7d5d..c313fd77c 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/ArrayFiltersTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/ArrayFiltersTest.java @@ -16,7 +16,7 @@ public class ArrayFiltersTest { @Test - void testParseAndCalculateKeys_Simple() throws Exception { + void testParseAndCalculateKeys_Simple() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'values.$[x]': 20}"); @@ -27,7 +27,7 @@ void testParseAndCalculateKeys_Simple() throws Exception { } @Test - void testParseAndCalculateKeys_Subdocument() throws Exception { + void testParseAndCalculateKeys_Subdocument() { Document query = json("arrayFilters: [{'elem.name': {$in: ['A', 'B']}}]"); Document updateQuery = json("$set: {'values.$[elem].active': true}"); @@ -43,7 +43,7 @@ void testParseAndCalculateKeys_Subdocument() throws Exception { } @Test - void testParseAndCalculateKeys_NestedSubdocument() throws Exception { + void testParseAndCalculateKeys_NestedSubdocument() { Document query = json("arrayFilters: [{'elem.name': {$in: ['B', 'C']}}]"); Document updateQuery = json("$set: {'a.b.$[elem].active': true}"); @@ -59,7 +59,7 @@ void testParseAndCalculateKeys_NestedSubdocument() throws Exception { } @Test - void testParseAndCalculateKeys_PathDoesNotExist() throws Exception { + void testParseAndCalculateKeys_PathDoesNotExist() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'a.b.$[x]': 20}"); @@ -71,7 +71,7 @@ void testParseAndCalculateKeys_PathDoesNotExist() throws Exception { } @Test - void testParseAndCalculateKeys_TopLevelPathDoesNotExist() throws Exception { + void testParseAndCalculateKeys_TopLevelPathDoesNotExist() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'a.b.$[x]': 20}"); @@ -83,7 +83,7 @@ void testParseAndCalculateKeys_TopLevelPathDoesNotExist() throws Exception { } @Test - void testParseAndCalculateKeys_NonArray() throws Exception { + void testParseAndCalculateKeys_NonArray() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'a.b.$[x]': 20}"); @@ -95,7 +95,7 @@ void testParseAndCalculateKeys_NonArray() throws Exception { } @Test - void testParseAndCalculateKeys_PositionalAll() throws Exception { + void testParseAndCalculateKeys_PositionalAll() { Document query = json(""); Document updateQuery = json("$set: {'values.$[].active': true}"); @@ -108,7 +108,7 @@ void testParseAndCalculateKeys_PositionalAll() throws Exception { } @Test - void testParseAndCalculateKeys_PositionalAllAndElementFilter() throws Exception { + void testParseAndCalculateKeys_PositionalAllAndElementFilter() { Document query = json("arrayFilters: [{element: {$gte: 3}}]"); Document updateQuery = json("$inc: {'grades.$[].x.$[element]': 1}"); @@ -127,7 +127,7 @@ void testParseAndCalculateKeys_PositionalAllAndElementFilter() throws Exception } @Test - void testParse_FilterNotUsed() throws Exception { + void testParse_FilterNotUsed() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'a.b': 20}"); @@ -137,7 +137,7 @@ void testParse_FilterNotUsed() throws Exception { } @Test - void testParseAndCalculateKeys_TopLevelFilter() throws Exception { + void testParseAndCalculateKeys_TopLevelFilter() { Document query = json("arrayFilters: [{x: {$gt: 20}}]"); Document updateQuery = json("$set: {'$[x]': 20}"); @@ -149,7 +149,7 @@ void testParseAndCalculateKeys_TopLevelFilter() throws Exception { } @Test - void testParse_MultipleFilters() throws Exception { + void testParse_MultipleFilters() { Document query = json("arrayFilters: [{x: {$gt: 20}}, {y: {$lt: 10}}]"); Document updateQuery = json("$set: {'values.$[x]': 20, 'values.$[y]': 30}"); @@ -162,7 +162,7 @@ void testParse_MultipleFilters() throws Exception { } @Test - void testParse_MultipleSubdocumentFieldsInOneFilter() throws Exception { + void testParse_MultipleSubdocumentFieldsInOneFilter() { Document query = json("arrayFilters: [{'a.x': {$gt: 20}, 'a.y': {$lt: 30}}]"); Document updateQuery = json("$set: {'values.$[a].amount': 20}"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/AssertTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/AssertTest.java index d6e2516f1..a613b46b9 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/AssertTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/AssertTest.java @@ -11,7 +11,7 @@ public class AssertTest { @Test - void testIsEmpty() throws Exception { + void testIsEmpty() { Assert.isEmpty(Collections.emptyList()); Assert.isEmpty(Collections.emptySet()); Assert.isEmpty(new ArrayList<>()); @@ -26,7 +26,7 @@ void testIsEmpty() throws Exception { } @Test - void testNotEmpty() throws Exception { + void testNotEmpty() { Assert.notEmpty(List.of("a", "b", "c")); assertThatExceptionOfType(IllegalArgumentException.class) @@ -39,7 +39,7 @@ void testNotEmpty() throws Exception { } @Test - void testHasSize() throws Exception { + void testHasSize() { Assert.hasSize(List.of("a", "b", "c"), 3); assertThatExceptionOfType(IllegalArgumentException.class) @@ -52,7 +52,7 @@ void testHasSize() throws Exception { } @Test - void testEquals() throws Exception { + void testEquals() { Assert.equals(null, null); Assert.equals("a", "a"); Assert.equals(123, 123); @@ -75,7 +75,7 @@ void testEquals() throws Exception { } @Test - void testIsTrue() throws Exception { + void testIsTrue() { Assert.isTrue(true, () -> ""); assertThatExceptionOfType(IllegalArgumentException.class) @@ -84,7 +84,7 @@ void testIsTrue() throws Exception { } @Test - void testIsFalse() throws Exception { + void testIsFalse() { Assert.isFalse(false, () -> ""); assertThatExceptionOfType(IllegalArgumentException.class) @@ -93,7 +93,7 @@ void testIsFalse() throws Exception { } @Test - void testIsNull() throws Exception { + void testIsNull() { Assert.isNull(null); assertThatExceptionOfType(IllegalArgumentException.class) @@ -106,7 +106,7 @@ void testIsNull() throws Exception { } @Test - void testNotNull() throws Exception { + void testNotNull() { Assert.notNull(""); assertThatExceptionOfType(IllegalArgumentException.class) @@ -119,7 +119,7 @@ void testNotNull() throws Exception { } @Test - void testStartsWith() throws Exception { + void testStartsWith() { Assert.startsWith("abc", "ab"); assertThatExceptionOfType(IllegalArgumentException.class) @@ -132,7 +132,7 @@ void testStartsWith() throws Exception { } @Test - void testDoesNotStartWith() throws Exception { + void testDoesNotStartWith() { Assert.doesNotStartWith("a", "b"); assertThatExceptionOfType(IllegalArgumentException.class) @@ -145,7 +145,7 @@ void testDoesNotStartWith() throws Exception { } @Test - void testNotNullOrEmpty() throws Exception { + void testNotNullOrEmpty() { Assert.notNullOrEmpty("a"); assertThatExceptionOfType(IllegalArgumentException.class) diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/CollectionUtilsTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/CollectionUtilsTest.java index ef1843599..b2f3ffe34 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/CollectionUtilsTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/CollectionUtilsTest.java @@ -17,7 +17,7 @@ public class CollectionUtilsTest { @Test - void testGetSingleElement() throws Exception { + void testGetSingleElement() { assertThat(CollectionUtils.getSingleElement(List.of(1))).isEqualTo(1); assertThatExceptionOfType(IllegalArgumentException.class) @@ -34,7 +34,7 @@ void testGetSingleElement() throws Exception { } @Test - void testGetLastElement() throws Exception { + void testGetLastElement() { assertThat(CollectionUtils.getLastElement(List.of(1))).isEqualTo(1); assertThat(CollectionUtils.getLastElement(List.of(1, 2, 3))).isEqualTo(3); @@ -44,7 +44,7 @@ void testGetLastElement() throws Exception { } @Test - void testGetSingleElement_exceptionSupplier() throws Exception { + void testGetSingleElement_exceptionSupplier() { Supplier exceptionSupplier = () -> new MongoServerException("too many elements"); assertThat(CollectionUtils.getSingleElement(List.of(1), exceptionSupplier)).isEqualTo(1); @@ -59,7 +59,7 @@ void testGetSingleElement_exceptionSupplier() throws Exception { } @Test - void testMultiplyWithOtherElements() throws Exception { + void testMultiplyWithOtherElements() { List values = List.of(1, 2); List collection = List.of("abc", "def", values); @@ -84,7 +84,7 @@ void testMultiplyWithOtherElements() throws Exception { } @Test - void testMultiplyWithOtherElementsWrongSize() throws Exception { + void testMultiplyWithOtherElementsWrongSize() { List smallValues = List.of(1, 2); List bigValues = List.of(1, 2, 3); List collection = List.of("abc", "def", smallValues, bigValues); @@ -95,7 +95,7 @@ void testMultiplyWithOtherElementsWrongSize() throws Exception { } @Test - void testGetElementAtPosition_list() throws Exception { + void testGetElementAtPosition_list() { List list = List.of("a", "b", "c"); assertThat(CollectionUtils.getElementAtPosition(list, 0)).isEqualTo("a"); assertThat(CollectionUtils.getElementAtPosition(list, 1)).isEqualTo("b"); @@ -112,7 +112,7 @@ void testGetElementAtPosition_list() throws Exception { } @Test - void testGetElementAtPosition_set() throws Exception { + void testGetElementAtPosition_set() { Set set = new LinkedHashSet<>(); set.add("a"); set.add("b"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcherTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcherTest.java index bebde61ee..da9f1a289 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcherTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcherTest.java @@ -45,21 +45,21 @@ class DefaultQueryMatcherTest { private final QueryMatcher matcher = new DefaultQueryMatcher(); @Test - void testMatchesSimple() throws Exception { + void testMatchesSimple() { assertThat(matcher.matches(json(""), json(""))).isTrue(); assertThat(matcher.matches(json(""), json("foo: 'bar'"))).isFalse(); assertThat(matcher.matches(json("foo: 'bar'"), json("foo: 'bar'"))).isTrue(); } @Test - void testIllegalQuery() throws Exception { + void testIllegalQuery() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> matcher.matches(json(""), json("x: {$lt: 10, y: 23}"))) .withMessage("[Error 2] unknown operator: y"); } @Test - void testLegalQueryWithOperatorAndWithoutOperator() throws Exception { + void testLegalQueryWithOperatorAndWithoutOperator() { List documents = List.of( json(""), json("x: 23"), @@ -75,13 +75,13 @@ void testLegalQueryWithOperatorAndWithoutOperator() throws Exception { } @Test - void testMatchesNullOrMissing() throws Exception { + void testMatchesNullOrMissing() { assertThat(matcher.matches(json("x: null"), json("x: null"))).isTrue(); assertThat(matcher.matches(json(""), json("x: null"))).isTrue(); } @Test - void testMatchesPattern() throws Exception { + void testMatchesPattern() { Document document = json("name: 'john'"); assertThat(matcher.matches(document, map("name", regex("jo.*")))).isTrue(); assertThat(matcher.matches(document, map("name", regex("Jo.*", "i")))).isTrue(); @@ -106,7 +106,7 @@ void testMatchesPattern() throws Exception { } @Test - void testMatchesInQuery() throws Exception { + void testMatchesInQuery() { Document query = map("a", in(3, 2, 1)); assertThat(matcher.matches(json(""), query)).isFalse(); assertThat(matcher.matches(json("a: 'x'"), query)).isFalse(); @@ -119,7 +119,7 @@ void testMatchesInQuery() throws Exception { } @Test - void testMatchesGreaterThanQuery() throws Exception { + void testMatchesGreaterThanQuery() { assertThat(matcher.matches(json(""), map("a", gt(-1)))).isFalse(); assertThat(matcher.matches(json("a: 1"), map("a", gt(0.9)))).isTrue(); assertThat(matcher.matches(json("a: 1"), map("a", gt(0)))).isTrue(); @@ -130,7 +130,7 @@ void testMatchesGreaterThanQuery() throws Exception { } @Test - void testMatchesLessThanQuery() throws Exception { + void testMatchesLessThanQuery() { assertThat(matcher.matches(json(""), map("a", lt(-1)))).isFalse(); assertThat(matcher.matches(json("a: 1"), map("a", lt(1.001)))).isTrue(); assertThat(matcher.matches(json("a: 1"), map("a", lt(2)))).isTrue(); @@ -141,7 +141,7 @@ void testMatchesLessThanQuery() throws Exception { } @Test - void testMatchesLessThanAndGreaterThanQuery() throws Exception { + void testMatchesLessThanAndGreaterThanQuery() { Document query = json("x: { $lt : { n: 'a' , t: 10}, $gt: { n: 'a', t: 1}}}"); assertThat(matcher.matches(json("x: {n: 'a', t: 1}"), query)).isFalse(); @@ -150,7 +150,7 @@ void testMatchesLessThanAndGreaterThanQuery() throws Exception { } @Test - void testMatchesValueList() throws Exception { + void testMatchesValueList() { Document document = json("a: [1, 2, 3]"); assertThat(matcher.matches(document, json(""))).isTrue(); assertThat(matcher.matches(document, json("a: 1"))).isTrue(); @@ -160,7 +160,7 @@ void testMatchesValueList() throws Exception { } @Test - void testMatchesLists() throws Exception { + void testMatchesLists() { assertThat(matcher.matches(json("a: [2, 1]"), json("a: [2, 1]"))).isTrue(); assertThat(matcher.matches(json("a: [2, 1]"), json("a: [2, 1.0]"))).isTrue(); assertThat(matcher.matches(json("a: [2.0, 1]"), json("a: [2, 1.0]"))).isTrue(); @@ -168,7 +168,7 @@ void testMatchesLists() throws Exception { } @Test - void testMatchesDocumentList() throws Exception { + void testMatchesDocumentList() { Document document = json("_id: 1, c: [{a: 1, b: 2}, {a: 3, b: 4}]"); assertThat(matcher.matches(document, json(""))).isTrue(); @@ -182,7 +182,7 @@ void testMatchesDocumentList() throws Exception { } @Test - void testMatchesSubquery() throws Exception { + void testMatchesSubquery() { Document document = json("c: {a: 1}"); assertThat(matcher.matches(document, json(""))).isTrue(); assertThat(matcher.matches(document, json("c: 1"))).isFalse(); @@ -201,7 +201,7 @@ void testMatchesSubquery() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/35 @Test - void testMatchesMissingEmbeddedDocument() throws Exception { + void testMatchesMissingEmbeddedDocument() { assertThat(matcher.matches(json(""), json("b: {c: null}"))).isFalse(); assertThat(matcher.matches(json("b: null"), json("b: {c: null}"))).isFalse(); assertThat(matcher.matches(json("b: null"), json("'b.c': null"))).isTrue(); @@ -221,7 +221,7 @@ void testMatchesMissingEmbeddedDocument() throws Exception { } @Test - void testMatchesEmbeddedDocument() throws Exception { + void testMatchesEmbeddedDocument() { assertThat(matcher.matches(json("b: {c: 1, d: 2}"), json("b: {c: 1}"))).isFalse(); assertThat(matcher.matches(json("b: {c: 1}"), json("b: {c: 1, d: 1}"))).isFalse(); assertThat(matcher.matches(json("b: {c: 0}"), json("b: {c: 0}"))).isTrue(); @@ -236,7 +236,7 @@ void testMatchesEmbeddedDocument() throws Exception { } @Test - void testMatchesSubqueryList() throws Exception { + void testMatchesSubqueryList() { Document document = json("c: {a: [1, 2, 3]}"); assertThat(matcher.matches(document, json(""))).isTrue(); @@ -253,7 +253,7 @@ void testMatchesSubqueryList() throws Exception { } @Test - void testMatchesSubqueryListPosition() throws Exception { + void testMatchesSubqueryListPosition() { Document document = json("c: {a: [1, 2, 3]}"); assertThat(matcher.matches(document, json(""))).isTrue(); assertThat(matcher.matches(document, json("c: 1"))).isFalse(); @@ -272,7 +272,7 @@ void testMatchesSubqueryListPosition() throws Exception { } @Test - void testInvalidOperator() throws Exception { + void testInvalidOperator() { Document document = json(""); Document query = json("field: {$someInvalidOperator: 123}"); @@ -282,7 +282,7 @@ void testInvalidOperator() throws Exception { } @Test - void testMatchesExists() throws Exception { + void testMatchesExists() { Document query = json("qty: {$exists: true, $nin: [5, 15]}"); assertThat(matcher.matches(json(""), query)).isFalse(); assertThat(matcher.matches(json("qty: 17"), query)).isTrue(); @@ -299,7 +299,7 @@ void testMatchesExists() throws Exception { } @Test - void testMatchesExistsArray() throws Exception { + void testMatchesExistsArray() { assertThat(matcher.matches(json("a: ['X', 'Y', 'Z']"), json("'a.1': {$exists: true}"))).isTrue(); assertThat(matcher.matches(json("a: ['X', 'Y', 'Z']"), json("'a.5': {$exists: true}"))).isFalse(); assertThat(matcher.matches(json("a: ['X', 'Y', 'Z']"), json("'a.5': {$exists: false}"))).isTrue(); @@ -322,7 +322,7 @@ void testMatchesExistsArray() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/53 @Test - void testMatchesExistsTrailingDot() throws Exception { + void testMatchesExistsTrailingDot() { assertThat(matcher.matches(json("a: ['X', 'Y', 'Z']"), json("'a.': {$exists: true}"))).isTrue(); assertThat(matcher.matches(json("a: ['X', 'Y', 'Z']"), json("'a..': {$exists: true}"))).isFalse(); assertThat(matcher.matches(json("a: 123"), json("'a.': {$exists: true}"))).isFalse(); @@ -333,7 +333,7 @@ void testMatchesExistsTrailingDot() throws Exception { } @Test - void testMatchesNotEqual() throws Exception { + void testMatchesNotEqual() { Document document = json(""); Document query = json("qty: {$ne: 17}"); @@ -349,7 +349,7 @@ void testMatchesNotEqual() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/220 @Test - void testMatchesNeFieldInArray() throws Exception { + void testMatchesNeFieldInArray() { Document query = json("'tags.value': {$ne: 'B'}"); Document document = json("_id: 1, tags: [{'value': 'A'}, {'value': 'D'}]"); @@ -361,7 +361,7 @@ void testMatchesNeFieldInArray() throws Exception { // http://docs.mongodb.org/v3.0/reference/operator/query/eq/#op._S_eq @Test - void testMatchesEqual() throws Exception { + void testMatchesEqual() { Document document1 = json("_id: 1, item: {name: 'ab', code: '123'}, qty: 15, tags: ['A', 'B', 'C']"); Document document2 = json("_id: 2, item: {name: 'cd', code: '123'}, qty: 20, tags: ['B']"); Document document3 = json("_id: 3, item: {name: 'ij', code: '456'}, qty: 25, tags: ['A', 'B']"); @@ -379,7 +379,7 @@ void testMatchesEqual() throws Exception { // http://docs.mongodb.org/v3.0/reference/operator/query/eq/#op._S_eq @Test - void testMatchesEqualEmbeddedDocument() throws Exception { + void testMatchesEqualEmbeddedDocument() { Document document1 = json("_id: 1, item: {name: 'ab', code: '123'}, qty: 15, tags: ['A', 'B', 'C']"); Document document2 = json("_id: 2, item: {name: 'cd', code: '123'}, qty: 20, tags: ['B']"); Document document3 = json("_id: 3, item: {name: 'ij', code: '456'}, qty: 25, tags: ['A', 'B']"); @@ -397,7 +397,7 @@ void testMatchesEqualEmbeddedDocument() throws Exception { // http://docs.mongodb.org/v3.0/reference/operator/query/eq/#op._S_eq @Test - void testMatchesEqualOneArrayValue() throws Exception { + void testMatchesEqualOneArrayValue() { Document document1 = json("_id: 1, item: {name: 'ab', code: '123'}, qty: 15, tags: ['A', 'B', 'C']"); Document document2 = json("_id: 2, item: {name: 'cd', code: '123'}, qty: 20, tags: ['B']"); Document document3 = json("_id: 3, item: {name: 'ij', code: '456'}, qty: 25, tags: ['A', 'B']"); @@ -415,7 +415,7 @@ void testMatchesEqualOneArrayValue() throws Exception { // http://docs.mongodb.org/v3.0/reference/operator/query/eq/#op._S_eq @Test - void testMatchesEqualTwoArrayValues() throws Exception { + void testMatchesEqualTwoArrayValues() { Document document1 = json("_id: 1, item: {name: 'ab', code: '123'}, qty: 15, tags: ['A', 'B', 'C']"); Document document2 = json("_id: 2, item: {name: 'cd', code: '123'}, qty: 20, tags: ['B']"); Document document3 = json("_id: 3, item: {name: 'ij', code: '456'}, qty: 25, tags: ['A', 'B']"); @@ -433,7 +433,7 @@ void testMatchesEqualTwoArrayValues() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/45 @Test - void testMatchesNotEqualArrayValue() throws Exception { + void testMatchesNotEqualArrayValue() { assertThat(matcher.matches(json("a: [-1]"), json("a: {$ne: 0}"))).isTrue(); assertThat(matcher.matches(json("a: -1"), json("a: {$ne: 0}"))).isTrue(); @@ -445,7 +445,7 @@ void testMatchesNotEqualArrayValue() throws Exception { } @Test - void testMatchNotEqualArray() throws Exception { + void testMatchNotEqualArray() { assertThat(matcher.matches(json("a: []"), json("a: {$ne: []}"))).isFalse(); assertThat(matcher.matches(json("a: null"), json("a: {$ne: []}"))).isTrue(); assertThat(matcher.matches(json(""), json("a: {$ne: []}"))).isTrue(); @@ -456,7 +456,7 @@ void testMatchNotEqualArray() throws Exception { } @Test - void testMatchesNotEqualAndSize() throws Exception { + void testMatchesNotEqualAndSize() { assertThat(matcher.matches(json("a: [1, 2]"), json("a: {$ne: [1, 3], $size: 2}"))).isTrue(); assertThat(matcher.matches(json("a: [1, 2]"), json("a: {$ne: [1, 2], $size: 2}"))).isFalse(); assertThat(matcher.matches(json("a: [1, 2]"), json("a: {$size: 2, $ne: [1, 2]}"))).isFalse(); @@ -464,7 +464,7 @@ void testMatchesNotEqualAndSize() throws Exception { } @Test - void testMatchEqualArray() throws Exception { + void testMatchEqualArray() { assertThat(matcher.matches(json("a: []"), json("a: {$eq: []}"))).isTrue(); assertThat(matcher.matches(json("a: null"), json("a: {$eq: []}"))).isFalse(); assertThat(matcher.matches(json(""), json("a: {$eq: []}"))).isFalse(); @@ -475,7 +475,7 @@ void testMatchEqualArray() throws Exception { } @Test - void testMatchesNot() throws Exception { + void testMatchesNot() { Document query = map("price", not(gt(1.99))); @@ -517,13 +517,13 @@ void testMatchesNot() throws Exception { } @Test - void testMatchesNotSize() throws Exception { + void testMatchesNotSize() { assertThat(matcher.matches(json("a: [1, 2, 3]"), json("a: {$not: {$size: 3}}"))).isFalse(); assertThat(matcher.matches(json("a: [1, 2, 3]"), json("a: {$not: {$size: 4}}"))).isTrue(); } @Test - void testMatchesNotPattern() throws Exception { + void testMatchesNotPattern() { // { item: { $not: /^p.*/ } } Document query = map("item", not(regex("^p.*"))); @@ -539,7 +539,7 @@ void testMatchesNotPattern() throws Exception { } @Test - void testMatchesAnd() throws Exception { + void testMatchesAnd() { Document query = and(json("price: 1.99"), map("qty", lt(20)).append("sale", true)); @@ -566,7 +566,7 @@ void testMatchesAnd() throws Exception { } @Test - void testMatchesOr() throws Exception { + void testMatchesOr() { Document query = or(json("price: 1.99"), map("qty", lt(20))); @@ -584,7 +584,7 @@ void testMatchesOr() throws Exception { } @Test - void testMatchesNor() throws Exception { + void testMatchesNor() { Document query = nor(json("price: 1.99"), map("qty", lt(20))); @@ -603,7 +603,7 @@ void testMatchesNor() throws Exception { } @Test - void testMatchesIllegalQueryAndOrNor() throws Exception { + void testMatchesIllegalQueryAndOrNor() { for (QueryFilter op : new QueryFilter[] { QueryFilter.AND, QueryFilter.OR, QueryFilter.NOR }) { assertNonEmptyArrayException(map(op.getValue(), null)); @@ -616,7 +616,7 @@ void testMatchesIllegalQueryAndOrNor() throws Exception { } } - private void assertNonEmptyArrayException(Document query) throws Exception { + private void assertNonEmptyArrayException(Document query) { Document emptyDocument = json(""); assertThatExceptionOfType(MongoServerError.class) @@ -625,7 +625,7 @@ private void assertNonEmptyArrayException(Document query) throws Exception { } @Test - void testMatchesMod() throws Exception { + void testMatchesMod() { Document document = json(""); Document query = map("x", mod(4, 0)); @@ -641,7 +641,7 @@ void testMatchesMod() throws Exception { } @Test - void testMatchesSize() throws Exception { + void testMatchesSize() { Document query = map("a", size(1)); @@ -657,7 +657,7 @@ void testMatchesSize() throws Exception { } @Test - void testMatchesAll() throws Exception { + void testMatchesAll() { Document document = map("a", map("x", list())); @@ -688,7 +688,7 @@ void testMatchesAll() throws Exception { } @Test - void testMatchesAllSubdocument() throws Exception { + void testMatchesAllSubdocument() { // with subdocuments Document document = map("a", list(json("x: 1"), json("x: 2"))); assertThat(matcher.matches(document, map("a.x", allOf()))).isTrue(); @@ -701,7 +701,7 @@ void testMatchesAllSubdocument() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/36 @Test - void testMatchesAllWithEmptyCollection() throws Exception { + void testMatchesAllWithEmptyCollection() { Document query = json("$and: [{'text': 'TextA'}, {'tags': {$all: []}}]"); assertThat(matcher.matches(json("text: 'TextA', tags: []"), query)).isFalse(); @@ -710,7 +710,7 @@ void testMatchesAllWithEmptyCollection() throws Exception { } @Test - void testMatchesAllAndIn() throws Exception { + void testMatchesAllAndIn() { Document document = map("a", map("x", list(1, 3))); assertThat(matcher.matches(document, map("a.x", allOf(1, 3).appendAll(in(2))))).isFalse(); assertThat(matcher.matches(document, map("a.x", allOf(1, 3).appendAll(in(3))))).isTrue(); @@ -724,7 +724,7 @@ void testMatchesAllAndIn() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/36 @Test - void testMatchesAllAndNin() throws Exception { + void testMatchesAllAndNin() { Document query = json("$and: [{'tags': {$all: ['A']}}, {'tags': {$nin: ['B', 'C']}}]"); assertThat(matcher.matches(json("tags: ['A', 'D']"), query)).isTrue(); @@ -734,7 +734,7 @@ void testMatchesAllAndNin() throws Exception { } @Test - void testMatchesAllAndNotIn() throws Exception { + void testMatchesAllAndNotIn() { Document query = json("$and: [{'tags': {$all: ['A']}}, {'tags': {$not: {$in: ['B', 'C']}}}]"); assertThat(matcher.matches(json("tags: ['A', 'D']"), query)).isTrue(); @@ -745,7 +745,7 @@ void testMatchesAllAndNotIn() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/96 @Test - void testMatchesAllAndSize() throws Exception { + void testMatchesAllAndSize() { Document query = json("list: {$all: ['A', 'B'], $size: 2}"); assertThat(matcher.matches(json("list: ['A', 'B']"), query)).isTrue(); @@ -757,7 +757,7 @@ void testMatchesAllAndSize() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/96 @Test - void testMatchesSizeAndAll() throws Exception { + void testMatchesSizeAndAll() { Document query = json("list: {$size: 2, $all: ['A', 'B']}"); assertThat(matcher.matches(json("list: ['A', 'D']"), query)).isFalse(); @@ -769,7 +769,7 @@ void testMatchesSizeAndAll() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/97 @Test - void testMatchesAllElements() throws Exception { + void testMatchesAllElements() { Document document = json("list: [{a: 'b'}, {c: 'd'}]"); assertThat(matcher.matches(document, json("list: {$all: [{$elemMatch: {a: 'b'}}]}"))).isTrue(); @@ -779,7 +779,7 @@ void testMatchesAllElements() throws Exception { } @Test - void testMatchesElement() throws Exception { + void testMatchesElement() { Document document1 = json("results: [82, 85, 88]"); assertThat(matcher.matches(document1, map("results", elemMatch(gte(80))))).isTrue(); assertThat(matcher.matches(document1, map("results", elemMatch(gte(80).appendAll(lt(85)))))).isTrue(); @@ -800,7 +800,7 @@ void testMatchesElement() throws Exception { } @Test - void testMatchesElementInEmbeddedDocuments() throws Exception { + void testMatchesElementInEmbeddedDocuments() { Document document1 = json("_id: 1, results: [{product: 'abc', score: 10}, {product: 'xyz', score: 5}]"); Document document2 = json("_id: 2, results: [{product: 'abc', score: 9}, {product: 'xyz', score: 7}]"); Document document3 = json("_id: 3, results: [{product: 'abc', score: 7}, {product: 'xyz', score: 8}]"); @@ -817,7 +817,7 @@ void testMatchesElementInEmbeddedDocuments() throws Exception { } @Test - void testMatchesElementWithQueryFilter() throws Exception { + void testMatchesElementWithQueryFilter() { Document document1 = json("a: [{v: 'X'}, {v: 'Y'}]"); Document document2 = json("a: [{v: 'Z'}]"); @@ -832,13 +832,13 @@ void testMatchesElementWithQueryFilter() throws Exception { } @Test - void testEmptyMatchesElementQuery() throws Exception { + void testEmptyMatchesElementQuery() { Document document = json("_id: 1, results: [{product: 'xyz', score: 5}]"); assertThat(matcher.matches(document, map("results", elemMatch(json(""))))).isTrue(); } @Test - void testMatchesExpr() throws Exception { + void testMatchesExpr() { assertThat(matcher.matches(json(""), json("$expr: true"))).isTrue(); assertThat(matcher.matches(json(""), json("$expr: false"))).isFalse(); assertThat(matcher.matches(json("value: 1"), json("$expr: '$value'"))).isTrue(); @@ -847,7 +847,7 @@ void testMatchesExpr() throws Exception { } @Test - void testMatchesZeroValues() throws Exception { + void testMatchesZeroValues() { assertThat(matcher.matches(json("v: 0"), json("v: 0.0"))).isTrue(); assertThat(matcher.matches(json("v: 0.0"), json("v: 0.0"))).isTrue(); assertThat(matcher.matches(json("v: 0.0"), json("v: 0"))).isTrue(); @@ -857,7 +857,7 @@ void testMatchesZeroValues() throws Exception { } @Test - void testMatchesType() throws Exception { + void testMatchesType() { assertThat(matcher.matches(json("v: 0"), json("v: {$type: 16}"))).isTrue(); assertThat(matcher.matches(json("v: 'abc'"), json("v: {$type: 16}"))).isFalse(); assertThat(matcher.matches(json("v: 0"), json("v: {$type: 16.0}"))).isTrue(); @@ -910,7 +910,7 @@ void testMatchesType() throws Exception { } @Test - void testMatchesJavaScript() throws Exception { + void testMatchesJavaScript() { Document document = new Document("data", new BsonJavaScript("code 1")); assertThat(matcher.matches(document, new Document("data", new BsonJavaScript("code 1")))).isTrue(); assertThat(matcher.matches(document, new Document("data", new BsonJavaScript("code 2")))).isFalse(); @@ -918,7 +918,7 @@ void testMatchesJavaScript() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/132 @Test - void testNearSphere() throws Exception { + void testNearSphere() { assertThatExceptionOfType(MongoServerNotYetImplementedException.class) .isThrownBy(() -> matcher.matches(json("location: [0, 0]"), json("location: " + "{" + @@ -936,7 +936,7 @@ void testNearSphere() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/132 @Test - void testGeoWithin() throws Exception { + void testGeoWithin() { assertThatExceptionOfType(MongoServerNotYetImplementedException.class) .isThrownBy(() -> matcher.matches(json("location: [0, 0]"), json("location: {" + " $geoWithin: {" + diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/DocumentComparatorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/DocumentComparatorTest.java index 299de3ee1..a1370aa50 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/DocumentComparatorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/DocumentComparatorTest.java @@ -64,7 +64,7 @@ void testCompareMultiKey() { } @Test - void testCompareCompoundKey() throws Exception { + void testCompareCompoundKey() { DocumentComparator comparator = new DocumentComparator(json("'a.b': 1, c: -1")); Document a = json("a: {b: 10}"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/EmptyCursorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/EmptyCursorTest.java index ea16ccd39..181795e7e 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/EmptyCursorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/EmptyCursorTest.java @@ -28,7 +28,7 @@ void testTakeDocuments() { } @Test - void testToString() throws Exception { + void testToString() { assertThat(EmptyCursor.get()).hasToString("EmptyCursor()"); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/InMemoryCursorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/InMemoryCursorTest.java index 61366e7e9..a1b80edbf 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/InMemoryCursorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/InMemoryCursorTest.java @@ -54,7 +54,7 @@ void testTakeDocuments_returnsUnmodifiableList() { } @Test - void testToString() throws Exception { + void testToString() { assertThat(new InMemoryCursor(123L, List.of(new Document()))) .hasToString("InMemoryCursor(id: 123)"); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/KeyValueTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/KeyValueTest.java index 5e56b9b41..84c2d76c4 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/KeyValueTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/KeyValueTest.java @@ -9,12 +9,12 @@ public class KeyValueTest { @Test - void testEqualsAndHashCodeContract() throws Exception { + void testEqualsAndHashCodeContract() { EqualsVerifier.forClass(KeyValue.class).verify(); } @Test - void testToString() throws Exception { + void testToString() { assertThat(new KeyValue(1, 2)).hasToString("{ : 1, : 2 }"); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/LinkedTreeSetTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/LinkedTreeSetTest.java index 6a3756b43..79b107d97 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/LinkedTreeSetTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/LinkedTreeSetTest.java @@ -12,7 +12,7 @@ public class LinkedTreeSetTest { @Test - void testAddContainsRemove() throws Exception { + void testAddContainsRemove() { Set set = new LinkedTreeSet<>(); assertThat(set.add(1)).isTrue(); assertThat(set.add(-0.0)).isTrue(); @@ -39,7 +39,7 @@ void testAddContainsRemove() throws Exception { } @Test - void testSize() throws Exception { + void testSize() { Set set = new LinkedTreeSet<>(); assertThat(set).isEmpty(); assertThat(set).hasSize(0); @@ -52,7 +52,7 @@ void testSize() throws Exception { } @Test - void testToString() throws Exception { + void testToString() { Set set = new LinkedTreeSet<>(); assertThat(set).hasToString("[]"); @@ -63,7 +63,7 @@ void testToString() throws Exception { } @Test - void testEqualsAndHashCode() throws Exception { + void testEqualsAndHashCode() { Set set1 = new LinkedTreeSet<>(); Set set2 = new LinkedTreeSet<>(); @@ -89,7 +89,7 @@ void testEqualsAndHashCode() throws Exception { } @Test - void testIterator() throws Exception { + void testIterator() { Set set = new LinkedTreeSet<>(); set.add(null); set.add("abc"); @@ -117,7 +117,7 @@ void testIterator() throws Exception { } @Test - void testListValues() throws Exception { + void testListValues() { Set set = new LinkedTreeSet<>(); assertThat(set.add(List.of(1, 2, 3))).isTrue(); assertThat(set.add(List.of(2, 3))).isTrue(); @@ -132,7 +132,7 @@ void testListValues() throws Exception { } @Test - void testRemoveAll() throws Exception { + void testRemoveAll() { Set set = new LinkedTreeSet<>(); assertThat(set.removeAll(List.of(2, -0.0))).isFalse(); @@ -158,7 +158,7 @@ void testRemoveAll() throws Exception { } @Test - void testRetainAll() throws Exception { + void testRetainAll() { Set set = new LinkedTreeSet<>(); set.add(1.0); @@ -171,7 +171,7 @@ void testRetainAll() throws Exception { } @Test - void testContains() throws Exception { + void testContains() { Set set1 = new LinkedTreeSet<>(); assertThat(set1.contains(0)).isFalse(); @@ -188,7 +188,7 @@ void testContains() throws Exception { } @Test - void testContainsAll() throws Exception { + void testContainsAll() { Set set1 = new LinkedTreeSet<>(); Set set2 = new LinkedTreeSet<>(); @@ -208,7 +208,7 @@ void testContainsAll() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/109 @Test - void testSizeAfterRemoveAll() throws Exception { + void testSizeAfterRemoveAll() { Set set = new LinkedTreeSet<>(List.of("A", "B")); set.removeAll(List.of("B", "C", "D")); @@ -219,7 +219,7 @@ void testSizeAfterRemoveAll() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/109 @Test - void testSizeAfterRetainAll() throws Exception { + void testSizeAfterRetainAll() { Set set = new LinkedTreeSet<>(List.of("A", "B", "C")); set.retainAll(List.of("B", "C")); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/MissingTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/MissingTest.java index 08b19d882..147895129 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/MissingTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/MissingTest.java @@ -7,7 +7,7 @@ public class MissingTest { @Test - void testIsNullOrMissing() throws Exception { + void testIsNullOrMissing() { assertThat(Missing.isNullOrMissing(null)).isTrue(); assertThat(Missing.isNullOrMissing(Missing.getInstance())).isTrue(); assertThat(Missing.isNullOrMissing("value")).isFalse(); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/ProjectionTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/ProjectionTest.java index 0cc2157fe..cf996f52f 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/ProjectionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/ProjectionTest.java @@ -12,7 +12,7 @@ class ProjectionTest { @Test - void testProjectDocument() throws Exception { + void testProjectDocument() { assertThat(projectDocument(null, new Document(), null)).isNull(); assertThat(projectDocument(json("_id: 100"), json("_id: 1"), "_id")) @@ -50,7 +50,7 @@ void testProjectDocument() throws Exception { } @Test - void testInvalidMixedProjections() throws Exception { + void testInvalidMixedProjections() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> projectDocument(json("{}"), json("_id: 1, foo: 0"), "_id")) .withMessage("[Error 31253] Cannot do inclusion on field _id in exclusion projection"); @@ -105,7 +105,7 @@ void testProjectOut() { @Test - void testProjectMissingValue() throws Exception { + void testProjectMissingValue() { assertThat(projectDocument(json("_id: 1"), json("'a.b': 1"), "_id")) .isEqualTo(json("_id: 1")); @@ -120,7 +120,7 @@ void testProjectMissingValue() throws Exception { } @Test - void testProjectListValues() throws Exception { + void testProjectListValues() { assertThat(projectDocument(json("_id: 1, a: [1, 2, 3]"), json("'a.c': 1"), "_id")) .isEqualTo(json("_id: 1, a: []")); @@ -144,7 +144,7 @@ void testProjectListValues() throws Exception { } @Test - void testProjectListValuesWithPositionalOperator() throws Exception { + void testProjectListValuesWithPositionalOperator() { Document document = json(""" _id: 1, students: [ {name: 'john', school: 'A', age: 10}, @@ -161,7 +161,7 @@ void testProjectListValuesWithPositionalOperator() throws Exception { } @Test - void testProjectWithElemMatch() throws Exception { + void testProjectWithElemMatch() { Document document = json(""" _id: 1, students: [ {name: 'john', school: 'A', age: 10}, @@ -191,7 +191,7 @@ void testProjectWithElemMatch() throws Exception { @Test - void testProjectWithSlice() throws Exception { + void testProjectWithSlice() { Document document = json("_id: 1, values: [1, 2, 3, 4], value: 'other'"); assertThat(projectDocument(document, json("values: {$slice: 2}"), "_id")) diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/StreamUtilsTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/StreamUtilsTest.java index 92fa5aba0..773acbbb7 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/StreamUtilsTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/StreamUtilsTest.java @@ -14,7 +14,7 @@ public class StreamUtilsTest { @Test - void testToLinkedHashMap() throws Exception { + void testToLinkedHashMap() { Map result = Stream.of("a", "b", "c") .map(value -> new SimpleEntry<>(value, value)) .collect(StreamUtils.toLinkedHashMap()); @@ -27,7 +27,7 @@ void testToLinkedHashMap() throws Exception { } @Test - void testToLinkedHashMap_duplicates() throws Exception { + void testToLinkedHashMap_duplicates() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Stream.of("a", "b", "c", "b") .map(value -> new SimpleEntry<>(value, value)) @@ -36,7 +36,7 @@ void testToLinkedHashMap_duplicates() throws Exception { } @Test - void testToLinkedHashSet() throws Exception { + void testToLinkedHashSet() { Set result = Stream.of("a", "b", "c", "b") .collect(StreamUtils.toLinkedHashSet()); assertThat(result).containsExactly("a", "b", "c"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/UtilsTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/UtilsTest.java index 639156dd1..10682398c 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/UtilsTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/UtilsTest.java @@ -16,14 +16,14 @@ class UtilsTest { @Test - void testMarkOkay() throws Exception { + void testMarkOkay() { Document obj = new Document(); Utils.markOkay(obj); assertThat(obj.get("ok")).isEqualTo(Double.valueOf(1.0)); } @Test - void testIsTrue() throws Exception { + void testIsTrue() { assertThat(Utils.isTrue("foo")).isTrue(); assertThat(Utils.isTrue(null)).isFalse(); assertThat(Utils.isTrue(true)).isTrue(); @@ -63,7 +63,7 @@ void testNormalizeLongValue() { } @Test - void testNormalizeNumber() throws Exception { + void testNormalizeNumber() { assertThat(Utils.normalizeNumber(null)).isNull(); assertThat(Utils.normalizeNumber(0)).isEqualTo(0); assertThat(Utils.normalizeNumber(1.0)).isEqualTo(1); @@ -93,13 +93,13 @@ void testNullAwareEquals() { } @Test - void testCalculateSize() throws Exception { + void testCalculateSize() { assertThat(Utils.calculateSize(new Document())).isEqualTo(5); assertThat(Utils.calculateSize(new Document("_id", 7))).isEqualTo(14); } @Test - void testGetSubdocumentValue() throws Exception { + void testGetSubdocumentValue() { Document document = json("foo: 25"); assertThat(Utils.getSubdocumentValue(document, "foo")).isEqualTo(25); assertThat(Utils.getSubdocumentValue(document, "foo.bar")).isInstanceOf(Missing.class); @@ -127,7 +127,7 @@ void testGetSubdocumentValue() throws Exception { } @Test - void testGetFieldValueListSafe() throws Exception { + void testGetFieldValueListSafe() { assertThat(Utils.getFieldValueListSafe(Missing.getInstance(), "foo")).isInstanceOf(Missing.class); assertThat(Utils.getFieldValueListSafe(null, "foo")).isInstanceOf(Missing.class); assertThat(Utils.getFieldValueListSafe(json(""), "foo")).isInstanceOf(Missing.class); @@ -149,7 +149,7 @@ void testGetFieldValueListSafe() throws Exception { } @Test - void testHasFieldValueListSafe() throws Exception { + void testHasFieldValueListSafe() { assertThat(Utils.hasFieldValueListSafe(null, "foo")).isFalse(); Document document = json("foo: 25"); assertThat(Utils.hasFieldValueListSafe(document, "foo")).isTrue(); @@ -163,19 +163,19 @@ void testHasFieldValueListSafe() throws Exception { } @Test - void testGetDatabaseNameFromFullName() throws Exception { + void testGetDatabaseNameFromFullName() { assertThat(Utils.getDatabaseNameFromFullName("foo.bar")).isEqualTo("foo"); assertThat(Utils.getDatabaseNameFromFullName("foo.bar.bla")).isEqualTo("foo"); } @Test - void testGetCollectionNameFromFullName() throws Exception { + void testGetCollectionNameFromFullName() { assertThat(Utils.getCollectionNameFromFullName("foo.bar")).isEqualTo("bar"); assertThat(Utils.getCollectionNameFromFullName("foo.bar.bla")).isEqualTo("bar.bla"); } @Test - void testChangeSubdocumentValue() throws Exception { + void testChangeSubdocumentValue() { Document document = json("_id: 1, foo: {bar: 1, bla: 2}"); Utils.changeSubdocumentValue(document, "foo.bar", 3); @@ -195,7 +195,7 @@ void testChangeSubdocumentValue() throws Exception { } @Test - void testCopySubdocumentValue() throws Exception { + void testCopySubdocumentValue() { Document document = json("_id: 1, foo: {bar: 1, bla: 2}, x: null, y: {a: 1, b: [1, 2, 3]}"); Document result = new Document(); @@ -219,7 +219,7 @@ void testCopySubdocumentValue() throws Exception { } @Test - void testRemoveSubdocumentValue() throws Exception { + void testRemoveSubdocumentValue() { Document document = json("_id: 1, foo: {bar: 1, bla: 2}, baz: { bar: { a: 1, b: 2 } }"); Object removedValue = Utils.removeSubdocumentValue(document, "foo.bar"); @@ -248,7 +248,7 @@ void testRemoveSubdocumentValue() throws Exception { } @Test - void testRemoveSubdocumentValue_array() throws Exception { + void testRemoveSubdocumentValue_array() { Document document = json("_id: 1, x: [{a: 1, b: 2, c: 3}, {b: 3}]"); Object removedValues = Utils.removeSubdocumentValue(document, "x.b"); @@ -257,7 +257,7 @@ void testRemoveSubdocumentValue_array() throws Exception { } @Test - void testRemoveSubdocumentValue_arrayOnLevel1() throws Exception { + void testRemoveSubdocumentValue_arrayOnLevel1() { Document document = json("a: [{b: [{c: 1}, {c: 2, d: 3}, 'abc']}]"); Object removedValues = Utils.removeSubdocumentValue(document, "a.b.c"); @@ -266,7 +266,7 @@ void testRemoveSubdocumentValue_arrayOnLevel1() throws Exception { } @Test - void testRemoveSubdocumentValue_arrayOnLevel2() throws Exception { + void testRemoveSubdocumentValue_arrayOnLevel2() { Document document = json("a: {b: [{c: 1}, {c: 2, d: 3}, 'abc']}"); Object removedValues = Utils.removeSubdocumentValue(document, "a.b.c"); @@ -275,7 +275,7 @@ void testRemoveSubdocumentValue_arrayOnLevel2() throws Exception { } @Test - void testRemoveSubdocumentValue_arrayValue() throws Exception { + void testRemoveSubdocumentValue_arrayValue() { Document document = json("a: {b: {c: [1, 2, 3]}}"); Object removedValues = Utils.removeSubdocumentValue(document, "a.b.c"); @@ -316,7 +316,7 @@ void testCanFullyTraverseSubkeyForRename() { } @Test - void testShorterPathIfPrefix() throws Exception { + void testShorterPathIfPrefix() { assertThat(Utils.getShorterPathIfPrefix("a", "b")).isNull(); assertThat(Utils.getShorterPathIfPrefix("a.b", "b.c")).isNull(); assertThat(Utils.getShorterPathIfPrefix("a.b.c", "a.b.d")).isNull(); @@ -330,7 +330,7 @@ void testShorterPathIfPrefix() throws Exception { } @Test - void testJoinTail() throws Exception { + void testJoinTail() { assertThat(Utils.joinTail(List.of("a"))).isEqualTo(""); assertThat(Utils.joinTail(Collections.emptyList())).isEqualTo(""); assertThat(Utils.joinTail(List.of("a", "b"))).isEqualTo("b"); @@ -339,7 +339,7 @@ void testJoinTail() throws Exception { } @Test - void testCollectCommonPathFragments() throws Exception { + void testCollectCommonPathFragments() { assertThat(Utils.collectCommonPathFragments("a", "b")).isEmpty(); assertThat(Utils.collectCommonPathFragments("aaa", "a.aab")).isEmpty(); assertThat(Utils.collectCommonPathFragments("a.a", "a.b")).containsExactly("a"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/ValueComparatorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/ValueComparatorTest.java index f899d0183..bbf219c6b 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/ValueComparatorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/ValueComparatorTest.java @@ -38,7 +38,7 @@ private static BinData emptyBinData() { } @Test - void testReverse() throws Exception { + void testReverse() { assertThat(ValueComparator.asc().reversed()).isSameAs(ValueComparator.desc()); assertThat(ValueComparator.desc().reversed()).isSameAs(ValueComparator.asc()); } @@ -65,19 +65,19 @@ void testCompareMinMaxKeys() { } @Test - void testCompareNullWithValue() throws Exception { + void testCompareNullWithValue() { assertFirstValueBeforeSecondValue(null, 1.0); } @Test - void testCompareList() throws Exception { + void testCompareList() { assertThat(ValueComparator.ascWithoutListHandling().compare(List.of(1, 2), List.of(1))).isGreaterThan(0); assertThat(ValueComparator.ascWithoutListHandling().compare(List.of(1, 2), List.of(1, 2))).isZero(); assertThat(ValueComparator.ascWithoutListHandling().compare(List.of(1, 2.0), List.of(1.0, 2))).isZero(); } @Test - void testCompareListsInAscendingOrder() throws Exception { + void testCompareListsInAscendingOrder() { assertComparesTheSame(1, List.of(1, 2)); assertFirstValueBeforeSecondValue(List.of(1, 2), "abc"); assertFirstValueBeforeSecondValue(List.of(1, 2), json("a: 1")); @@ -100,7 +100,7 @@ void testCompareListsInAscendingOrder() throws Exception { } @Test - void testCompareListsInDescendingOrder() throws Exception { + void testCompareListsInDescendingOrder() { assertThat(ValueComparator.desc().compare(List.of(2, 3), List.of(1, 2))).isLessThan(0); assertThat(ValueComparator.desc().compare(List.of(1, "abc", 2), List.of(3))).isLessThan(0); @@ -108,7 +108,7 @@ void testCompareListsInDescendingOrder() throws Exception { } @Test - void testCompareMissingWithValue() throws Exception { + void testCompareMissingWithValue() { assertFirstValueBeforeSecondValue(Missing.getInstance(), 1.0); } @@ -159,7 +159,7 @@ void testCompareByteArrayValues() { } @Test - void testCompareDocuments() throws Exception { + void testCompareDocuments() { assertComparesTheSame(json("a: 1"), json("a: 1.0")); assertComparesTheSame(json("a: 0"), json("a: -0.0")); assertComparesTheSame(json("a: {b: 1}"), json("a: {b: 1.0}")); @@ -177,7 +177,7 @@ void testCompareDocuments() throws Exception { } @Test - void testCompareUuids() throws Exception { + void testCompareUuids() { assertComparesTheSame(new UUID(1, 1), new UUID(1, 1)); assertFirstValueBeforeSecondValue(null, new UUID(1, 2)); assertFirstValueBeforeSecondValue(new UUID(0, 1), new UUID(1, 1)); @@ -189,7 +189,7 @@ void testCompareUuids() throws Exception { } @Test - void testCompareLegacyUuids() throws Exception { + void testCompareLegacyUuids() { assertComparesTheSame(new LegacyUUID(1, 1), new LegacyUUID(1, 1)); assertFirstValueBeforeSecondValue(null, new LegacyUUID(1, 2)); assertFirstValueBeforeSecondValue(new LegacyUUID(0, 1), new LegacyUUID(1, 1)); @@ -201,7 +201,7 @@ void testCompareLegacyUuids() throws Exception { } @Test - void testCompareDecimal128() throws Exception { + void testCompareDecimal128() { assertComparesTheSame(Decimal128.ONE, Decimal128.ONE); assertComparesTheSame(Decimal128.ONE, 1); assertComparesTheSame(Decimal128.ONE, 1L); @@ -217,7 +217,7 @@ void testCompareDecimal128() throws Exception { } @Test - void testCompareNumbers() throws Exception { + void testCompareNumbers() { assertFirstValueBeforeSecondValue(223372036854775806L, 223372036854775807L); assertFirstValueBeforeSecondValue(223372036854775807L, 223372036854775808L); assertFirstValueBeforeSecondValue(10.0, 223372036854775807L); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTest.java index 1030fe52f..031fee446 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTest.java @@ -22,7 +22,7 @@ class ExpressionTest { @Test - void testEvaluateSimpleValue() throws Exception { + void testEvaluateSimpleValue() { assertThat(Expression.evaluate(1, json(""))).isEqualTo(1); assertThat(Expression.evaluate(null, json(""))).isNull(); assertThat(Expression.evaluate("abc", json(""))).isEqualTo("abc"); @@ -33,7 +33,7 @@ void testEvaluateSimpleValue() throws Exception { } @Test - void testEvaluateAbs() throws Exception { + void testEvaluateAbs() { assertThat(Expression.evaluate(json("$abs: '$a'"), json("a: -2"))).isEqualTo(2); assertThat(Expression.evaluate(json("$abs: '$a'"), json("a: -2.5"))).isEqualTo(2.5); assertThat(Expression.evaluate(json("$abs: ['$a']"), json("a: -2.5"))).isEqualTo(2.5); @@ -51,7 +51,7 @@ void testEvaluateAbs() throws Exception { } @Test - void testEvaluateAdd() throws Exception { + void testEvaluateAdd() { assertThat(Expression.evaluate(json("$add: ['$a', '$b']"), json("a: 7, b: 5"))).isEqualTo(12); assertThat(Expression.evaluate(json("$add: ['$doesNotExist', 5]"), json(""))).isNull(); assertThat(Expression.evaluate(json("$add: [7.5, 3]"), json(""))).isEqualTo(10.5); @@ -69,7 +69,7 @@ void testEvaluateAdd() throws Exception { } @Test - void testEvaluateAnd() throws Exception { + void testEvaluateAnd() { assertThat(Expression.evaluate(json("$and: [1, 'green']"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$and: []"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$and: [[null], [false], [0]]"), json(""))).isEqualTo(true); @@ -86,7 +86,7 @@ void testEvaluateAnd() throws Exception { } @Test - void testEvaluateAnyElementTrue() throws Exception { + void testEvaluateAnyElementTrue() { assertThat(Expression.evaluate(json("$anyElementTrue: [[true, false]]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$anyElementTrue: ['$items']"), json("items: [false, true]"))).isEqualTo(true); assertThat(Expression.evaluate(json("$anyElementTrue: [[[false]]]"), json(""))).isEqualTo(true); @@ -112,7 +112,7 @@ void testEvaluateAnyElementTrue() throws Exception { } @Test - void testEvaluateAllElementsTrue() throws Exception { + void testEvaluateAllElementsTrue() { assertThat(Expression.evaluate(json("$allElementsTrue: [[true, 1, 'someString']]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$allElementsTrue: [[[false]]]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$allElementsTrue: [[]]"), json(""))).isEqualTo(true); @@ -137,7 +137,7 @@ void testEvaluateAllElementsTrue() throws Exception { } @Test - void testEvaluateArrayElemAt() throws Exception { + void testEvaluateArrayElemAt() { assertThat(Expression.evaluate(json("$arrayElemAt: [[1, 2, 3], 0]"), json(""))).isEqualTo(1); assertThat(Expression.evaluate(json("$arrayElemAt: [[1, 2, 3], 1.0]"), json(""))).isEqualTo(2); assertThat(Expression.evaluate(json("$arrayElemAt: [[1, 2, 3], -2]"), json(""))).isEqualTo(2); @@ -173,7 +173,7 @@ void testEvaluateArrayElemAt() throws Exception { } @Test - void testEvaluateArrayToObject() throws Exception { + void testEvaluateArrayToObject() { assertThat(Expression.evaluate(json("$arrayToObject: {$literal: [['item', 'abc123'], ['qty', 25]]}"), json(""))) .isEqualTo(json("item: 'abc123', qty: 25")); @@ -217,7 +217,7 @@ void testEvaluateArrayToObject() throws Exception { } @Test - void testEvaluateCeil() throws Exception { + void testEvaluateCeil() { assertThat(Expression.evaluate(json("$ceil: '$a'"), json("a: 2.5"))).isEqualTo(3.0); assertThat(Expression.evaluate(json("$ceil: 42"), json(""))).isEqualTo(42.0); assertThat(Expression.evaluate(json("$ceil: [5.4]"), json(""))).isEqualTo(6.0); @@ -237,7 +237,7 @@ void testEvaluateCeil() throws Exception { } @Test - void testEvaluateCmp() throws Exception { + void testEvaluateCmp() { assertThat(Expression.evaluate(json("$cmp: [20, 10]"), json(""))).isEqualTo(1); assertThat(Expression.evaluate(json("$cmp: [20, 20]"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$cmp: [10, 20]"), json(""))).isEqualTo(-1); @@ -257,7 +257,7 @@ void testEvaluateCmp() throws Exception { } @Test - void testEvaluateConcat() throws Exception { + void testEvaluateConcat() { assertThat(Expression.evaluate(json("$concat: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$concat: ['A', 'B', 'C']"), json(""))).isEqualTo("ABC"); assertThat(Expression.evaluate(json("$concat: ['$a', '-', '$b']"), json("a: 'A', b: 'B'"))).isEqualTo("A-B"); @@ -277,7 +277,7 @@ void testEvaluateConcat() throws Exception { } @Test - void testEvaluateConcatArrays() throws Exception { + void testEvaluateConcatArrays() { assertThat(Expression.evaluate(json("$concatArrays: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$concatArrays: [['hello', ' '], ['world']]"), json(""))) @@ -302,7 +302,7 @@ void testEvaluateConcatArrays() throws Exception { } @Test - void testEvaluateCond() throws Exception { + void testEvaluateCond() { assertThat(Expression.evaluate(json("$cond: {if: {$gte: ['$qty', 250]}, then: 30, else: 20}"), json("qty: 100"))) .isEqualTo(20); @@ -345,7 +345,7 @@ void testEvaluateCond() throws Exception { } @Test - void testEvaluateEq() throws Exception { + void testEvaluateEq() { assertThat(Expression.evaluate(json("$eq: [20, 20]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$eq: [20, 10]"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$eq: [null, null]"), json(""))).isEqualTo(true); @@ -363,7 +363,7 @@ void testEvaluateEq() throws Exception { } @Test - void testEvaluateMap() throws Exception { + void testEvaluateMap() { assertThat(Expression.evaluate( json("$map: {input: '$quizzes', as: 'grade', in: {$add: ['$$grade', 2]}}"), json("quizzes: [5, 6, 7]"))) @@ -411,7 +411,7 @@ void testEvaluateMap() throws Exception { } @Test - void testEvaluateReduce() throws Exception { + void testEvaluateReduce() { assertThat((Integer) Expression.evaluate( json("$reduce: {input: '$quizzes', initialValue: 0, in: {$add: ['$$this', '$$value']}}"), json("quizzes: [5, 6, 7]"))) @@ -476,7 +476,7 @@ void testEvaluateReduce() throws Exception { } @Test - void testEvaluateMergeObjects() throws Exception { + void testEvaluateMergeObjects() { assertThat(Expression.evaluate(json("$mergeObjects: [{a: 1}, null]"), json(""))).isEqualTo(json("a: 1")); assertThat(Expression.evaluate(json("$mergeObjects: [null, null]"), json(""))).isEqualTo(json("")); assertThat(Expression.evaluate(json("$mergeObjects: ['$a', '$b']"), json(""))).isEqualTo(json("")); @@ -500,7 +500,7 @@ void testEvaluateMergeObjects() throws Exception { } @Test - void testEvaluateMinute() throws Exception { + void testEvaluateMinute() { assertThat(Expression.evaluate(json("$minute: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$minute: '$a'"), new Document("a", toDate("2018-07-03T14:10:00Z")))).isEqualTo(10); @@ -510,7 +510,7 @@ void testEvaluateMinute() throws Exception { } @Test - void testEvaluateMod() throws Exception { + void testEvaluateMod() { assertThat(Expression.evaluate(json("$mod: [10, 2]"), json(""))).isEqualTo(0.0); assertThat(Expression.evaluate(json("$mod: [3, 2]"), json(""))).isEqualTo(1.0); assertThat(Expression.evaluate(json("$mod: [3.5, 3]"), json(""))).isEqualTo(0.5); @@ -533,7 +533,7 @@ void testEvaluateMod() throws Exception { } @Test - void testEvaluateMonth() throws Exception { + void testEvaluateMonth() { assertThat(Expression.evaluate(json("$month: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$month: '$a'"), new Document("a", toDate("2018-07-03T14:00:00Z")))).isEqualTo(7); @@ -543,7 +543,7 @@ void testEvaluateMonth() throws Exception { } @Test - void testEvaluateMultiply() throws Exception { + void testEvaluateMultiply() { assertThat(Expression.evaluate(json("$multiply: ['$a', '$b']"), json("a: 8, b: 4"))).isEqualTo(32); assertThat(Expression.evaluate(json("$multiply: [4.5, 3]"), json(""))).isEqualTo(13.5); assertThat(Expression.evaluate(json("$multiply: [5, 3.0]"), json(""))).isEqualTo(15.0); @@ -574,7 +574,7 @@ void testEvaluateMultiply() throws Exception { } @Test - void testEvaluateNe() throws Exception { + void testEvaluateNe() { assertThat(Expression.evaluate(json("$ne: [20, 20]"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$ne: [20, 10]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$ne: [20, 'a']"), json(""))).isEqualTo(true); @@ -592,7 +592,7 @@ void testEvaluateNe() throws Exception { } @Test - void testEvaluateNot() throws Exception { + void testEvaluateNot() { assertThat(Expression.evaluate(json("$not: false"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$not: true"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$not: 1"), json(""))).isEqualTo(false); @@ -609,7 +609,7 @@ void testEvaluateNot() throws Exception { } @Test - void testEvaluateOr() throws Exception { + void testEvaluateOr() { assertThat(Expression.evaluate(json("$or: [1, 'green']"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$or: []"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$or: [[null], [false], [0]]"), json(""))).isEqualTo(true); @@ -629,7 +629,7 @@ void testEvaluateOr() throws Exception { } @Test - void testEvaluateObjectToArray() throws Exception { + void testEvaluateObjectToArray() { assertThat(Expression.evaluate(json("$objectToArray: '$v'"), json("v: {a: 1, b: 2}"))) .asInstanceOf(LIST) .containsExactly( @@ -647,7 +647,7 @@ void testEvaluateObjectToArray() throws Exception { } @Test - void testEvaluatePow() throws Exception { + void testEvaluatePow() { assertThat(Expression.evaluate(json("$pow: ['$a', '$b']"), json("a: 8, b: 4"))).isEqualTo(4096.0); assertThat(Expression.evaluate(json("$pow: [4.5, 3]"), json(""))).isEqualTo(91.125); assertThat(Expression.evaluate(json("$pow: [null, 3]"), json(""))).isNull(); @@ -678,7 +678,7 @@ void testEvaluatePow() throws Exception { } @Test - void testEvaluateRange() throws Exception { + void testEvaluateRange() { assertThat(Expression.evaluate(json("$range: [0, 5]"), json(""))).isEqualTo(List.of(0, 1, 2, 3, 4)); assertThat(Expression.evaluate(json("$range: [0, 10, 2]"), json(""))).isEqualTo(List.of(0, 2, 4, 6, 8)); assertThat(Expression.evaluate(json("$range: [0, 1.0, 2]"), json(""))).isEqualTo(List.of(0)); @@ -724,7 +724,7 @@ void testEvaluateRange() throws Exception { } @Test - void testEvaluateReverseArray() throws Exception { + void testEvaluateReverseArray() { assertThat(Expression.evaluate(json("$reverseArray: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$reverseArray: '$a'"), json(""))).isNull(); @@ -754,7 +754,7 @@ void testEvaluateReverseArray() throws Exception { } @Test - void testEvaluateGt() throws Exception { + void testEvaluateGt() { assertThat(Expression.evaluate(json("$gt: [20, 10]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$gt: [20, 20]"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$gt: ['$a', '$b']"), json("a: 10, b: 5"))).isEqualTo(true); @@ -773,7 +773,7 @@ void testEvaluateGt() throws Exception { } @Test - void testEvaluateGte() throws Exception { + void testEvaluateGte() { assertThat(Expression.evaluate(json("$gte: [20, 10]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$gte: [20, 20]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$gte: [20, 21]"), json(""))).isEqualTo(false); @@ -790,7 +790,7 @@ void testEvaluateGte() throws Exception { } @Test - void testEvaluateHour() throws Exception { + void testEvaluateHour() { assertThat(Expression.evaluate(json("$hour: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$hour: '$a'"), new Document("a", toDate("2018-07-03T14:10:00Z")))).isEqualTo(14); assertThat(Expression.evaluate(json("$hour: {date: '$a'}"), new Document("a", toDate("2018-07-03T14:10:00Z")))).isEqualTo(14); @@ -823,7 +823,7 @@ void testDateExpressionsDefaultToUtc() { } @Test - void testEvaluateLt() throws Exception { + void testEvaluateLt() { assertThat(Expression.evaluate(json("$lt: [10, 20]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$lt: [20, 20]"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$lt: ['$qty', 250]"), json("qty: 100"))).isEqualTo(true); @@ -839,7 +839,7 @@ void testEvaluateLt() throws Exception { } @Test - void testEvaluateLte() throws Exception { + void testEvaluateLte() { assertThat(Expression.evaluate(json("$lte: [10, 20]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$lte: [20, 20]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$lte: [21, 20]"), json(""))).isEqualTo(false); @@ -856,7 +856,7 @@ void testEvaluateLte() throws Exception { } @Test - void testEvaluateSecond() throws Exception { + void testEvaluateSecond() { assertThat(Expression.evaluate(json("$second: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$second: '$a'"), new Document("a", toDate("2018-07-03T14:10:23Z")))).isEqualTo(23); @@ -866,7 +866,7 @@ void testEvaluateSecond() throws Exception { } @Test - void testEvaluateSetDifference() throws Exception { + void testEvaluateSetDifference() { assertThat(Expression.evaluate(json("$setDifference: [null, null]"), json(""))).isNull(); assertThat(Expression.evaluate(json("$setDifference: [[], null]"), json(""))).isNull(); assertThat(Expression.evaluate(json("$setDifference: [null, []]"), json(""))).isNull(); @@ -901,7 +901,7 @@ void testEvaluateSetDifference() throws Exception { } @Test - void testEvaluateSetEquals() throws Exception { + void testEvaluateSetEquals() { assertThat(Expression.evaluate(json("$setEquals: [['a', 'b', 'a'], ['b']]"), json(""))) .isEqualTo(false); @@ -942,7 +942,7 @@ void testEvaluateSetEquals() throws Exception { } @Test - void testEvaluateSetIntersection() throws Exception { + void testEvaluateSetIntersection() { assertThat(Expression.evaluate(json("$setIntersection: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$setIntersection: '$field'"), json(""))).isNull(); assertThat((Collection) Expression.evaluate(json("$setIntersection: []"), json(""))).isEmpty(); @@ -981,7 +981,7 @@ void testEvaluateSetIntersection() throws Exception { } @Test - void testEvaluateSetIsSubset() throws Exception { + void testEvaluateSetIsSubset() { assertThat(Expression.evaluate(json("$setIsSubset: [['a', 'b', 'a'], ['b', 'a']]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$setIsSubset: [['a', 'b'], [['a', 'b']]]"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$setIsSubset: ['$a', '$b']"), json("a: [1, 2], b: [1, 2, 3, 4]"))).isEqualTo(true); @@ -1017,7 +1017,7 @@ void testEvaluateSetIsSubset() throws Exception { } @Test - void testEvaluateSetUnion() throws Exception { + void testEvaluateSetUnion() { assertThat(Expression.evaluate(json("$setUnion: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$setUnion: '$a'"), json(""))).isNull(); @@ -1039,7 +1039,7 @@ void testEvaluateSetUnion() throws Exception { } @Test - void testEvaluateSize() throws Exception { + void testEvaluateSize() { assertThat(Expression.evaluate(json("$size: [['$a', '$b']]"), json("a: 7, b: 5"))).isEqualTo(2); assertThat(Expression.evaluate(json("$size: [[7.5, 3]]"), json(""))).isEqualTo(2); assertThat(Expression.evaluate(json("$size: {$literal: [7.5, 3]}"), json(""))).isEqualTo(2); @@ -1058,7 +1058,7 @@ void testEvaluateSize() throws Exception { } @Test - void testEvaluateSlice() throws Exception { + void testEvaluateSlice() { assertThat(Expression.evaluate(json("$slice: [[1, 2, 3], 1, 1]"), json(""))) .isEqualTo(List.of(2)); @@ -1119,7 +1119,7 @@ void testEvaluateSlice() throws Exception { } @Test - void testEvaluateSplit() throws Exception { + void testEvaluateSplit() { assertThat(Expression.evaluate(json("$split: ['June-15-2013', '-']"), json(""))) .asInstanceOf(LIST) .containsExactly("June", "15", "2013"); @@ -1151,7 +1151,7 @@ void testEvaluateSplit() throws Exception { } @Test - void testEvaluateSubtract() throws Exception { + void testEvaluateSubtract() { assertThat(Expression.evaluate(json("$subtract: ['$a', '$b']"), json("a: 7, b: 5"))).isEqualTo(2); assertThat(Expression.evaluate(json("$subtract: [7.5, 3]"), json(""))).isEqualTo(4.5); assertThat(Expression.evaluate(json("$subtract: [null, 3]"), json(""))).isNull(); @@ -1185,7 +1185,7 @@ void testEvaluateSubtract() throws Exception { } @Test - void testEvaluateSum() throws Exception { + void testEvaluateSum() { assertThat(Expression.evaluate(json("$sum: null"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$sum: ''"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$sum: 5"), json(""))).isEqualTo(5); @@ -1198,7 +1198,7 @@ void testEvaluateSum() throws Exception { } @Test - void testEvaluateToLower() throws Exception { + void testEvaluateToLower() { assertThat(Expression.evaluate(json("$toLower: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toLower: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toLower: '$a'"), json("a: 'FOO'"))).isEqualTo("foo"); @@ -1214,7 +1214,7 @@ void testEvaluateToLower() throws Exception { } @Test - void testEvaluateToUpper() throws Exception { + void testEvaluateToUpper() { assertThat(Expression.evaluate(json("$toUpper: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toUpper: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toUpper: '$a'"), json("a: 'foo'"))).isEqualTo("FOO"); @@ -1230,7 +1230,7 @@ void testEvaluateToUpper() throws Exception { } @Test - void testEvaluateTrunc() throws Exception { + void testEvaluateTrunc() { assertThat(Expression.evaluate(json("$trunc: '$a'"), json("a: 2.5"))).isEqualTo(2); assertThat(Expression.evaluate(json("$trunc: 42"), json(""))).isEqualTo(42); assertThat(Expression.evaluate(json("$trunc: NaN"), json(""))).isEqualTo(Double.NaN); @@ -1251,7 +1251,7 @@ void testEvaluateTrunc() throws Exception { } @Test - void testEvaluateToString() throws Exception { + void testEvaluateToString() { assertThat(Expression.evaluate(json("$toString: null"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toString: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$toString: '$a'"), json("a: 'foo'"))).isEqualTo("foo"); @@ -1268,7 +1268,7 @@ void testEvaluateToString() throws Exception { } @Test - void testEvaluateSqrt() throws Exception { + void testEvaluateSqrt() { assertThat((double) Expression.evaluate(json("$sqrt: '$a'"), json("a: 2.5"))).isEqualTo(1.581, Offset.offset(0.001)); assertThat(Expression.evaluate(json("$sqrt: 16"), json(""))).isEqualTo(4.0); assertThat(Expression.evaluate(json("$sqrt: [25]"), json(""))).isEqualTo(5.0); @@ -1284,7 +1284,7 @@ void testEvaluateSqrt() throws Exception { } @Test - void testEvaluateStrLenBytes() throws Exception { + void testEvaluateStrLenBytes() { assertThat(Expression.evaluate(json("$strLenBytes: ''"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$strLenBytes: '$a'"), json("a: 'value'"))).isEqualTo(5); assertThat(Expression.evaluate(json("$strLenBytes: 'cafétéria'"), json(""))).isEqualTo(11); @@ -1305,7 +1305,7 @@ void testEvaluateStrLenBytes() throws Exception { } @Test - void testEvaluateStrLenCP() throws Exception { + void testEvaluateStrLenCP() { assertThat(Expression.evaluate(json("$strLenCP: ''"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$strLenCP: '$a'"), json("a: 'value'"))).isEqualTo(5); assertThat(Expression.evaluate(json("$strLenCP: 'cafétéria'"), json(""))).isEqualTo(9); @@ -1326,7 +1326,7 @@ void testEvaluateStrLenCP() throws Exception { } @Test - void testEvaluateSubstrBytes() throws Exception { + void testEvaluateSubstrBytes() { assertThat(Expression.evaluate(json("$substrBytes: ['', -1, -1]"), json(""))).isEqualTo(""); assertThat(Expression.evaluate(json("$substrBytes: ['$a', 0, -1]"), json("a: 'value'"))).isEqualTo("value"); assertThat(Expression.evaluate(json("$substrBytes: ['$a', 0, 5]"), json("a: 'cafétéria'"))).isEqualTo("café"); @@ -1351,7 +1351,7 @@ void testEvaluateSubstrBytes() throws Exception { } @Test - void testEvaluateSubstrCP() throws Exception { + void testEvaluateSubstrCP() { assertThat(Expression.evaluate(json("$substrCP: ['', -1, -1]"), json(""))).isEqualTo(""); assertThat(Expression.evaluate(json("$substrCP: ['$a', 0, -1]"), json("a: 'value'"))).isEqualTo("value"); assertThat(Expression.evaluate(json("$substrCP: ['$a', 0, 5]"), json("a: 'cafétéria'"))).isEqualTo("cafét"); @@ -1376,7 +1376,7 @@ void testEvaluateSubstrCP() throws Exception { } @Test - void testEvaluateYear() throws Exception { + void testEvaluateYear() { assertThat(Expression.evaluate(json("$year: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$year: '$a'"), new Document("a", toDate("2018-07-03T14:00:00Z")))).isEqualTo(2018); @@ -1386,7 +1386,7 @@ void testEvaluateYear() throws Exception { } @Test - void testEvaluateDayOfWeek() throws Exception { + void testEvaluateDayOfWeek() { assertThat(Expression.evaluate(json("$dayOfWeek: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$dayOfWeek: '$a'"), new Document("a", toDate("2018-01-01T14:00:00Z")))).isEqualTo(1); assertThat(Expression.evaluate(json("$dayOfWeek: '$a'"), new Document("a", toDate("2014-02-03T14:00:00Z")))).isEqualTo(1); @@ -1398,7 +1398,7 @@ void testEvaluateDayOfWeek() throws Exception { } @Test - void testEvaluateDayOfMonth() throws Exception { + void testEvaluateDayOfMonth() { assertThat(Expression.evaluate(json("$dayOfMonth: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$dayOfMonth: '$a'"), new Document("a", toDate("2018-01-01T14:00:00Z")))).isEqualTo(1); assertThat(Expression.evaluate(json("$dayOfMonth: '$a'"), new Document("a", toDate("2014-02-03T14:00:00Z")))).isEqualTo(3); @@ -1410,7 +1410,7 @@ void testEvaluateDayOfMonth() throws Exception { } @Test - void testEvaluateDayOfYear() throws Exception { + void testEvaluateDayOfYear() { assertThat(Expression.evaluate(json("$dayOfYear: '$a'"), json(""))).isNull(); assertThat(Expression.evaluate(json("$dayOfYear: '$a'"), new Document("a", toDate("2018-01-01T14:00:00Z")))).isEqualTo(1); assertThat(Expression.evaluate(json("$dayOfYear: '$a'"), new Document("a", toDate("2014-02-03T14:00:00Z")))).isEqualTo(34); @@ -1421,7 +1421,7 @@ void testEvaluateDayOfYear() throws Exception { } @Test - void testDateToString() throws Exception { + void testDateToString() { Instant instant = Instant.parse("2011-12-19T10:15:20.250Z"); assertThat(Expression.evaluate(json("$dateToString: {date: '$a'}"), json(""))).isNull(); @@ -1493,7 +1493,7 @@ void testDateToString() throws Exception { } @Test - void testEvaluateDivide() throws Exception { + void testEvaluateDivide() { assertThat(Expression.evaluate(json("$divide: ['$a', '$b']"), json("a: 8, b: 4"))).isEqualTo(2.0); assertThat(Expression.evaluate(json("$divide: [4.5, 3]"), json(""))).isEqualTo(1.5); assertThat(Expression.evaluate(json("$divide: [null, 3]"), json(""))).isNull(); @@ -1522,7 +1522,7 @@ void testEvaluateDivide() throws Exception { } @Test - void testEvaluateExp() throws Exception { + void testEvaluateExp() { assertThat(Expression.evaluate(json("$exp: 0"), json(""))).isEqualTo(1.0); assertThat(Expression.evaluate(json("$exp: [0]"), json(""))).isEqualTo(1.0); assertThat((double) Expression.evaluate(json("$exp: '$a'"), json("a: 2"))).isEqualTo(7.389, Offset.offset(0.001)); @@ -1543,7 +1543,7 @@ void testEvaluateExp() throws Exception { } @Test - void testEvaluateFilter() throws Exception { + void testEvaluateFilter() { assertThat(Expression.evaluate(json("$filter: {input: null, cond: null}"), json(""))).isNull(); assertThat(Expression.evaluate(json("$filter: {input: [1, 2, 3, 4], as: 'value', cond: {$lte: ['$$value', 3]}}"), json(""))) @@ -1602,7 +1602,7 @@ void testEvaluateFilter() throws Exception { } @Test - void testEvaluateFloor() throws Exception { + void testEvaluateFloor() { assertThat(Expression.evaluate(json("$floor: '$a'"), json("a: 2.5"))).isEqualTo(2); assertThat(Expression.evaluate(json("$floor: 42"), json(""))).isEqualTo(42); assertThat(Expression.evaluate(json("$floor: NaN"), json(""))).isEqualTo(Double.NaN); @@ -1623,7 +1623,7 @@ void testEvaluateFloor() throws Exception { } @Test - void testEvaluateIfNull() throws Exception { + void testEvaluateIfNull() { assertThat(Expression.evaluate(json("$ifNull: [17, 'Unspecified']"), json(""))).isEqualTo(17); assertThat(Expression.evaluate(json("$ifNull: [null, null]"), json(""))).isNull(); assertThat(Expression.evaluate(json("$ifNull: ['$desc', 'Unspecified']"), json(""))).isEqualTo("Unspecified"); @@ -1645,7 +1645,7 @@ void testEvaluateIfNull() throws Exception { } @Test - void testEvaluateIn() throws Exception { + void testEvaluateIn() { assertThat(Expression.evaluate(json("$in: [2, [1, 2, 3]]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$in: ['abc', ['xyz', 'abc']]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$in: [['a'], ['a']]"), json(""))).isEqualTo(false); @@ -1663,7 +1663,7 @@ void testEvaluateIn() throws Exception { } @Test - void testEvaluateIndexOfArray() throws Exception { + void testEvaluateIndexOfArray() { assertThat(Expression.evaluate(json("$indexOfArray: [['a', 'abc'], 'a']"), json(""))).isEqualTo(0); assertThat(Expression.evaluate(json("$indexOfArray: [['a', 'abc', 'de', ['de']], ['de']]"), json(""))).isEqualTo(3); assertThat(Expression.evaluate(json("$indexOfArray: [[1, 2], 5]"), json(""))).isEqualTo(-1); @@ -1707,7 +1707,7 @@ void testEvaluateIndexOfArray() throws Exception { } @Test - void testEvaluateIndexOfBytes() throws Exception { + void testEvaluateIndexOfBytes() { assertThat(Expression.evaluate(json("$indexOfBytes: ['cafeteria', 'e']"), json(""))).isEqualTo(3); assertThat(Expression.evaluate(json("$indexOfBytes: ['cafétéria', 'é']"), json(""))).isEqualTo(3); assertThat(Expression.evaluate(json("$indexOfBytes: ['cafétéria', 'e']"), json(""))).isEqualTo(-1); @@ -1756,7 +1756,7 @@ void testEvaluateIndexOfBytes() throws Exception { } @Test - void testEvaluateIndexOfCP() throws Exception { + void testEvaluateIndexOfCP() { assertThat(Expression.evaluate(json("$indexOfCP: ['cafeteria', 'e']"), json(""))).isEqualTo(3); assertThat(Expression.evaluate(json("$indexOfCP: ['cafétéria', 'é']"), json(""))).isEqualTo(3); assertThat(Expression.evaluate(json("$indexOfCP: ['cafétéria', 'e']"), json(""))).isEqualTo(-1); @@ -1805,7 +1805,7 @@ void testEvaluateIndexOfCP() throws Exception { } @Test - void testEvaluateIsArray() throws Exception { + void testEvaluateIsArray() { assertThat(Expression.evaluate(json("$isArray: ['hello']"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$isArray: [[2, 3]]"), json(""))).isEqualTo(true); assertThat(Expression.evaluate(json("$isArray: 'foo'}"), json(""))).isEqualTo(false); @@ -1819,7 +1819,7 @@ void testEvaluateIsArray() throws Exception { } @Test - void testEvaluateIsNumber() throws Exception { + void testEvaluateIsNumber() { assertThat(Expression.evaluate(json("$isNumber: ['hello']"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$isNumber: 'pi'}"), json(""))).isEqualTo(false); assertThat(Expression.evaluate(json("$isNumber: null"), json(""))).isEqualTo(false); @@ -1831,13 +1831,13 @@ void testEvaluateIsNumber() throws Exception { } @Test - void testEvaluateLiteral() throws Exception { + void testEvaluateLiteral() { assertThat(Expression.evaluate(json("$literal: {$add: [2, 3]}"), json(""))).isEqualTo(json("$add: [2, 3]")); assertThat(Expression.evaluate(json("$literal: {$literal: 1}"), json(""))).isEqualTo(json("$literal: 1")); } @Test - void testEvaluateLn() throws Exception { + void testEvaluateLn() { assertThat(Expression.evaluate(json("$ln: 1"), json(""))).isEqualTo(0.0); assertThat(Expression.evaluate(json("$ln: [1]"), json(""))).isEqualTo(0.0); assertThat((double) Expression.evaluate(json("$ln: '$a'"), json("a: 10"))).isEqualTo(2.302, Offset.offset(0.001)); @@ -1858,7 +1858,7 @@ void testEvaluateLn() throws Exception { } @Test - void testEvaluateLog() throws Exception { + void testEvaluateLog() { assertThat(Expression.evaluate(json("$log: 1"), json(""))).isEqualTo(0.0); assertThat(Expression.evaluate(json("$log: [1]"), json(""))).isEqualTo(0.0); assertThat((double) Expression.evaluate(json("$log: '$a'"), json("a: 10"))).isEqualTo(2.302, Offset.offset(0.001)); @@ -1879,7 +1879,7 @@ void testEvaluateLog() throws Exception { } @Test - void testEvaluateLog10() throws Exception { + void testEvaluateLog10() { assertThat(Expression.evaluate(json("$log10: 1"), json(""))).isEqualTo(0.0); assertThat(Expression.evaluate(json("$log10: 10"), json(""))).isEqualTo(1.0); assertThat(Expression.evaluate(json("$log10: 100"), json(""))).isEqualTo(2.0); @@ -1903,27 +1903,27 @@ void testEvaluateLog10() throws Exception { } @Test - void testEvaluateIllegalExpression() throws Exception { + void testEvaluateIllegalExpression() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> Expression.evaluate(json("$foo: '$a'"), json(""))) .withMessage("[Error 168] Unrecognized expression '$foo'"); } @Test - void testEvaluateDocument_SimpleExpression() throws Exception { + void testEvaluateDocument_SimpleExpression() { Object evaluatedDocument = Expression.evaluateDocument(json("key: '$key2'"), json("key2: 123")); assertThat(evaluatedDocument).isEqualTo(json("key: 123")); } @Test - void testEvaluateDocument_NullValue() throws Exception { + void testEvaluateDocument_NullValue() { Object evaluatedDocument = Expression.evaluateDocument(json("key: '$value'"), json("value: null")); assertThat(evaluatedDocument).isEqualTo(json("key: null")); } // https://github.com/bwaldvogel/mongo-java-server/issues/111 @Test - void testEvaluateDocument_MissingValue() throws Exception { + void testEvaluateDocument_MissingValue() { Object evaluatedDocument = Expression.evaluateDocument(json("key: '$missing'"), json("")); assertThat(evaluatedDocument).isEqualTo(json("")); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MaxAccumulatorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MaxAccumulatorTest.java index 3e11d944b..28acb8b70 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MaxAccumulatorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MaxAccumulatorTest.java @@ -11,7 +11,7 @@ public class MaxAccumulatorTest { private final ComparingAccumulator accumulator = new MaxAccumulator(null, null); @Test - void testAccumulateNumbers() throws Exception { + void testAccumulateNumbers() { accumulator.aggregate(1); accumulator.aggregate(5); accumulator.aggregate(3); @@ -21,7 +21,7 @@ void testAccumulateNumbers() throws Exception { } @Test - void testAccumulateArrays() throws Exception { + void testAccumulateArrays() { accumulator.aggregate(List.of(10, 20, 30)); accumulator.aggregate(List.of(3, 40)); accumulator.aggregate(List.of(11, 25)); @@ -31,7 +31,7 @@ void testAccumulateArrays() throws Exception { } @Test - void testAccumulateArraysAndNonArray() throws Exception { + void testAccumulateArraysAndNonArray() { accumulator.aggregate(List.of(3, 40)); accumulator.aggregate(List.of(10, 20, 30)); accumulator.aggregate(50); @@ -41,7 +41,7 @@ void testAccumulateArraysAndNonArray() throws Exception { } @Test - void testAccumulateNothing() throws Exception { + void testAccumulateNothing() { Object result = accumulator.getResult(); assertThat(result).isNull(); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MinAccumulatorTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MinAccumulatorTest.java index a52e3760a..06f303ac4 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MinAccumulatorTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/accumulator/MinAccumulatorTest.java @@ -11,7 +11,7 @@ public class MinAccumulatorTest { private final ComparingAccumulator accumulator = new MinAccumulator(null, null); @Test - void testAccumulateNumbers() throws Exception { + void testAccumulateNumbers() { accumulator.aggregate(5); accumulator.aggregate(1); accumulator.aggregate(3); @@ -21,7 +21,7 @@ void testAccumulateNumbers() throws Exception { } @Test - void testAccumulateArrays() throws Exception { + void testAccumulateArrays() { accumulator.aggregate(List.of(10, 20, 30)); accumulator.aggregate(List.of(3, 40)); accumulator.aggregate(List.of(11, 25)); @@ -31,7 +31,7 @@ void testAccumulateArrays() throws Exception { } @Test - void testAccumulateArraysAndNonArray() throws Exception { + void testAccumulateArraysAndNonArray() { accumulator.aggregate(List.of(3, 40)); accumulator.aggregate(List.of(10, 20, 30)); accumulator.aggregate(50); @@ -41,7 +41,7 @@ void testAccumulateArraysAndNonArray() throws Exception { } @Test - void testAccumulateNothing() throws Exception { + void testAccumulateNothing() { Object result = accumulator.getResult(); assertThat(result).isNull(); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/AddFieldsStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/AddFieldsStageTest.java index 3f5cd097f..cce9b76b3 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/AddFieldsStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/AddFieldsStageTest.java @@ -12,7 +12,7 @@ public class AddFieldsStageTest { @Test - void testAddFields() throws Exception { + void testAddFields() { assertThat(addFields(json("a: 'value'"), json("a: true"))).isEqualTo(json("a: true")); assertThat(addFields(json("_id: 1"), json("a: 10"))).isEqualTo(json("_id: 1, a: 10")); assertThat(addFields(json("_id: 1, a: 'value'"), json("b: '$a'"))).isEqualTo(json("_id: 1, a: 'value', b: 'value'")); @@ -29,7 +29,7 @@ private static Document addFields(Document document, Document addFields) { } @Test - void testIllegalSpecification() throws Exception { + void testIllegalSpecification() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> new AddFieldsStage(json(""))) .withMessage("[Error 40177] Invalid $addFields :: caused by :: specification must have at least one field"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/LookupStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/LookupStageTest.java index 68cd1bdf3..64dead435 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/LookupStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/LookupStageTest.java @@ -134,7 +134,7 @@ void testLookupObjectBasedOnAnArrayKey() { } @Test - public void testLookupWithNestedField() throws Exception { + public void testLookupWithNestedField() { prepareAuthorsCollectionMock(); LookupStage lookupStage = buildLookupStage("from: 'authors', 'localField': 'author.id', foreignField: '_id', as: 'author'"); @@ -149,7 +149,7 @@ public void testLookupWithNestedField() throws Exception { } @Test - public void testLookupWithNestedFieldArray() throws Exception { + public void testLookupWithNestedFieldArray() { prepareAuthorsCollectionMock(); LookupStage lookupStage = buildLookupStage("from: 'authors', 'localField': 'author.id', foreignField: '_id', as: 'author'"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ProjectStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ProjectStageTest.java index e9b64801f..16c734a71 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ProjectStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ProjectStageTest.java @@ -14,7 +14,7 @@ class ProjectStageTest { @Test - void testProject() throws Exception { + void testProject() { assertThat(project(json("a: 'value'"), json("a: true"))).isEqualTo(json("a: 'value'")); assertThat(project(json("_id: 1"), json("a: 1"))).isEqualTo(json("_id: 1")); assertThat(project(json("_id: 1, a: 'value'"), json("a: 1"))).isEqualTo(json("_id: 1, a: 'value'")); @@ -29,19 +29,19 @@ void testProject() throws Exception { } @Test - void testProject_withNestedExclusion() throws Exception { + void testProject_withNestedExclusion() { assertThat(project(json("_id: 1, x: {a: 1, b: 2, c: 3}"), json("'x.b': 0"))) .isEqualTo(json("_id: 1, x: {a: 1, c: 3}")); } @Test - void testProject_withNestedExclusion_array() throws Exception { + void testProject_withNestedExclusion_array() { assertThat(project(json("_id: 1, x: [{a: 1, b: 2, c: 3}, {a: 2}]"), json("'x.b': 0"))) .isEqualTo(json("_id: 1, x: [{a: 1, c: 3}, {a: 2}]")); } @Test - void testProject_withNestedInclusion() throws Exception { + void testProject_withNestedInclusion() { assertThat(project(json("_id: 1, x: {a: 1, b: 2, c: 3}"), json("'x.b': 1, 'x.c': 1, 'y': 1, 'x.d': 1"))) .isEqualTo(json("_id: 1, x: {b: 2, c: 3}")); } @@ -69,7 +69,7 @@ private static Document project(Document document, Document projection) { } @Test - void testIllegalProject() throws Exception { + void testIllegalProject() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> new ProjectStage(json(""))) .withMessage("[Error 40177] specification must have at least one field"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ReplaceRootStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ReplaceRootStageTest.java index 334d85bf2..2a12110c0 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ReplaceRootStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/ReplaceRootStageTest.java @@ -12,7 +12,7 @@ public class ReplaceRootStageTest { @Test - void testReplaceRoot() throws Exception { + void testReplaceRoot() { assertThat(replaceRoot(json("newRoot: '$a'"), json("a: { b: { c: 1 } }"))).isEqualTo(json("b: { c: 1 }")); assertThat(replaceRoot(json("newRoot: '$a.b'"), json("a: { b: { c: 1 } }"))).isEqualTo(json("c: 1")); assertThat(replaceRoot(json("newRoot: { x: '$a.b' }"), json("a: { b: { c: 1 } }"))).isEqualTo(json("x: { c: 1 }")); @@ -23,7 +23,7 @@ private static Document replaceRoot(Document replaceRoot, Document document) { } @Test - void testIllegalReplaceRoot() throws Exception { + void testIllegalReplaceRoot() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> new ReplaceRootStage(json(""))) .withMessage("[Error 40231] no newRoot specified for the $replaceRoot stage"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnsetStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnsetStageTest.java index 47bfd35e4..24b91aefd 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnsetStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnsetStageTest.java @@ -16,7 +16,7 @@ class UnsetStageTest { @Test - void testUnset() throws Exception { + void testUnset() { assertThat(unset("field1", json("_id: 1, field1: 'value1'"), json("_id: 2, field1: 'value1', field2: 'value2'"), @@ -31,7 +31,7 @@ void testUnset() throws Exception { } @Test - void testUnsetMultipleFields() throws Exception { + void testUnsetMultipleFields() { assertThat(unset(List.of("field1", "field2"), json("_id: 1, field1: 'value1'"), json("_id: 2, field1: 'value1', field2: 'value2'"), @@ -48,7 +48,7 @@ void testUnsetMultipleFields() throws Exception { } @Test - void testUnsetWithSubdocument() throws Exception { + void testUnsetWithSubdocument() { assertThat(unset("fields.field1", json("_id: 1, fields: { field1: 'value1' }"), json("_id: 2, fields: { field1: 'value1', field2: 'value2' }"), @@ -65,7 +65,7 @@ void testUnsetWithSubdocument() throws Exception { } @Test - void testIllegalUnset() throws Exception { + void testIllegalUnset() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> new UnsetStage("")) .withMessage("[Error 40352] Invalid $unset :: caused by :: FieldPath cannot be constructed with empty string"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnwindStageTest.java b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnwindStageTest.java index bfe556d7e..f1d2f8b1f 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnwindStageTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/backend/aggregation/stage/UnwindStageTest.java @@ -16,7 +16,7 @@ public class UnwindStageTest { @Test - void testUnwind() throws Exception { + void testUnwind() { assertThat(unwind("$field", json("_id: 1, field: [1, 2, 3]"), json("_id: 2, field: [2, 3]"), @@ -37,7 +37,7 @@ void testUnwind() throws Exception { } @Test - void testUnwindWithSubdocument() throws Exception { + void testUnwindWithSubdocument() { assertThat(unwind("$field.values", json("_id: 1, field: {values: [1, 2, 3]}"), json("_id: 2, field: {values: [2, 3]}"))) @@ -66,7 +66,7 @@ private List unwind(Object input, Document... documents) { } @Test - void testIllegalParameter() throws Exception { + void testIllegalParameter() { assertThatExceptionOfType(MongoServerError.class) .isThrownBy(() -> new UnwindStage("illegalField")) .withMessage("[Error 28818] path option to $unwind stage should be prefixed with a '$': illegalField"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonJavaScriptTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonJavaScriptTest.java index e6e07e100..c131462e2 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonJavaScriptTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonJavaScriptTest.java @@ -7,7 +7,7 @@ class BsonJavaScriptTest { @Test - void testEqualsAndHashCode() throws Exception { + void testEqualsAndHashCode() { EqualsVerifier.forClass(BsonJavaScript.class).verify(); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonRegularExpressionTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonRegularExpressionTest.java index ebac8c4cf..fec8a9753 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonRegularExpressionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonRegularExpressionTest.java @@ -11,13 +11,13 @@ class BsonRegularExpressionTest { @Test - void testToString() throws Exception { + void testToString() { assertThat(new BsonRegularExpression(".*")).hasToString("{\"$regex\" : \".*\"}"); assertThat(new BsonRegularExpression(".*", "im")).hasToString("{\"$regex\" : \".*\", \"$options\" : \"im\"}"); } @Test - void testConvertToRegularExpressionWithoutOptions() throws Exception { + void testConvertToRegularExpressionWithoutOptions() { BsonRegularExpression regularExpression = BsonRegularExpression.convertToRegularExpression(json("$regex: 'a.*z'")); assertThat(regularExpression.getPattern()).isEqualTo("a.*z"); assertThat(regularExpression.getOptions()).isEqualTo(""); @@ -28,7 +28,7 @@ void testConvertToRegularExpressionWithoutOptions() throws Exception { } @Test - void testConvertToRegularExpressionWithOptions() throws Exception { + void testConvertToRegularExpressionWithOptions() { BsonRegularExpression regularExpression = BsonRegularExpression.convertToRegularExpression(new Document("$regex", "a.*z").append("$options", "usxmi")); assertThat(regularExpression.getPattern()).isEqualTo("a.*z"); assertThat(regularExpression.getOptions()).isEqualTo("usxmi"); @@ -39,7 +39,7 @@ void testConvertToRegularExpressionWithOptions() throws Exception { } @Test - void testConvertToRegularExpressionWithIllegalArgument() throws Exception { + void testConvertToRegularExpressionWithIllegalArgument() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BsonRegularExpression.convertToRegularExpression("abc")) .withMessage("'abc' is not a regular expression"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonTimestampTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonTimestampTest.java index 9da5d0e4a..26a90c1f5 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/BsonTimestampTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/BsonTimestampTest.java @@ -11,12 +11,12 @@ class BsonTimestampTest { @Test - void testEqualsHashCodeContract() throws Exception { + void testEqualsHashCodeContract() { EqualsVerifier.forClass(BsonTimestamp.class).verify(); } @Test - void testToString() throws Exception { + void testToString() { assertThat(new BsonTimestamp(Instant.ofEpochSecond(123), 456)) .hasToString("BsonTimestamp[value=528280977864, seconds=123, inc=456]"); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/Decimal128Test.java b/core/src/test/java/de/bwaldvogel/mongo/bson/Decimal128Test.java index be14e8b6b..6e7f407a7 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/Decimal128Test.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/Decimal128Test.java @@ -12,12 +12,12 @@ class Decimal128Test { @Test - void testEqualsAndHashCodeContract() throws Exception { + void testEqualsAndHashCodeContract() { EqualsVerifier.forClass(Decimal128.class).verify(); } @Test - void testFromAndToBigDecimal() throws Exception { + void testFromAndToBigDecimal() { assertThat(new Decimal128(new BigDecimal("1.2345")).toBigDecimal().toString()).isEqualTo("1.2345"); assertThat(new Decimal128(new BigDecimal("1.2345678901234567890123465789")).toBigDecimal().toString()).isEqualTo("1.2345678901234567890123465789"); assertThat(new Decimal128(new BigDecimal("12345678901234567890123465789")).toBigDecimal().toString()).isEqualTo("12345678901234567890123465789"); @@ -43,7 +43,7 @@ void testFromBigDecimal_NumberFormatException() { } @Test - void testToInt() throws Exception { + void testToInt() { assertThat(Decimal128.ONE.intValue()).isEqualTo(1); assertThat(Decimal128.POSITIVE_ZERO.intValue()).isEqualTo(0); assertThat(Decimal128.NEGATIVE_ZERO.intValue()).isEqualTo(0); @@ -62,7 +62,7 @@ void testToInt() throws Exception { } @Test - void testToLong() throws Exception { + void testToLong() { assertThat(Decimal128.ONE.longValue()).isEqualTo(1L); assertThat(Decimal128.POSITIVE_ZERO.longValue()).isEqualTo(0L); assertThat(Decimal128.NEGATIVE_ZERO.longValue()).isEqualTo(0L); @@ -81,7 +81,7 @@ void testToLong() throws Exception { } @Test - void testToFloat() throws Exception { + void testToFloat() { assertThat(Decimal128.ONE.floatValue()).isEqualTo(1.0f); assertThat(Decimal128.POSITIVE_ZERO.floatValue()).isEqualTo(0.0f); assertThat(Decimal128.NEGATIVE_ZERO.floatValue()).isEqualTo(0.0f); @@ -91,7 +91,7 @@ void testToFloat() throws Exception { } @Test - void testToDouble() throws Exception { + void testToDouble() { assertThat(Decimal128.ONE.doubleValue()).isEqualTo(1.0); assertThat(Decimal128.POSITIVE_ZERO.doubleValue()).isEqualTo(0.0); assertThat(Decimal128.NEGATIVE_ZERO.doubleValue()).isEqualTo(0.0); @@ -101,7 +101,7 @@ void testToDouble() throws Exception { } @Test - void testToString() throws Exception { + void testToString() { assertThat(new Decimal128(new BigDecimal("1e1000"))).hasToString("1E+1000"); assertThat(new Decimal128(new BigDecimal("1000"))).hasToString("1000"); assertThat(new Decimal128(new BigDecimal("1000.987654321"))).hasToString("1000.987654321"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/DocumentTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/DocumentTest.java index 133261fca..4a4dfaccf 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/DocumentTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/DocumentTest.java @@ -19,14 +19,14 @@ class DocumentTest { @Test - void testEqualsAndHashCodeContract() throws Exception { + void testEqualsAndHashCodeContract() { EqualsVerifier.forClass(Document.class) .withNonnullFields("documentAsMap") .verify(); } @Test - void testEquals() throws Exception { + void testEquals() { assertThat(new Document()).isNotEqualTo(Collections.emptyMap()); assertThat(new Document()).isNotEqualTo(null); assertThat(new Document()).isEqualTo(new Document()); @@ -35,7 +35,7 @@ void testEquals() throws Exception { } @Test - void testClone() throws Exception { + void testClone() { Document original = json("abc: 123"); Document clone = original.clone(); assertThat(clone) @@ -44,14 +44,14 @@ void testClone() throws Exception { } @Test - void testConstructor() throws Exception { + void testConstructor() { Map data = Collections.singletonMap("key", 123L); Document document = new Document(data); assertThat(document).containsExactly(entry("key", 123L)); } @Test - void testCloneDeeply() throws Exception { + void testCloneDeeply() { Document original = new Document(); original.put("subDocument", new Document("_id", 1)); original.put("sub", new Document("sub", List.of(1, new Document("key", "value"), 3))); @@ -82,27 +82,27 @@ void testCloneDeeply() throws Exception { } @Test - void testClear() throws Exception { + void testClear() { Document document = json("abc: 123"); document.clear(); assertThat(document).isEqualTo(json("")); } @Test - void testContainsValue() throws Exception { + void testContainsValue() { Document document = json("abc: 123"); assertThat(document.containsValue(123)).isTrue(); assertThat(document.containsValue(42)).isFalse(); } @Test - void testValues() throws Exception { + void testValues() { Document document = json("abc: 123, efg: 456"); assertThat(document.values()).containsExactly(123, 456); } @Test - void testToString() throws Exception { + void testToString() { assertThat(new Document()).hasToString("{}"); assertThat(new Document("key", "value")).hasToString("{\"key\" : \"value\"}"); assertThat(new Document("key", new Document("value", 12345L))).hasToString("{\"key\" : {\"value\" : 12345}}"); @@ -110,7 +110,7 @@ void testToString() throws Exception { } @Test - void testToString_compactKey() throws Exception { + void testToString_compactKey() { assertThat(new Document().toString(true)) .isEqualTo("{}"); @@ -125,7 +125,7 @@ void testToString_compactKey() throws Exception { } @Test - void testGetOrMissing() throws Exception { + void testGetOrMissing() { Document document = new Document().append("a", 1); assertThat(document.getOrMissing("b")).isInstanceOf(Missing.class); assertThat(document.getOrMissing("a")).isEqualTo(1); diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/JsonTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/JsonTest.java index 193c1a85f..c0ad45b53 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/JsonTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/JsonTest.java @@ -14,7 +14,7 @@ class JsonTest { @Test - void testToJsonValue() throws Exception { + void testToJsonValue() { assertThat(Json.toJsonValue(null)).isEqualTo("null"); assertThat(Json.toJsonValue(Missing.getInstance())).isEqualTo("null"); assertThat(Json.toJsonValue(true)).isEqualTo("true"); @@ -49,7 +49,7 @@ void testToJsonValue() throws Exception { } @Test - void testToJsonValueWithCompactKey() throws Exception { + void testToJsonValueWithCompactKey() { assertThat(Json.toJsonValue(new Document().append("a", 1), true, "{", "}")).isEqualTo("{a: 1}"); assertThat(Json.toJsonValue(new Document().append("a", new Document().append("b", 1)), true, "{", "}")).isEqualTo("{a: {b: 1}}"); } diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/LegacyUUIDTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/LegacyUUIDTest.java index d6a9a84cb..0a663d107 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/LegacyUUIDTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/LegacyUUIDTest.java @@ -11,14 +11,14 @@ class LegacyUUIDTest { @Test - void testEqualsAndHashCode() throws Exception { + void testEqualsAndHashCode() { EqualsVerifier.forClass(LegacyUUID.class) .withNonnullFields("uuid") .verify(); } @Test - void testCompare() throws Exception { + void testCompare() { UUID uuid0 = UUID.fromString("00000000-0000-0000-0000-000000000000"); UUID uuid1 = UUID.fromString("48fe9251-9502-4d43-bd81-b8861eb69dc5"); UUID uuid2 = UUID.fromString("cb6bdaa5-d134-4244-9383-ccded62a7bb3"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/bson/ObjectIdTest.java b/core/src/test/java/de/bwaldvogel/mongo/bson/ObjectIdTest.java index 053843d9f..37e256fe7 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/bson/ObjectIdTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/bson/ObjectIdTest.java @@ -12,7 +12,7 @@ class ObjectIdTest { @Test - void testHashCodeEquals() throws Exception { + void testHashCodeEquals() { ObjectId objectId = new ObjectId(); ObjectId other = new ObjectId(); assertThat(objectId).isEqualTo(objectId); @@ -24,13 +24,13 @@ void testHashCodeEquals() throws Exception { } @Test - void testToString() throws Exception { + void testToString() { String expectedPattern = "^ObjectId\\[[a-f0-9]{" + 2 * BsonConstants.LENGTH_OBJECTID + "}\\]$"; assertThat(new ObjectId().toString()).matches(expectedPattern); } @Test - void testToHexStringAndBack() throws Exception { + void testToHexStringAndBack() { ObjectId objectId = new ObjectId(); ObjectId clone = new ObjectId(objectId.getHexData()); assertThat(clone).isEqualTo(objectId); @@ -42,7 +42,7 @@ void testToHexStringAndBack() throws Exception { "abcdef123456789abcdef000", "deadbeefcafebabedeadbeef", }) - void testFromValidHexString(String hexString) throws Exception { + void testFromValidHexString(String hexString) { ObjectId objectId = new ObjectId(hexString); assertThat(objectId.getHexData()).isEqualTo(hexString); } @@ -57,7 +57,7 @@ void testFromValidHexString(String hexString) throws Exception { "abcdefabcdefabcdefabcde", "abcdefabcdefabcdefabcdeff" }) - void testFromIllegalHexString(String hexString) throws Exception { + void testFromIllegalHexString(String hexString) { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> new ObjectId(hexString)) .withMessage("Failed to parse '" + hexString + "'"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/exception/MongoServerExceptionTest.java b/core/src/test/java/de/bwaldvogel/mongo/exception/MongoServerExceptionTest.java index e5031ea1e..217a082ab 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/exception/MongoServerExceptionTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/exception/MongoServerExceptionTest.java @@ -7,7 +7,7 @@ public class MongoServerExceptionTest { @Test - void testIllegalMessage() throws Exception { + void testIllegalMessage() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> new MongoServerException(null)) .withMessage("Illegal error message"); diff --git a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandlerTest.java b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandlerTest.java index 55f9f7148..9b68a7709 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandlerTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandlerTest.java @@ -28,7 +28,7 @@ class MongoDatabaseHandlerTest { @Test - void testWrappedCommand() throws Exception { + void testWrappedCommand() { MongoBackend backend = mock(MongoBackend.class); Document queryDoc = json("'$query': { 'count': 'collectionName' }, '$readPreference': { 'mode': 'secondaryPreferred' }"); @@ -43,7 +43,7 @@ void testWrappedCommand() throws Exception { } @Test - void testNonWrappedCommand() throws Exception { + void testNonWrappedCommand() { MongoBackend backend = mock(MongoBackend.class); Document queryDoc = json("'count': 'collectionName'"); @@ -57,7 +57,7 @@ void testNonWrappedCommand() throws Exception { } @Test - void testHandleMessageUnknownError() throws Exception { + void testHandleMessageUnknownError() { MongoBackend backend = mock(MongoBackend.class); when(backend.handleMessage(any())).thenThrow(new RuntimeException("unexpected")); @@ -78,7 +78,7 @@ void testHandleMessageUnknownError() throws Exception { } @Test - void testMessageWithMoreToComeIsHandledWithoutReply() throws Exception { + void testMessageWithMoreToComeIsHandledWithoutReply() { MongoBackend backend = mock(MongoBackend.class); Channel channel = mock(Channel.class); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); @@ -95,7 +95,7 @@ void testMessageWithMoreToComeIsHandledWithoutReply() throws Exception { } @Test - void testMessageWithoutMoreToComeIsReplied() throws Exception { + void testMessageWithoutMoreToComeIsReplied() { MongoBackend backend = mock(MongoBackend.class); Channel channel = mock(Channel.class); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); diff --git a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireMessageEncoderTest.java b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireMessageEncoderTest.java index 3f217c74e..201e1aaeb 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireMessageEncoderTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireMessageEncoderTest.java @@ -28,12 +28,12 @@ public class MongoWireMessageEncoderTest { private Channel channel; @BeforeEach - void setUpContext() throws Exception { + void setUpContext() { when(ctx.channel()).thenReturn(channel); } @Test - void testExceptionHandling() throws Exception { + void testExceptionHandling() { MongoWireMessageEncoder mongoWireEncoder = new MongoWireMessageEncoder(); MessageHeader header = new MessageHeader(0, 0); diff --git a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireReplyEncoderTest.java b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireReplyEncoderTest.java index abf26df98..0714add0e 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireReplyEncoderTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/wire/MongoWireReplyEncoderTest.java @@ -28,12 +28,12 @@ public class MongoWireReplyEncoderTest { private Channel channel; @BeforeEach - void setUpContext() throws Exception { + void setUpContext() { when(ctx.channel()).thenReturn(channel); } @Test - void testExceptionHandling() throws Exception { + void testExceptionHandling() { MongoWireReplyEncoder mongoWireEncoder = new MongoWireReplyEncoder(); MessageHeader header = new MessageHeader(0, 0); diff --git a/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonDecoderTest.java b/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonDecoderTest.java index fe0ce3b75..08bb2e727 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonDecoderTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonDecoderTest.java @@ -17,7 +17,7 @@ public class BsonDecoderTest { @Test - void testDecodeStringUnicode() throws Exception { + void testDecodeStringUnicode() { String string = "\u0442\u0435\u0441\u0442"; byte[] bytes = string.getBytes(StandardCharsets.UTF_8); ByteBuf buffer = Unpooled.buffer(); @@ -31,7 +31,7 @@ void testDecodeStringUnicode() throws Exception { } @Test - void testEncodeDecodeRoundtrip() throws Exception { + void testEncodeDecodeRoundtrip() { List objects = new ArrayList<>(); objects.add(new Document("key", MaxKey.getInstance()).append("foo", "bar")); objects.add(new Document("key", MinKey.getInstance()).append("test", MaxKey.getInstance())); diff --git a/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonEncoderTest.java b/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonEncoderTest.java index 247a9aeb1..7c675586f 100644 --- a/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonEncoderTest.java +++ b/core/src/test/java/de/bwaldvogel/mongo/wire/bson/BsonEncoderTest.java @@ -16,7 +16,7 @@ public class BsonEncoderTest { @Test - void testEncodeEmptyDocument() throws Exception { + void testEncodeEmptyDocument() { Document document = new Document(); ByteBuf buffer = Unpooled.buffer(); @@ -32,7 +32,7 @@ void testEncodeEmptyDocument() throws Exception { } @Test - void testEncodeDecodeRoundtrip() throws Exception { + void testEncodeDecodeRoundtrip() { Document document = new Document(); document.put("key1", "value"); document.put("key2", 123.0); diff --git a/examples/src/main/java/SimpleJUnit5Test.java b/examples/src/main/java/SimpleJUnit5Test.java index 46ba6fcfa..25d44102b 100644 --- a/examples/src/main/java/SimpleJUnit5Test.java +++ b/examples/src/main/java/SimpleJUnit5Test.java @@ -36,7 +36,7 @@ void tearDown() { } @Test - void testSimpleInsertQuery() throws Exception { + void testSimpleInsertQuery() { assertThat(collection.countDocuments()).isZero(); // creates the database and collection in memory and insert the object diff --git a/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendMongoServerTest.java b/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendMongoServerTest.java index c535adaf7..a8c660e6b 100644 --- a/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendMongoServerTest.java +++ b/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendMongoServerTest.java @@ -5,7 +5,7 @@ class H2BackendMongoServerTest extends MongoServerTest { @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { return H2Backend.inMemory(); } diff --git a/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendReadOnlyProxyTest.java b/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendReadOnlyProxyTest.java index 2012b8669..6a4f83bbc 100644 --- a/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendReadOnlyProxyTest.java +++ b/h2-backend/src/test/java/de/bwaldvogel/mongo/H2BackendReadOnlyProxyTest.java @@ -6,7 +6,7 @@ class H2BackendReadOnlyProxyTest extends AbstractReadOnlyProxyTest { @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { return H2Backend.inMemory(); } diff --git a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2BackendTest.java b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2BackendTest.java index 1f8f9d8fd..81fc3e41f 100644 --- a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2BackendTest.java +++ b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2BackendTest.java @@ -7,7 +7,7 @@ class H2BackendTest extends AbstractBackendTest { @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { return H2Backend.inMemory(clock); } diff --git a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OnDiskBackendTest.java b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OnDiskBackendTest.java index 169bd72e8..610f23dee 100644 --- a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OnDiskBackendTest.java +++ b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OnDiskBackendTest.java @@ -30,7 +30,7 @@ class H2OnDiskBackendTest extends AbstractBackendTest { private static Path tempFile; @Override - protected void setUpBackend() throws Exception { + protected void setUpBackend() { if (tempFile == null) { tempFile = tempFolder.resolve(getClass().getSimpleName() + ".mv"); log.debug("created {} for testing", tempFile); @@ -39,14 +39,14 @@ protected void setUpBackend() throws Exception { } @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { backend = new H2Backend(tempFile.toString(), clock); backend.getMvStore().setAutoCommitDelay(0); return backend; } @Test - void testShutdownAndRestart() throws Exception { + void testShutdownAndRestart() { collection.insertOne(json("_id: 1")); collection.insertOne(json("_id: 2")); @@ -64,7 +64,7 @@ void testShutdownAndRestart() throws Exception { } @Test - void testShutdownAndRestartOpensDatabasesAndCollections() throws Exception { + void testShutdownAndRestartOpensDatabasesAndCollections() { List dbs = List.of("local", "testdb1", "testdb2"); for (String db : dbs) { for (String coll : new String[] { "collection1", "collection2" }) { @@ -81,7 +81,7 @@ void testShutdownAndRestartOpensDatabasesAndCollections() throws Exception { } @Test - void testShutdownAndRestartOpensIndexes() throws Exception { + void testShutdownAndRestartOpensIndexes() { collection.createIndex(json("a: 1")); collection.createIndex(json("b: 1")); assertThat(collection.listIndexes()).hasSize(3); @@ -100,7 +100,7 @@ void testShutdownAndRestartOpensIndexes() throws Exception { } @Test - void testShutdownAndRestartKeepsStatistics() throws Exception { + void testShutdownAndRestartKeepsStatistics() { collection.createIndex(json("a: 1"), new IndexOptions().unique(true)); collection.createIndex(json("b: 1"), new IndexOptions().unique(true)); diff --git a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OplogTest.java b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OplogTest.java index 9ab675bc3..98270bc7e 100644 --- a/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OplogTest.java +++ b/h2-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/H2OplogTest.java @@ -7,7 +7,7 @@ class H2OplogTest extends AbstractOplogTest { @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { return H2Backend.inMemory(clock); } diff --git a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/IndexTest.java b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/IndexTest.java index d46027d5b..b69b25a31 100644 --- a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/IndexTest.java +++ b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/IndexTest.java @@ -14,7 +14,7 @@ class IndexTest { @Test - void testGetKeyValues_simple() throws Exception { + void testGetKeyValues_simple() { Index index = new MemoryUniqueIndex("index", List.of(new IndexKey("x", true)), false); assertThat(index.getKeyValues(new Document("x", 1))).containsExactly(new KeyValue(1.0)); @@ -22,7 +22,7 @@ void testGetKeyValues_simple() throws Exception { } @Test - void testGetKeyValues_compound() throws Exception { + void testGetKeyValues_compound() { Index index = new MemoryUniqueIndex("index", List.of( new IndexKey("a", true), new IndexKey("b", true)), false); @@ -33,7 +33,7 @@ void testGetKeyValues_compound() throws Exception { } @Test - void testGetKeyValues_Subdocument() throws Exception { + void testGetKeyValues_Subdocument() { Index index = new MemoryUniqueIndex("index", List.of(new IndexKey("a.b", true)), false); assertThat(index.getKeyValues(new Document("a", 1))).containsExactly(new KeyValue((Object) null)); @@ -43,7 +43,7 @@ void testGetKeyValues_Subdocument() throws Exception { } @Test - void testGetKeyValues_multiKey() throws Exception { + void testGetKeyValues_multiKey() { Index index = new MemoryUniqueIndex("index", List.of(new IndexKey("a", true)), false); assertThat(index.getKeyValues(new Document("a", List.of(1, 2, 3, 2)))) @@ -54,7 +54,7 @@ void testGetKeyValues_multiKey() throws Exception { } @Test - void testGetKeyValues_compoundMultiKey() throws Exception { + void testGetKeyValues_compoundMultiKey() { Index index = new MemoryUniqueIndex("index", List.of( new IndexKey("a", true), new IndexKey("b", true), @@ -69,7 +69,7 @@ void testGetKeyValues_compoundMultiKey() throws Exception { } @Test - void testGetKeyValues_compoundMultiKey_tooManyCollections() throws Exception { + void testGetKeyValues_compoundMultiKey_tooManyCollections() { Index index = new MemoryUniqueIndex("index", List.of( new IndexKey("a", true), new IndexKey("b", true) @@ -81,7 +81,7 @@ void testGetKeyValues_compoundMultiKey_tooManyCollections() throws Exception { } @Test - void testGetKeyValues_multiKey_document() throws Exception { + void testGetKeyValues_multiKey_document() { Index index = new MemoryUniqueIndex("index", List.of(new IndexKey("a.b", true)), false); assertThat(index.getKeyValues(new Document("a", List.of(new Document("b", 1), new Document("b", 2))))) diff --git a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/MemoryBackendAggregationTest.java b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/MemoryBackendAggregationTest.java index 92cedbb14..3ad4949bc 100644 --- a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/MemoryBackendAggregationTest.java +++ b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/MemoryBackendAggregationTest.java @@ -6,7 +6,7 @@ class MemoryBackendAggregationTest extends AbstractAggregationTest { @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { return new MemoryBackend(clock); } diff --git a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/index/MemoryUniqueIndexTest.java b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/index/MemoryUniqueIndexTest.java index 4347fc954..8ceef051c 100644 --- a/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/index/MemoryUniqueIndexTest.java +++ b/memory-backend/src/test/java/de/bwaldvogel/mongo/backend/memory/index/MemoryUniqueIndexTest.java @@ -18,7 +18,7 @@ class MemoryUniqueIndexTest { @Test - void testGetKeyValues_multiKey_simpleCase() throws Exception { + void testGetKeyValues_multiKey_simpleCase() { Index index = new MemoryUniqueIndex("name", List.of( new IndexKey("a", true), new IndexKey("b", true) @@ -29,7 +29,7 @@ void testGetKeyValues_multiKey_simpleCase() throws Exception { } @Test - void testGetKeyValues_multiKey_cannotIndexParallelArrays() throws Exception { + void testGetKeyValues_multiKey_cannotIndexParallelArrays() { Index index = new MemoryUniqueIndex("name", List.of( new IndexKey("a", true), new IndexKey("b", true) @@ -42,7 +42,7 @@ void testGetKeyValues_multiKey_cannotIndexParallelArrays() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/98 @Test - void testGetKeyValues_multiKey_document_nested_objects_cannotIndexParallelArrays() throws Exception { + void testGetKeyValues_multiKey_document_nested_objects_cannotIndexParallelArrays() { Index index = new MemoryUniqueIndex("name", List.of( new IndexKey("stock.size", true), new IndexKey("stock.quantity", true) @@ -55,7 +55,7 @@ void testGetKeyValues_multiKey_document_nested_objects_cannotIndexParallelArrays // https://github.com/bwaldvogel/mongo-java-server/issues/98 @Test - void testGetKeyValues_multiKey_document_nested_objects() throws Exception { + void testGetKeyValues_multiKey_document_nested_objects() { Index index = new MemoryUniqueIndex("name", List.of( new IndexKey("stock.size", true), new IndexKey("stock.quantity", true) @@ -73,7 +73,7 @@ void testGetKeyValues_multiKey_document_nested_objects() throws Exception { } @Test - void testGetKeyValues_multiKey_nested_objects_multiple_keys() throws Exception { + void testGetKeyValues_multiKey_nested_objects_multiple_keys() { Index index = new MemoryUniqueIndex("name", List.of( new IndexKey("item", true), new IndexKey("stock.size", true), diff --git a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlCollectionTest.java b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlCollectionTest.java index d4f204e43..f5def570c 100644 --- a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlCollectionTest.java +++ b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlCollectionTest.java @@ -11,7 +11,7 @@ class PostgresqlCollectionTest { @Test - void testConvertOrderByToSql() throws Exception { + void testConvertOrderByToSql() { assertThat(PostgresqlCollection.convertOrderByToSql(json(""))).isEqualTo(""); assertThat(PostgresqlCollection.convertOrderByToSql(json("key: 1"))) diff --git a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtilsTest.java b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtilsTest.java index 28e1a390f..aee08b055 100644 --- a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtilsTest.java +++ b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtilsTest.java @@ -16,14 +16,14 @@ class PostgresqlUtilsTest { @Test - void testToDataKey() throws Exception { + void testToDataKey() { assertThat(PostgresqlUtils.toDataKey("foo")).isEqualTo("data ->> 'foo'"); assertThat(PostgresqlUtils.toDataKey("foo.bar")).isEqualTo("data -> 'foo' ->> 'bar'"); assertThat(PostgresqlUtils.toDataKey("foo.bar.bla")).isEqualTo("data -> 'foo' -> 'bar' ->> 'bla'"); } @Test - void testToQueryValue() throws Exception { + void testToQueryValue() { assertThat(PostgresqlUtils.toQueryValue(123)).isEqualTo("123"); assertThat(PostgresqlUtils.toQueryValue(123.0)).isEqualTo("123"); assertThat(PostgresqlUtils.toQueryValue(123.1)).isEqualTo("123.1"); diff --git a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/index/PostgresUniqueIndexTest.java b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/index/PostgresUniqueIndexTest.java index a3a2934fe..1bd9e2165 100644 --- a/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/index/PostgresUniqueIndexTest.java +++ b/postgresql-backend/src/test/java/de/bwaldvogel/mongo/backend/postgresql/index/PostgresUniqueIndexTest.java @@ -14,7 +14,7 @@ class PostgresUniqueIndexTest { @Test - void testCreateSelectStatement() throws Exception { + void testCreateSelectStatement() { List keys = new ArrayList<>(); keys.add(new IndexKey("a", true)); keys.add(new IndexKey("b", true)); @@ -27,7 +27,7 @@ void testCreateSelectStatement() throws Exception { } @Test - void testCreateSelectStatement_SparseIndex() throws Exception { + void testCreateSelectStatement_SparseIndex() { List keys = new ArrayList<>(); keys.add(new IndexKey("a", true)); keys.add(new IndexKey("b", true)); diff --git a/test-common/src/main/java/de/bwaldvogel/AbstractReadOnlyProxyTest.java b/test-common/src/main/java/de/bwaldvogel/AbstractReadOnlyProxyTest.java index c594f2e79..c71d7f7fa 100644 --- a/test-common/src/main/java/de/bwaldvogel/AbstractReadOnlyProxyTest.java +++ b/test-common/src/main/java/de/bwaldvogel/AbstractReadOnlyProxyTest.java @@ -35,10 +35,10 @@ public abstract class AbstractReadOnlyProxyTest { private MongoServer writeableServer; private MongoClient writeClient; - protected abstract MongoBackend createBackend() throws Exception; + protected abstract MongoBackend createBackend(); @BeforeEach - public void setUp() throws Exception { + public void setUp() { MongoBackend mongoBackend = createBackend(); writeableServer = new MongoServer(mongoBackend); writeClient = MongoClients.create(writeableServer.bindAndGetConnectionString()); @@ -56,30 +56,30 @@ public void tearDown() { } @Test - void testMaxDocumentSize() throws Exception { + void testMaxDocumentSize() { ServerDescription serverDescription = CollectionUtils.getOnlyElement(readOnlyClient.getClusterDescription().getServerDescriptions()); assertThat(serverDescription.getMaxDocumentSize()).isEqualTo(16777216); } @Test - void testServerStatus() throws Exception { + void testServerStatus() { readOnlyClient.getDatabase("admin").runCommand(new Document("serverStatus", 1)); } @Test - void testCurrentOperations() throws Exception { + void testCurrentOperations() { Document currentOperations = readOnlyClient.getDatabase("admin").getCollection("$cmd.sys.inprog").find().first(); assertThat(currentOperations).isNotNull(); } @Test - void testStats() throws Exception { + void testStats() { Document stats = readOnlyClient.getDatabase("testdb").runCommand(json("dbStats:1")); assertThat(((Number) stats.get("objects")).longValue()).isZero(); } @Test - void testListDatabaseNames() throws Exception { + void testListDatabaseNames() { assertThat(readOnlyClient.listDatabaseNames()).isEmpty(); writeClient.getDatabase("testdb").getCollection("testcollection").insertOne(new Document()); assertThat(readOnlyClient.listDatabaseNames()).containsExactly("testdb"); @@ -88,7 +88,7 @@ void testListDatabaseNames() throws Exception { } @Test - void testIllegalCommand() throws Exception { + void testIllegalCommand() { assertThatExceptionOfType(MongoException.class) .isThrownBy(() -> readOnlyClient.getDatabase("testdb").runCommand(json("foo:1"))) .withMessageContaining("Command execution failed on MongoDB server with error 59 (CommandNotFound): 'no such command: 'foo'"); @@ -99,7 +99,7 @@ void testIllegalCommand() throws Exception { } @Test - void testQuery() throws Exception { + void testQuery() { MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection"); Document obj = collection.find(json("_id: 1")).first(); assertThat(obj).isNull(); @@ -117,7 +117,7 @@ void testDistinctQuery() { } @Test - void testInsert() throws Exception { + void testInsert() { MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection"); assertThat(collection.countDocuments()).isZero(); @@ -126,7 +126,7 @@ void testInsert() throws Exception { } @Test - void testUpdate() throws Exception { + void testUpdate() { MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection"); Document object = new Document("_id", 1); Document newObject = new Document("_id", 1); @@ -137,7 +137,7 @@ void testUpdate() throws Exception { } @Test - void testUpsert() throws Exception { + void testUpsert() { MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection"); assertThatExceptionOfType(MongoException.class) @@ -146,7 +146,7 @@ void testUpsert() throws Exception { } @Test - void testDropDatabase() throws Exception { + void testDropDatabase() { MongoDatabase database = readOnlyClient.getDatabase("testdb"); assertThatExceptionOfType(MongoException.class) @@ -154,7 +154,7 @@ void testDropDatabase() throws Exception { } @Test - void testDropCollection() throws Exception { + void testDropCollection() { MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("foo"); assertThatExceptionOfType(MongoException.class) @@ -176,7 +176,7 @@ void testHandleKillCursor() { } @Test - void testAggregateWithExpressionProjection() throws Exception { + void testAggregateWithExpressionProjection() { List pipeline = jsonList("$project: {_id: 0, idHex: {$toString: '$_id'}}"); MongoCollection collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection"); diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/MongoServerTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/MongoServerTest.java index 531feaf48..9081ce79a 100644 --- a/test-common/src/main/java/de/bwaldvogel/mongo/MongoServerTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/MongoServerTest.java @@ -35,10 +35,10 @@ public abstract class MongoServerTest { private MongoServer server; - protected abstract MongoBackend createBackend() throws Exception; + protected abstract MongoBackend createBackend(); @BeforeEach - void setUp() throws Exception { + void setUp() { server = new MongoServer(createBackend()); } @@ -48,14 +48,14 @@ void tearDown() { } @Test - void testToString() throws Exception { + void testToString() { assertThat(server).hasToString("MongoServer()"); InetSocketAddress inetSocketAddress = server.bind(); assertThat(server).hasToString("MongoServer(port: " + inetSocketAddress.getPort() + ", ssl: false)"); } @Test - void testBindAndConnect() throws Exception { + void testBindAndConnect() { InetSocketAddress inetSocketAddress = server.bind(); try (MongoClient mongoClient = MongoClients.create("mongodb://" + inetSocketAddress.getHostString() + ":" + inetSocketAddress.getPort())) { mongoClient.getDatabase("abc").createCollection("def"); @@ -65,7 +65,7 @@ void testBindAndConnect() throws Exception { } @Test - void testBindAndGetConnectionStringThenConnect() throws Exception { + void testBindAndGetConnectionStringThenConnect() { String connectionString = server.bindAndGetConnectionString(); try (MongoClient mongoClient = MongoClients.create(connectionString)) { mongoClient.getDatabase("abc").createCollection("def"); @@ -76,7 +76,7 @@ void testBindAndGetConnectionStringThenConnect() throws Exception { @Test @Timeout(TEST_TIMEOUT_SECONDS) - void testStopListening() throws Exception { + void testStopListening() { String connectionString = server.bindAndGetConnectionString(); try (MongoClient client = MongoClients.create(connectionString)) { @@ -101,7 +101,7 @@ void testStopListening() throws Exception { @Test @Timeout(TEST_TIMEOUT_SECONDS) - void testShutdownNow() throws Exception { + void testShutdownNow() { String connectionString = server.bindAndGetConnectionString(); MongoClient client = MongoClients.create(connectionString); @@ -113,7 +113,7 @@ void testShutdownNow() throws Exception { @Test @Timeout(TEST_TIMEOUT_SECONDS) - void testGetLocalAddress() throws Exception { + void testGetLocalAddress() { assertThat(server.getLocalAddress()).isNull(); InetSocketAddress serverAddress = server.bind(); InetSocketAddress localAddress = server.getLocalAddress(); @@ -124,7 +124,7 @@ void testGetLocalAddress() throws Exception { @Test @Timeout(TEST_TIMEOUT_SECONDS) - void testShutdownAndRestart() throws Exception { + void testShutdownAndRestart() { String connectionString = server.bindAndGetConnectionString(); InetSocketAddress serverAddress = server.getLocalAddress(); @@ -170,7 +170,7 @@ void testSsl() throws Exception { } @Test - void testEnableSslAfterAlreadyStarted() throws Exception { + void testEnableSslAfterAlreadyStarted() { server.bindAndGetConnectionString(); assertThatExceptionOfType(IllegalArgumentException.class) @@ -179,7 +179,7 @@ void testEnableSslAfterAlreadyStarted() throws Exception { } @Test - void testEnableSslWithEmptyKeyCertChain() throws Exception { + void testEnableSslWithEmptyKeyCertChain() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> server.enableSsl(null, null)) .withMessage("Param 'keyCertChain' must not be empty"); diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractAggregationTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractAggregationTest.java index f4e747338..d5e5c0a6e 100644 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractAggregationTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractAggregationTest.java @@ -41,7 +41,7 @@ void dropAllDatabasesBeforeEachTest() { } @Test - void testUnrecognizedAggregatePipelineStage() throws Exception { + void testUnrecognizedAggregatePipelineStage() { List pipeline = jsonList("$unknown: {}"); assertThatExceptionOfType(MongoCommandException.class) @@ -50,7 +50,7 @@ void testUnrecognizedAggregatePipelineStage() throws Exception { } @Test - void testIllegalAggregatePipelineStage() throws Exception { + void testIllegalAggregatePipelineStage() { List pipeline = jsonList("$unknown: {}, bar: 1"); assertThatExceptionOfType(MongoCommandException.class) @@ -59,14 +59,14 @@ void testIllegalAggregatePipelineStage() throws Exception { } @Test - void testAggregateWithMissingCursor() throws Exception { + void testAggregateWithMissingCursor() { assertThatExceptionOfType(MongoCommandException.class) .isThrownBy(() -> db.runCommand(json("aggregate: 'collection', pipeline: [{$match: {}}]"))) .withMessageContaining("Command execution failed on MongoDB server with error 9 (FailedToParse): 'The 'cursor' option is required, except for aggregate with the explain argument'"); } @Test - void testAggregateWithIllegalPipeline() throws Exception { + void testAggregateWithIllegalPipeline() { assertThatExceptionOfType(MongoCommandException.class) .isThrownBy(() -> db.runCommand(json("aggregate: 'collection', cursor: {}, pipeline: 123"))) .withMessageContaining("Command execution failed on MongoDB server with error 14 (TypeMismatch): ''pipeline' option must be specified as an array'"); @@ -77,7 +77,7 @@ void testAggregateWithIllegalPipeline() throws Exception { } @Test - void testAggregateWithComplexGroupBySumPipeline() throws Exception { + void testAggregateWithComplexGroupBySumPipeline() { Document query = json("_id: null, n: {$sum: 1}, sumOfA: {$sum: '$a'}, sumOfB: {$sum: '$b.value'}"); List pipeline = List.of(new Document("$group", query)); @@ -93,7 +93,7 @@ void testAggregateWithComplexGroupBySumPipeline() throws Exception { } @Test - void testAggregateWithGroupByMinAndMax() throws Exception { + void testAggregateWithGroupByMinAndMax() { Document query = json("_id: null, minA: {$min: '$a'}, maxB: {$max: '$b.value'}, maxC: {$max: '$c'}, minC: {$min: '$c'}"); List pipeline = List.of(new Document("$group", query)); @@ -110,7 +110,7 @@ void testAggregateWithGroupByMinAndMax() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/68 @Test - void testAggregateWithGroupByMinAndMaxOnArrayField() throws Exception { + void testAggregateWithGroupByMinAndMaxOnArrayField() { Document query = json("_id: null, min: {$min: '$v'}, max: {$max: '$v'}"); List pipeline = List.of(new Document("$group", query)); @@ -126,7 +126,7 @@ void testAggregateWithGroupByMinAndMaxOnArrayField() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/68 @Test - void testAggregateWithGroupByMinAndMaxOnArrayFieldAndNonArrayFields() throws Exception { + void testAggregateWithGroupByMinAndMaxOnArrayFieldAndNonArrayFields() { Document query = json("_id: null, min: {$min: '$v'}, max: {$max: '$v'}"); List pipeline = List.of(new Document("$group", query)); @@ -144,7 +144,7 @@ void testAggregateWithGroupByMinAndMaxOnArrayFieldAndNonArrayFields() throws Exc } @Test - void testAggregateWithGroupByNonExistingMinAndMax() throws Exception { + void testAggregateWithGroupByNonExistingMinAndMax() { Document query = json("_id: null, minOfA: {$min: '$doesNotExist'}, maxOfB: {$max: '$doesNotExist'}"); List pipeline = List.of(new Document("$group", query)); @@ -159,7 +159,7 @@ void testAggregateWithGroupByNonExistingMinAndMax() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/104#issuecomment-548151945 @Test - void testMinMaxAvgProjectionOfArrayValues() throws Exception { + void testMinMaxAvgProjectionOfArrayValues() { List pipeline = jsonList("$project: {min: {$min: '$v'}, max: {$max: '$v'}, avg: {$avg: '$v'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -176,7 +176,7 @@ void testMinMaxAvgProjectionOfArrayValues() throws Exception { } @Test - void testMinMaxAvgProjectionOfNonArrayValue() throws Exception { + void testMinMaxAvgProjectionOfNonArrayValue() { List pipeline = jsonList("$project: {min: {$min: '$v'}, max: {$max: '$v'}, avg: {$avg: '$v'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -192,7 +192,7 @@ void testMinMaxAvgProjectionOfNonArrayValue() throws Exception { } @Test - void testMinMaxAvgProjectionWithTwoParameters() throws Exception { + void testMinMaxAvgProjectionWithTwoParameters() { List pipeline = jsonList("$project: {min: {$min: ['$v', 2]}, max: {$max: ['$v', 2]}, avg: {$avg: ['$v', 2]}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -212,7 +212,7 @@ void testMinMaxAvgProjectionWithTwoParameters() throws Exception { } @Test - void testMinMaxAvgProjectionWithOneParameter() throws Exception { + void testMinMaxAvgProjectionWithOneParameter() { List pipeline = jsonList("$project: {min: {$min: 'abc'}, max: {$max: 'def'}, avg: {$avg: 10}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -224,7 +224,7 @@ void testMinMaxAvgProjectionWithOneParameter() throws Exception { } @Test - void testAggregateWithUnknownGroupOperator() throws Exception { + void testAggregateWithUnknownGroupOperator() { Document query = json("_id: null, n: {$foo: 1}"); List pipeline = List.of(new Document("$group", query)); @@ -234,7 +234,7 @@ void testAggregateWithUnknownGroupOperator() throws Exception { } @Test - void testAggregateWithTooManyGroupOperators() throws Exception { + void testAggregateWithTooManyGroupOperators() { Document query = json("_id: null, n: {$sum: 1, $max: 1}"); List pipeline = List.of(new Document("$group", query)); @@ -244,7 +244,7 @@ void testAggregateWithTooManyGroupOperators() throws Exception { } @Test - void testAggregateWithEmptyPipeline() throws Exception { + void testAggregateWithEmptyPipeline() { assertThat(collection.aggregate(Collections.emptyList())).isEmpty(); collection.insertOne(json("_id: 1")); @@ -255,7 +255,7 @@ void testAggregateWithEmptyPipeline() throws Exception { } @Test - void testAggregateWithMissingIdInGroupSpecification() throws Exception { + void testAggregateWithMissingIdInGroupSpecification() { List pipeline = List.of(new Document("$group", json("n: {$sum: 1}"))); assertThatExceptionOfType(MongoCommandException.class) @@ -264,7 +264,7 @@ void testAggregateWithMissingIdInGroupSpecification() throws Exception { } @Test - void testAggregateWithGroupBySumPipeline() throws Exception { + void testAggregateWithGroupBySumPipeline() { Document query = json("_id: null, n: {$sum: 1}"); List pipeline = List.of(new Document("$group", query)); @@ -303,7 +303,7 @@ void testAggregateWithGroupBySumPipeline() throws Exception { } @Test - void testAggregateWithGroupByAvg() throws Exception { + void testAggregateWithGroupByAvg() { Document query = json("_id: null, avg: {$avg: 1}"); List pipeline = List.of(new Document("$group", query)); @@ -322,7 +322,7 @@ void testAggregateWithGroupByAvg() throws Exception { } @Test - void testAggregateWithGroupByKey() throws Exception { + void testAggregateWithGroupByKey() { List pipeline = jsonList("$group: {_id: '$a', count: {$sum: 1}, avg: {$avg: '$b'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -346,7 +346,7 @@ void testAggregateWithGroupByKey() throws Exception { } @Test - void testAggregateWithGroupByNumberEdgeCases() throws Exception { + void testAggregateWithGroupByNumberEdgeCases() { String groupBy = "$group: {_id: '$a', count: {$sum: 1}, avg: {$avg: '$a'}, min: {$min: '$a'}, max: {$max: '$a'}}"; List pipeline = jsonList(groupBy); @@ -370,7 +370,7 @@ void testAggregateWithGroupByNumberEdgeCases() throws Exception { } @Test - void testAggregateWithGroupByDocuments() throws Exception { + void testAggregateWithGroupByDocuments() { String groupBy = "$group: {_id: '$a', count: {$sum: 1}}"; String sort = "$sort: {_id: 1}"; List pipeline = List.of(json(groupBy), json(sort)); @@ -403,7 +403,7 @@ void testAggregateWithGroupByDocuments() throws Exception { } @Test - void testAggregateWithGroupByIllegalKey() throws Exception { + void testAggregateWithGroupByIllegalKey() { collection.insertOne(json("_id: 1, a: 1")); assertThatExceptionOfType(MongoCommandException.class) @@ -416,7 +416,7 @@ void testAggregateWithGroupByIllegalKey() throws Exception { } @Test - void testAggregateWithSimpleExpressions() throws Exception { + void testAggregateWithSimpleExpressions() { List pipeline = jsonList("$group: {_id: {$abs: '$value'}, count: {$sum: 1}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -436,7 +436,7 @@ void testAggregateWithSimpleExpressions() throws Exception { } @Test - void testAggregateWithMultipleExpressionsInKey() throws Exception { + void testAggregateWithMultipleExpressionsInKey() { List pipeline = jsonList("$group: {_id: {abs: {$abs: '$value'}, sum: {$subtract: ['$end', '$start']}}, count: {$sum: 1}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -458,7 +458,7 @@ void testAggregateWithMultipleExpressionsInKey() throws Exception { } @Test - void testAggregateWithAddToSet() throws Exception { + void testAggregateWithAddToSet() { List pipeline = jsonList( "$group: {_id: { day: { $dayOfYear: '$date'}, year: { $year: '$date' } }, itemsSold: { $addToSet: '$item' }}", "$sort: {_id: 1}"); @@ -481,7 +481,7 @@ void testAggregateWithAddToSet() throws Exception { } @Test - void testAggregateWithEmptyAddToSet() throws Exception { + void testAggregateWithEmptyAddToSet() { List pipeline = jsonList("$group: {_id: 1, set: { $addToSet: '$foo' }}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -496,7 +496,7 @@ void testAggregateWithEmptyAddToSet() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/111 @Test - void testAggregateWithAddToSetAndMissingValue() throws Exception { + void testAggregateWithAddToSetAndMissingValue() { List pipeline = jsonList(""" $group: { _id: '$_id', @@ -518,7 +518,7 @@ void testAggregateWithAddToSetAndMissingValue() throws Exception { } @Test - void testAggregateWithAdd() throws Exception { + void testAggregateWithAdd() { List pipeline = jsonList("$project: { item: 1, total: { $add: [ '$price', '$fee' ] } }"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -536,7 +536,7 @@ void testAggregateWithAdd() throws Exception { } @Test - void testAggregateWithSort() throws Exception { + void testAggregateWithSort() { List pipeline = jsonList("$sort: { price: -1, fee: 1 }"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -554,7 +554,7 @@ void testAggregateWithSort() throws Exception { } @Test - void testAggregateWithProjection() throws Exception { + void testAggregateWithProjection() { List pipeline = jsonList("$project: {_id: 1, value: '$x', n: '$foo.bar', other: null}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -573,7 +573,7 @@ void testAggregateWithProjection() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/121 @Test - void testAggregateWithNestedExclusiveProjection() throws Exception { + void testAggregateWithNestedExclusiveProjection() { List pipeline = jsonList("$project: {_id: 0, 'x.b': 0}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -594,7 +594,7 @@ void testAggregateWithNestedExclusiveProjection() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/121 @Test - void testAggregateWithNestedExclusiveProjection_array() throws Exception { + void testAggregateWithNestedExclusiveProjection_array() { List pipeline = jsonList("$project: {_id: 0, 'a.b.c': 0}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -614,7 +614,7 @@ void testAggregateWithNestedExclusiveProjection_array() throws Exception { } @Test - void testAggregateWithNestedInclusiveProjection() throws Exception { + void testAggregateWithNestedInclusiveProjection() { List pipeline = jsonList("$project: {'x.b': 1, 'x.c': 1}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -649,7 +649,7 @@ private static Stream aggregateWithProjectionArguments() { @ParameterizedTest @MethodSource("aggregateWithProjectionArguments") - void testAggregateWithProjection_IllegalFieldPath(String project, String expectedMessage) throws Exception { + void testAggregateWithProjection_IllegalFieldPath(String project, String expectedMessage) { collection.insertOne(json("_id: 1, x: 10")); assertThatExceptionOfType(MongoCommandException.class) @@ -659,7 +659,7 @@ void testAggregateWithProjection_IllegalFieldPath(String project, String expecte // https://github.com/bwaldvogel/mongo-java-server/pull/189 @Test - void testAggregateWithProjection_arrayElemAt() throws Exception { + void testAggregateWithProjection_arrayElemAt() { collection.insertOne(json("_id: 1, items: [{foo: 'bar'}, {foo: 'bas'}, {foo: 'bat'}]")); collection.insertOne(json("_id: 2, items: [{}]")); collection.insertOne(json("_id: 3, items: [{foo: null}]")); @@ -695,7 +695,7 @@ void testAggregateWithProjection_arrayElemAt() throws Exception { } @Test - void testAggregateWithExpressionProjection() throws Exception { + void testAggregateWithExpressionProjection() { List pipeline = jsonList("$project: {_id: 0, idHex: {$toString: '$_id'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -707,7 +707,7 @@ void testAggregateWithExpressionProjection() throws Exception { } @Test - void testAggregateWithStrLenExpressionProjection() throws Exception { + void testAggregateWithStrLenExpressionProjection() { List pipeline = jsonList("$project: {_id: 0, lenCP: {$strLenCP: '$a'}, lenBytes: {$strLenBytes: '$a'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -731,7 +731,7 @@ void testAggregateWithStrLenExpressionProjection() throws Exception { } @Test - void testAggregateWithSubstringExpressionProjection() throws Exception { + void testAggregateWithSubstringExpressionProjection() { List pipeline = jsonList("$project: {_id: 0, " + "a: {$substr: ['$v', 0, -1]}, " + "b: {$substr: ['$v', 1, -3]}, " + @@ -774,7 +774,7 @@ void testAggregateWithSubstringExpressionProjection() throws Exception { } @Test - void testAggregateWithSubstringUnicodeExpressionProjection() throws Exception { + void testAggregateWithSubstringUnicodeExpressionProjection() { List pipeline = jsonList("$project: {_id: 0, " + "a: {$substrBytes: ['$v', 0, 5]}, " + "b: {$substrCP: ['$v', 0, 5]}, " + @@ -791,7 +791,7 @@ void testAggregateWithSubstringUnicodeExpressionProjection() throws Exception { } @Test - void testAggregateWithAddFields() throws Exception { + void testAggregateWithAddFields() { List pipeline = jsonList("$addFields: {value: '$x'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -809,7 +809,7 @@ void testAggregateWithAddFields() throws Exception { } @Test - void testAggregateWithMultipleMatches() throws Exception { + void testAggregateWithMultipleMatches() { List pipeline = jsonList( "$match: {price: {$lt: 100}}", "$match: {quality: {$gt: 10}}" @@ -830,7 +830,7 @@ void testAggregateWithMultipleMatches() throws Exception { } @Test - void testAggregateWithLogicalAndInMatch() throws Exception { + void testAggregateWithLogicalAndInMatch() { List pipeline = jsonList("$match: {$and: [{price: {$lt: 100}}, {quality: {$gt: 10}}]}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -848,7 +848,7 @@ void testAggregateWithLogicalAndInMatch() throws Exception { } @Test - void testAggregateWithLogicalAndInMatchExpr() throws Exception { + void testAggregateWithLogicalAndInMatchExpr() { List pipeline = jsonList("$match: {$expr: {$and: [{$lt: ['$price', 100]}, {$gt: ['$quality', 10]}]}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -866,7 +866,7 @@ void testAggregateWithLogicalAndInMatchExpr() throws Exception { } @Test - void testAggregateWithLogicalOrInMatchExpr() throws Exception { + void testAggregateWithLogicalOrInMatchExpr() { List pipeline = jsonList("$match: {$expr: {$or: [{$gt: ['$price', 100]}, {$gt: ['$quality', 70]}]}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -884,7 +884,7 @@ void testAggregateWithLogicalOrInMatchExpr() throws Exception { } @Test - void testAggregateWithLogicalOrInMatch() throws Exception { + void testAggregateWithLogicalOrInMatch() { List pipeline = jsonList("$match: {$or: [{$and: [{price: {$lt: 50}}, {quality: {$gt: 10}}]}, {quality: {$gt: 200}}]}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -902,7 +902,7 @@ void testAggregateWithLogicalOrInMatch() throws Exception { } @Test - void testAggregateWithCeil() throws Exception { + void testAggregateWithCeil() { List pipeline = jsonList("$project: {a: 1, ceil: {$ceil: '$a'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -922,7 +922,7 @@ void testAggregateWithCeil() throws Exception { } @Test - void testAggregateWithNumericOperators() throws Exception { + void testAggregateWithNumericOperators() { List pipeline = jsonList("$project: {a: 1, exp: {$exp: '$a'}, ln: {$ln: '$a'}, log10: {$log10: '$a'}, sqrt: {$sqrt: '$a'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -934,7 +934,7 @@ void testAggregateWithNumericOperators() throws Exception { } @Test - void testAggregateWithCount() throws Exception { + void testAggregateWithCount() { Document match = json("$match: {score: {$gt: 80}}"); Document count = json("$count: 'passing_scores'"); List pipeline = List.of(match, count); @@ -952,7 +952,7 @@ void testAggregateWithCount() throws Exception { } @Test - void testAggregateWithFirstAndLast() throws Exception { + void testAggregateWithFirstAndLast() { Document sort = json("$sort: { item: 1, date: 1 }"); Document group = json("$group: {_id: '$item', firstSale: { $first: '$date' }, lastSale: { $last: '$date'} }"); List pipeline = List.of(sort, group); @@ -974,7 +974,7 @@ void testAggregateWithFirstAndLast() throws Exception { } @Test - void testAggregateWithFirstAndLast_Missing() throws Exception { + void testAggregateWithFirstAndLast_Missing() { Document group = json("$group: {_id: '$_id', first: { $first: '$field1' }, last: { $last: '$field2'} }"); List pipeline = List.of(group); @@ -993,7 +993,7 @@ void testAggregateWithFirstAndLast_Missing() throws Exception { } @Test - void testAggregateWithGroupingAndFirstMissing() throws Exception { + void testAggregateWithGroupingAndFirstMissing() { Document sort = json("$sort: {_id: 1}"); Document group = json("$group: {_id: '$group', first: { $first: '$field1' }}"); List pipeline = List.of(sort, group); @@ -1008,7 +1008,7 @@ void testAggregateWithGroupingAndFirstMissing() throws Exception { } @Test - void testAggregateWithGroupingAndLastMissing() throws Exception { + void testAggregateWithGroupingAndLastMissing() { Document sort = json("$sort: {_id: 1}"); Document group = json("$group: {_id: '$group', last: { $last: '$field1' }}"); List pipeline = List.of(sort, group); @@ -1023,7 +1023,7 @@ void testAggregateWithGroupingAndLastMissing() throws Exception { } @Test - void testAggregateWithPush() throws Exception { + void testAggregateWithPush() { List pipeline = jsonList("$group: {_id: null, a: {$push: '$a'}, b: {$push: {v: '$b'}}, c: {$push: '$c'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1036,7 +1036,7 @@ void testAggregateWithPush() throws Exception { } @Test - void testAggregateWithUndefinedVariable() throws Exception { + void testAggregateWithUndefinedVariable() { List pipeline = jsonList("$project: {result: '$$UNDEFINED'}"); collection.insertOne(json("_id: 1")); @@ -1048,7 +1048,7 @@ void testAggregateWithUndefinedVariable() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/31 @Test - void testAggregateWithRootVariable() throws Exception { + void testAggregateWithRootVariable() { List pipeline = jsonList("$project: {_id: 0, doc: '$$ROOT', a: '$$ROOT.a', a_v: '$$ROOT.a.v'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1060,7 +1060,7 @@ void testAggregateWithRootVariable() throws Exception { } @Test - void testAggregateWithRootVariable_IllegalFieldPath() throws Exception { + void testAggregateWithRootVariable_IllegalFieldPath() { collection.insertOne(json("_id: 1, x: 10")); assertThatExceptionOfType(MongoCommandException.class) @@ -1073,7 +1073,7 @@ void testAggregateWithRootVariable_IllegalFieldPath() throws Exception { } @Test - void testAggregateWithSetOperations() throws Exception { + void testAggregateWithSetOperations() { List pipeline = jsonList("$project: {union: {$setUnion: ['$a', '$b']}, diff: {$setDifference: ['$a', '$b']}, intersection: {$setIntersection: ['$a', '$b']}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1091,7 +1091,7 @@ void testAggregateWithSetOperations() throws Exception { } @Test - void testAggregateWithComparisonOperations() throws Exception { + void testAggregateWithComparisonOperations() { collection.insertOne(json("_id: 1, v: 'abc'")); collection.insertOne(json("_id: 2, v: null")); collection.insertOne(json("_id: 3, v: 10")); @@ -1144,7 +1144,7 @@ void testAggregateWithComparisonOperations() throws Exception { } @Test - void testAggregateWithSlice() throws Exception { + void testAggregateWithSlice() { List pipeline = jsonList("$project: {name: 1, threeFavorites: {$slice: ['$favorites', 3]}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1164,7 +1164,7 @@ void testAggregateWithSlice() throws Exception { } @Test - void testAggregateWithSplit() throws Exception { + void testAggregateWithSplit() { List pipeline = jsonList("$project: {_id: 1, names: {$split: ['$name', ' ']}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1181,7 +1181,7 @@ void testAggregateWithSplit() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/214 @Test - void testAggregateWithSplitAndArrayElementAt() throws Exception { + void testAggregateWithSplitAndArrayElementAt() { List pipeline = jsonList("$addFields: { pathSegments: { $split: ['$path', '/'] }}", "$project: { pathSegments: 1, firstSegment: { $arrayElemAt: ['$pathSegments', 0] }}"); @@ -1202,17 +1202,17 @@ void testAggregateWithSplitAndArrayElementAt() throws Exception { } @Test - void testAggregateWithUnwind() throws Exception { + void testAggregateWithUnwind() { testAggregateWithUnwind(json("$unwind: '$sizes'")); } // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_Path() throws Exception { + void testAggregateWithUnwind_Path() { testAggregateWithUnwind(json("$unwind: {path: '$sizes'}")); } - private void testAggregateWithUnwind(Document unwind) throws Exception { + private void testAggregateWithUnwind(Document unwind) { List pipeline = List.of(unwind); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1233,7 +1233,7 @@ private void testAggregateWithUnwind(Document unwind) throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_preserveNullAndEmptyArrays() throws Exception { + void testAggregateWithUnwind_preserveNullAndEmptyArrays() { List pipeline = jsonList("$unwind: {path: '$sizes', preserveNullAndEmptyArrays: true}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1257,7 +1257,7 @@ void testAggregateWithUnwind_preserveNullAndEmptyArrays() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_IncludeArrayIndex() throws Exception { + void testAggregateWithUnwind_IncludeArrayIndex() { List pipeline = jsonList("$unwind: {path: '$sizes', includeArrayIndex: 'idx'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1278,7 +1278,7 @@ void testAggregateWithUnwind_IncludeArrayIndex() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_IncludeArrayIndex_OverwriteExistingField() throws Exception { + void testAggregateWithUnwind_IncludeArrayIndex_OverwriteExistingField() { List pipeline = jsonList("$unwind: {path: '$sizes', includeArrayIndex: 'item'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1299,7 +1299,7 @@ void testAggregateWithUnwind_IncludeArrayIndex_OverwriteExistingField() throws E // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_IncludeArrayIndex_NestedIndexField() throws Exception { + void testAggregateWithUnwind_IncludeArrayIndex_NestedIndexField() { List pipeline = jsonList("$unwind: {path: '$sizes', includeArrayIndex: 'item.idx'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1320,7 +1320,7 @@ void testAggregateWithUnwind_IncludeArrayIndex_NestedIndexField() throws Excepti // https://github.com/bwaldvogel/mongo-java-server/issues/54 @Test - void testAggregateWithUnwind_preserveNullAndEmptyArraysAndIncludeArrayIndex() throws Exception { + void testAggregateWithUnwind_preserveNullAndEmptyArraysAndIncludeArrayIndex() { List pipeline = jsonList("$unwind: {path: '$sizes', preserveNullAndEmptyArrays: true, includeArrayIndex: 'idx'}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1343,7 +1343,7 @@ void testAggregateWithUnwind_preserveNullAndEmptyArraysAndIncludeArrayIndex() th } @Test - void testAggregateWithUnwind_subdocumentArray() throws Exception { + void testAggregateWithUnwind_subdocumentArray() { List pipeline = List.of(json("$unwind: {path: '$items.sizes'}")); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1632,7 +1632,7 @@ void testAggregateWithProjectingReplaceRoot() { } @Test - void testAggregateWithMergeObjects() throws Exception { + void testAggregateWithMergeObjects() { MongoCollection orders = db.getCollection("orders"); orders.insertOne(json("_id: 1, item: 'abc', 'price': 12, ordered: 2")); @@ -1658,7 +1658,7 @@ void testAggregateWithMergeObjects() throws Exception { } @Test - void testAggregateWithSortByCount() throws Exception { + void testAggregateWithSortByCount() { collection.insertOne(json("_id: 1, item: 'abc', 'price': 12, ordered: 2")); collection.insertOne(json("_id: 2, item: 'jkl', 'price': 20, ordered: 1")); collection.insertOne(json("_id: 3, item: 'jkl', 'price': 20, ordered: 7")); @@ -1705,7 +1705,7 @@ void testAggregateWithGraphLookup() { } @Test - void testObjectToArrayExpression() throws Exception { + void testObjectToArrayExpression() { List pipeline = jsonList("$project: {_id: 1, a: {$objectToArray: '$value'}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -1730,7 +1730,7 @@ void testObjectToArrayExpression() throws Exception { } @Test - void testArrayToObjectExpression() throws Exception { + void testArrayToObjectExpression() { collection.insertOne(TestUtils.json("_id: 1, a: 1, b: 'xyz', kv: [['a', 'b'], ['c', 'd']]")); assertThat(collection.aggregate(jsonList("$project: {_id: 1, x: {$arrayToObject: {$literal: [['a', 'foo']]}}}"))) @@ -1779,7 +1779,7 @@ void testArrayToObjectExpression() throws Exception { } @Test - void testAggregateWithReduceOperation() throws Exception { + void testAggregateWithReduceOperation() { collection.insertOne(json("_id: 1")); List pipeline = jsonList("$project: {}"); @@ -1809,7 +1809,7 @@ void testAggregateWithReduceOperation() throws Exception { } @Test - void testAggregateWithMatchProjectReduceConcatAndCond() throws Exception { + void testAggregateWithMatchProjectReduceConcatAndCond() { collection.insertOne(json("_id: 1, name: 'Melissa', hobbies: ['softball', 'drawing', 'reading']")); collection.insertOne(json("_id: 2, name: 'Brad', hobbies: ['gaming', 'skateboarding']")); collection.insertOne(json("_id: 3, name: 'Scott', hobbies: ['basketball', 'music', 'fishing']")); @@ -1854,7 +1854,7 @@ void testAggregateWithMatchProjectReduceConcatAndCond() throws Exception { } @Test - void testAggregateWithBucketStage() throws Exception { + void testAggregateWithBucketStage() { collection.insertOne(json("_id: 1, title: 'The Pillars of Society', artist: 'Grosz', year: 1926, price: 199.99")); collection.insertOne(json("_id: 2, title: 'Melancholy III', artist: 'Munch', year: 1902, price: 280.00")); collection.insertOne(json("_id: 3, title: 'Dancer', artist: 'Miro', year: 1925, price: 76.04")); @@ -1927,7 +1927,7 @@ void testAggregateWithBucketStage() throws Exception { } @Test - void testAggregateWithIllegalBucketStage() throws Exception { + void testAggregateWithIllegalBucketStage() { collection.insertOne(json("_id: 1")); assertThatExceptionOfType(MongoCommandException.class) @@ -1976,7 +1976,7 @@ void testAggregateWithIllegalBucketStage() throws Exception { } @Test - void testAggregateWithFacetStage() throws Exception { + void testAggregateWithFacetStage() { collection.insertOne(json("_id: 1, title: 'The Pillars of Society', price: 199.99, tags: ['painting', 'Expressionism']")); collection.insertOne(json("_id: 2, title: 'Melancholy III', price: 280.00, tags: ['Expressionism']")); collection.insertOne(json("_id: 3, title: 'Dancer', price: 76.04, tags: ['oil', 'painting']")); @@ -2049,7 +2049,7 @@ void testAggregateWithFacetStage() throws Exception { } @Test - void testAggregateWithMatchAndFacetStage() throws Exception { + void testAggregateWithMatchAndFacetStage() { collection.insertOne(json("_id: 1, title: 'The Pillars of Society', price: 199.99, tags: ['painting', 'Expressionism']")); collection.insertOne(json("_id: 2, title: 'Melancholy III', price: 280.00, tags: ['Expressionism']")); collection.insertOne(json("_id: 3, title: 'Dancer', price: 76.04, tags: ['oil', 'painting']")); @@ -2087,7 +2087,7 @@ void testAggregateWithMatchAndFacetStage() throws Exception { } @Test - void testAggregateWithUnsetStage() throws Exception { + void testAggregateWithUnsetStage() { List pipeline = jsonList("$unset: ['field1', 'fields.field2']"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -2109,7 +2109,7 @@ void testAggregateWithUnsetStage() throws Exception { } @Test - void testAggregateWithUnsetStage_illegalInput() throws Exception { + void testAggregateWithUnsetStage_illegalInput() { collection.insertOne(json("_id: 1")); assertThatExceptionOfType(MongoCommandException.class) @@ -2126,7 +2126,7 @@ void testAggregateWithUnsetStage_illegalInput() throws Exception { } @Test - void testAggregateWithIndexStats() throws Exception { + void testAggregateWithIndexStats() { List pipeline = jsonList("$indexStats: {}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -2201,7 +2201,7 @@ void testAggregateWithOut_illegal() { // Testing the official example from https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ (2022-11-22) @Test - void testAggregateWithMerge_officialExample() throws Exception { + void testAggregateWithMerge_officialExample() { syncClient.getDatabase("reporting").drop(); collection.insertMany(jsonList( @@ -2246,7 +2246,7 @@ void testAggregateWithMerge_officialExample() throws Exception { } @Test - void testAggregateWithMerge_otherCollection() throws Exception { + void testAggregateWithMerge_otherCollection() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2269,7 +2269,7 @@ void testAggregateWithMerge_otherCollection() throws Exception { } @Test - void testAggregateWithMerge_sameCollection() throws Exception { + void testAggregateWithMerge_sameCollection() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant', otherId: 4", "_id: 2, employee: 'Bee', otherId: 5", @@ -2300,7 +2300,7 @@ void testAggregateWithMerge_sameCollection() throws Exception { } @Test - void testAggregateWithMerge_mergeDocuments_simple() throws Exception { + void testAggregateWithMerge_mergeDocuments_simple() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2324,7 +2324,7 @@ void testAggregateWithMerge_mergeDocuments_simple() throws Exception { } @Test - void testAggregateWithMerge_mergeDocuments_complex() throws Exception { + void testAggregateWithMerge_mergeDocuments_complex() { collection.insertMany(jsonList( "_id: 1, x: 1", "_id: 2, x: { a: 1, b: 2 }", @@ -2355,7 +2355,7 @@ void testAggregateWithMerge_mergeDocuments_complex() throws Exception { } @Test - void testAggregateWithMerge_replaceDocuments() throws Exception { + void testAggregateWithMerge_replaceDocuments() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2381,7 +2381,7 @@ void testAggregateWithMerge_replaceDocuments() throws Exception { } @Test - void testAggregateWithMerge_keepExistingDocuments() throws Exception { + void testAggregateWithMerge_keepExistingDocuments() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2406,7 +2406,7 @@ void testAggregateWithMerge_keepExistingDocuments() throws Exception { } @Test - void testAggregateWithMerge_whenNotMatched_discard() throws Exception { + void testAggregateWithMerge_whenNotMatched_discard() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2433,7 +2433,7 @@ void testAggregateWithMerge_whenNotMatched_discard() throws Exception { } @Test - void testAggregateWithMerge_whenMatched_fail() throws Exception { + void testAggregateWithMerge_whenMatched_fail() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2455,7 +2455,7 @@ void testAggregateWithMerge_whenMatched_fail() throws Exception { } @Test - void testAggregateWithMerge_whenNotMatched_fail() throws Exception { + void testAggregateWithMerge_whenNotMatched_fail() { collection.insertMany(jsonList( "_id: 1, employee: 'Ant'", "_id: 2, employee: 'Bee'", @@ -2471,7 +2471,7 @@ void testAggregateWithMerge_whenNotMatched_fail() throws Exception { @Test - void testAggregateWithMerge_multipleOnFields() throws Exception { + void testAggregateWithMerge_multipleOnFields() { collection.insertMany(jsonList( "_id: 1, name: 'Ant', year: 2020, data: 'a'", "_id: 2, name: 'Bee', year: 2021, data: 'b'", @@ -2510,7 +2510,7 @@ void testAggregateWithMerge_multipleOnFields() throws Exception { } @Test - void testAggregateWithMerge_stringParameter() throws Exception { + void testAggregateWithMerge_stringParameter() { collection.insertMany(jsonList( "_id: 1, name: 'Ant', year: 2020, data: 'a'", "_id: 2, name: 'Bee', year: 2021, data: 'b'", @@ -2534,7 +2534,7 @@ void testAggregateWithMerge_stringParameter() throws Exception { } @Test - void testAggregateWithMerge_idMustNotBeModified_merge() throws Exception { + void testAggregateWithMerge_idMustNotBeModified_merge() { collection.insertMany(jsonList( "_id: 1, name: 'Ant'", "_id: 2, name: 'Bee'", @@ -2560,7 +2560,7 @@ void testAggregateWithMerge_idMustNotBeModified_merge() throws Exception { } @Test - void testAggregateWithMerge_idMustNotBeModified_replace() throws Exception { + void testAggregateWithMerge_idMustNotBeModified_replace() { collection.insertMany(jsonList( "_id: 1, name: 'Ant'", "_id: 2, name: 'Bee'", @@ -2586,7 +2586,7 @@ void testAggregateWithMerge_idMustNotBeModified_replace() throws Exception { } @Test - void testAggregateWithMerge_onWithoutUniqueIndex() throws Exception { + void testAggregateWithMerge_onWithoutUniqueIndex() { collection.insertOne(json("_id: 1")); assertThatExceptionOfType(MongoCommandException.class) @@ -2596,7 +2596,7 @@ void testAggregateWithMerge_onWithoutUniqueIndex() throws Exception { } @Test - void testAggregateWithMerge_onWithIndexWhichIsNotUnique() throws Exception { + void testAggregateWithMerge_onWithIndexWhichIsNotUnique() { collection.insertOne(json("_id: 1")); collection.createIndex(json("xyz: 1")); @@ -2607,7 +2607,7 @@ void testAggregateWithMerge_onWithIndexWhichIsNotUnique() throws Exception { } @Test - void testAggregateWithMerge_pipeline() throws Exception { + void testAggregateWithMerge_pipeline() { collection.insertOne(json("_id: 1")); MongoCollection otherCollection = db.getCollection("other"); @@ -2630,7 +2630,7 @@ void testAggregateWithMerge_pipeline() throws Exception { } @Test - void testAggregateWithMerge_pipeline_newVariable() throws Exception { + void testAggregateWithMerge_pipeline_newVariable() { collection.insertOne(json("_id: 1, obj: {a: 1, b: 'xyz'}")); MongoCollection otherCollection = db.getCollection("other"); @@ -2652,7 +2652,7 @@ void testAggregateWithMerge_pipeline_newVariable() throws Exception { } @Test - void testAggregateWithMerge_pipeline_nowVariable() throws Exception { + void testAggregateWithMerge_pipeline_nowVariable() { collection.insertOne(json("_id: 1")); MongoCollection otherCollection = db.getCollection("other"); @@ -2742,7 +2742,7 @@ private static Stream aggregateWithMerge_illegalParametersArguments() @ParameterizedTest @MethodSource("aggregateWithMerge_illegalParametersArguments") - void testAggregateWithMerge_illegalParameters(String merge, Class expectedException, String expectedMessage) throws Exception { + void testAggregateWithMerge_illegalParameters(String merge, Class expectedException, String expectedMessage) { collection.insertOne(json("_id: 1")); assertThatExceptionOfType(expectedException) @@ -2751,7 +2751,7 @@ void testAggregateWithMerge_illegalParameters(String merge, Class pipeline = jsonList("$project: {numItems: {$cond : [{$isArray : '$item'}, {$size: '$item'}, 0]}}"); assertThat(collection.aggregate(pipeline)).isEmpty(); @@ -2939,7 +2939,7 @@ void testProjectWithCondition() throws Exception { } @Test - void testAggregateWithSwitch() throws Exception { + void testAggregateWithSwitch() { collection.insertOne(json("_id: 1, name: 'Dave', qty: 1")); collection.insertOne(json("_id: 2, name: 'Carol', qty: 5")); collection.insertOne(json("_id: 3, name: 'Bob', qty: 10")); @@ -2971,7 +2971,7 @@ void testAggregateWithSwitch() throws Exception { } @Test - void testAggregateWithSwitchDefault() throws Exception { + void testAggregateWithSwitchDefault() { collection.insertOne(json("_id: 1, status: 'active'")); collection.insertOne(json("_id: 2, status: 'inactive'")); collection.insertOne(json("_id: 3, status: 'unknown'")); @@ -2999,7 +2999,7 @@ void testAggregateWithSwitchDefault() throws Exception { } @Test - void testAggregateWithSwitchMissingDefault() throws Exception { + void testAggregateWithSwitchMissingDefault() { collection.insertOne(json("_id: 1, value: 100")); List pipeline = jsonList(""" @@ -3020,7 +3020,7 @@ void testAggregateWithSwitchMissingDefault() throws Exception { } @Test - void testAggregateWithSwitchMissingBranches() throws Exception { + void testAggregateWithSwitchMissingBranches() { collection.insertOne(json("_id: 1, value: 100")); List pipeline = jsonList(""" @@ -3039,7 +3039,7 @@ void testAggregateWithSwitchMissingBranches() throws Exception { } @Test - void testAggregateWithSwitchEmptyBranches() throws Exception { + void testAggregateWithSwitchEmptyBranches() { collection.insertOne(json("_id: 1, value: 100")); List pipeline = jsonList(""" @@ -3060,7 +3060,7 @@ void testAggregateWithSwitchEmptyBranches() throws Exception { } @Test - void testAggregateWithSwitchInvalidBranch() throws Exception { + void testAggregateWithSwitchInvalidBranch() { collection.insertOne(json("_id: 1, value: 100")); List pipeline = jsonList(""" @@ -3082,7 +3082,7 @@ void testAggregateWithSwitchInvalidBranch() throws Exception { } @Test - void testAggregateWithSwitchInvalidArgument() throws Exception { + void testAggregateWithSwitchInvalidArgument() { collection.insertOne(json("_id: 1, value: 100")); List pipeline = jsonList(""" @@ -3105,7 +3105,7 @@ void testAggregateWithSwitchInvalidArgument() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/138 @Test - public void testAggregateWithGeoNear() throws Exception { + public void testAggregateWithGeoNear() { List pipeline = jsonList("$geoNear: {}"); assertThatExceptionOfType(MongoCommandException.class) @@ -3130,7 +3130,7 @@ private static Stream aggregateWithToDoubleArguments() { // https://github.com/bwaldvogel/mongo-java-server/issues/172 @ParameterizedTest @MethodSource("aggregateWithToDoubleArguments") - void testAggregateWithToInt(Object given, Double expected) throws Exception { + void testAggregateWithToInt(Object given, Double expected) { List pipeline = jsonList("$project: {value: {$toDouble: '$x'}}"); Document document = json("_id: 1"); @@ -3152,7 +3152,7 @@ private static Stream aggregateWithToDoubleArguments_illegalValue() { @ParameterizedTest @MethodSource("aggregateWithToDoubleArguments_illegalValue") - void testAggregateWithConvertToDouble_illegalValue(Object given, String expectedMessagePart) throws Exception { + void testAggregateWithConvertToDouble_illegalValue(Object given, String expectedMessagePart) { List pipeline = jsonList("$project: {value: {$toDouble: '$x'}}"); collection.insertOne(json("_id: 1").append("x", given)); @@ -3181,7 +3181,7 @@ private static Stream aggregateWithToDateArguments() { @ParameterizedTest @MethodSource("aggregateWithToDateArguments") - void testAggregateWithToDate(Object given, Instant expected) throws Exception { + void testAggregateWithToDate(Object given, Instant expected) { List pipeline = jsonList("$project: {value: {$toDate: '$x'}}"); Document document = json("_id: 1"); @@ -3206,7 +3206,7 @@ private static Stream aggregateWithToDateArguments_illegalValue() { @ParameterizedTest @MethodSource("aggregateWithToDateArguments_illegalValue") - void testAggregateWithConvertToDate_illegalValue(Object given, String expectedMessagePart) throws Exception { + void testAggregateWithConvertToDate_illegalValue(Object given, String expectedMessagePart) { List pipeline = jsonList("$project: {value: {$toDate: '$x'}}"); collection.insertOne(json("_id: 1").append("x", given)); @@ -3229,7 +3229,7 @@ private static Stream aggregateWithToIntArguments() { @ParameterizedTest @MethodSource("aggregateWithToIntArguments") - void testAggregateWithToInt(Object given, Integer expected) throws Exception { + void testAggregateWithToInt(Object given, Integer expected) { List pipeline = jsonList("$project: {value: {$toInt: '$x'}}"); Document document = json("_id: 1"); @@ -3251,7 +3251,7 @@ private static Stream aggregateWithToIntArguments_illegalValue() { @ParameterizedTest @MethodSource("aggregateWithToIntArguments_illegalValue") - void testAggregateWithConvertToInt_illegalValue(Object given, String expectedMessagePart) throws Exception { + void testAggregateWithConvertToInt_illegalValue(Object given, String expectedMessagePart) { List pipeline = jsonList("$project: {value: {$toInt: '$x'}}"); collection.insertOne(json("_id: 1").append("x", given)); @@ -3291,7 +3291,7 @@ private static Stream aggregateWithToBoolArguments() { @ParameterizedTest @MethodSource("aggregateWithToBoolArguments") - void testAggregateWithToBool(Object given, Boolean expected) throws Exception { + void testAggregateWithToBool(Object given, Boolean expected) { List pipeline = jsonList("$project: {value: {$toBool: '$x'}}"); Document document = json("_id: 1"); @@ -3319,7 +3319,7 @@ private static Stream aggregateWithToLongArguments() { @ParameterizedTest @MethodSource("aggregateWithToLongArguments") - void testAggregateWithToLong(Object given, Long expected) throws Exception { + void testAggregateWithToLong(Object given, Long expected) { List pipeline = jsonList("$project: {value: {$toLong: '$x'}}"); Document document = json("_id: 1"); @@ -3341,7 +3341,7 @@ private static Stream aggregateWithToLongArguments_illegalValue() { @ParameterizedTest @MethodSource("aggregateWithToLongArguments_illegalValue") - void testAggregateWithConvertToLong_illegalValue(Object given, String expectedMessagePart) throws Exception { + void testAggregateWithConvertToLong_illegalValue(Object given, String expectedMessagePart) { List pipeline = jsonList("$project: {value: {$toLong: '$x'}}"); collection.insertOne(json("_id: 1").append("x", given)); @@ -3361,7 +3361,7 @@ private static Stream aggregateWithToObjectIdArguments() { @ParameterizedTest @MethodSource("aggregateWithToObjectIdArguments") - void testAggregateWithToObjectId(Object given, ObjectId expected) throws Exception { + void testAggregateWithToObjectId(Object given, ObjectId expected) { List pipeline = jsonList("$project: {value: {$toObjectId: '$x'}}"); Document document = json("_id: 1"); @@ -3385,7 +3385,7 @@ private static Stream aggregateWithToObjectIdArguments_illegalValue() @ParameterizedTest @MethodSource("aggregateWithToObjectIdArguments_illegalValue") - void testAggregateWithConvertToObjectId_illegalValue(Object given, String expectedMessagePart) throws Exception { + void testAggregateWithConvertToObjectId_illegalValue(Object given, String expectedMessagePart) { List pipeline = jsonList("$project: {value: {$toObjectId: '$x'}}"); collection.insertOne(json("_id: 1").append("x", given)); @@ -3427,7 +3427,7 @@ private static Stream aggregateWithConvertArguments() { @ParameterizedTest @MethodSource("aggregateWithConvertArguments") - void testAggregateWithConvert_literals(String given, Object expected) throws Exception { + void testAggregateWithConvert_literals(String given, Object expected) { List pipeline = List.of(new Document("$project", new Document("value", new Document("$convert", json(given))))); @@ -3441,7 +3441,7 @@ void testAggregateWithConvert_literals(String given, Object expected) throws Exc @ParameterizedTest @MethodSource("aggregateWithConvertArguments") - void testAggregateWithConvert_indirect(String given, Object expected) throws Exception { + void testAggregateWithConvert_indirect(String given, Object expected) { Document convertDocument = json(given); Object inputValue = convertDocument.put("input", "$x"); @@ -3483,7 +3483,7 @@ private static Stream aggregateWithConvertArguments_illegalValue() { @ParameterizedTest @MethodSource("aggregateWithConvertArguments_illegalValue") - void testAggregateWithConvert_illegalValue(String given, String expectedMessageStartingWith) throws Exception { + void testAggregateWithConvert_illegalValue(String given, String expectedMessageStartingWith) { List pipeline = List.of(new Document("$project", new Document("value", new Document("$convert", json(given))))); @@ -3495,7 +3495,7 @@ void testAggregateWithConvert_illegalValue(String given, String expectedMessageS } @Test - void testAggregateWithConvert_noDocument() throws Exception { + void testAggregateWithConvert_noDocument() { List pipeline = List.of(new Document("$project", new Document("value", new Document("$convert", 123)))); @@ -3508,7 +3508,7 @@ void testAggregateWithConvert_noDocument() throws Exception { } @Test - void testSampleAggregation() throws Exception { + void testSampleAggregation() { for (int i = 0; i < 20; i++) { collection.insertOne(json("flag: 1")); } @@ -3534,7 +3534,7 @@ void testSampleAggregation() throws Exception { } @Test - void testSampleAggregation_illegalParameters() throws Exception { + void testSampleAggregation_illegalParameters() { collection.insertOne(json("_id: 1")); assertThatExceptionOfType(MongoCommandException.class) diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendSpringDataTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendSpringDataTest.java index 03cc6b356..aca3d5a85 100644 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendSpringDataTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractBackendSpringDataTest.java @@ -89,14 +89,14 @@ protected String getDatabaseName() { private MongoTemplate mongoTemplate; @BeforeEach - void deleteAll() throws Exception { + void deleteAll() { accountRepository.deleteAll(); personRepository.deleteAll(); testRepository.deleteAll(); } @Test - public void testSaveFindModifyAndUpdate() throws Exception { + public void testSaveFindModifyAndUpdate() { Person billy = personRepository.save(new Person("Billy", 123)); personRepository.save(new Person("Joe", 456)); @@ -132,7 +132,7 @@ public void testSaveFindModifyAndUpdate() throws Exception { } @Test - public void testInsertDuplicateThrows() throws Exception { + public void testInsertDuplicateThrows() { personRepository.save(new Person("Billy", 1)); personRepository.save(new Person("Alice", 2)); @@ -150,7 +150,7 @@ public void testInsertDuplicateThrows() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/39 @Test - public void testDeleteWithUniqueIndexes() throws Exception { + public void testDeleteWithUniqueIndexes() { TestEntity document = testRepository.save(new TestEntity("DOC_1", "Text1")); // update value of indexed property @@ -168,7 +168,7 @@ public void testDeleteWithUniqueIndexes() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/66 @Test - public void testCountByValueData() throws Exception { + public void testCountByValueData() { testRepository.save(new TestEntity("DOC_1", "Text1") .withValue(new SubEntity("v1"))); @@ -185,7 +185,7 @@ public void testCountByValueData() throws Exception { // https://github.com/bwaldvogel/mongo-java-server/issues/148 @Test - void testAggregation() throws Exception { + void testAggregation() { testRepository.save(new TestEntity("1", "text")); Aggregation agg = Aggregation.newAggregation( diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractOplogTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractOplogTest.java index 6592fa3df..81d52fbeb 100755 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractOplogTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractOplogTest.java @@ -64,7 +64,7 @@ protected MongoCollection getOplogCollection() { } @Test - void testListDatabaseNames() throws Exception { + void testListDatabaseNames() { assertThat(listDatabaseNames()).contains(LOCAL_DATABASE); collection.insertOne(json("")); assertThat(listDatabaseNames()).containsExactlyInAnyOrder(db.getName(), LOCAL_DATABASE); @@ -124,7 +124,7 @@ void testOplogInsertUpdateAndDelete() { } @Test - void testQueryOplogWhenOplogIsDisabled() throws Exception { + void testQueryOplogWhenOplogIsDisabled() { backend.disableOplog(); collection.insertOne(json("_id: 1")); assertThat(getOplogCollection().find()).isEmpty(); diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractPerformanceTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractPerformanceTest.java index 81771c629..06100f1dd 100755 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractPerformanceTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractPerformanceTest.java @@ -17,7 +17,7 @@ public abstract class AbstractPerformanceTest extends AbstractTest { // https://github.com/bwaldvogel/mongo-java-server/issues/84 @Test @EnabledIfSystemProperty(named = "run-mongo-java-server-performance-tests", matches = "true") - public void testComplexUpsert() throws Exception { + public void testComplexUpsert() { Document incUpdate = new Document(); Document updateQuery = new Document("$inc", incUpdate); incUpdate.put("version", 1); diff --git a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractTest.java b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractTest.java index 46e888bae..00de7b6a8 100644 --- a/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractTest.java +++ b/test-common/src/main/java/de/bwaldvogel/mongo/backend/AbstractTest.java @@ -58,10 +58,10 @@ public abstract class AbstractTest { protected static ConnectionString connectionString; protected static MongoBackend backend; - protected abstract MongoBackend createBackend() throws Exception; + protected abstract MongoBackend createBackend(); @BeforeEach - public void setUp() throws Exception { + public void setUp() { clock.reset(); if (connectionString == null) { setUpBackend(); @@ -103,7 +103,7 @@ public static void tearDown() { tearDownBackend(); } - private static void setUpClients() throws Exception { + private static void setUpClients() { MongoClientSettings mongoClientSettings = MongoClientSettings.builder() .applyConnectionString(connectionString) .uuidRepresentation(UuidRepresentation.STANDARD) @@ -118,7 +118,7 @@ private static void setUpClients() throws Exception { asyncCollection = asyncDb.getCollection(namespace.getCollectionName()); } - protected void setUpBackend() throws Exception { + protected void setUpBackend() { backend = createBackend(); mongoServer = new MongoServer(backend); connectionString = new ConnectionString(mongoServer.bindAndGetConnectionString()); @@ -141,7 +141,7 @@ private static void tearDownBackend() { connectionString = null; } - protected void restart() throws Exception { + protected void restart() { tearDown(); setUp(); } diff --git a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoAggregationTest.java b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoAggregationTest.java index 86675a003..da81ef224 100644 --- a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoAggregationTest.java +++ b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoAggregationTest.java @@ -12,19 +12,19 @@ public class RealMongoAggregationTest extends AbstractAggregationTest { static RealMongoContainer realMongoContainer = new RealMongoContainer(); @Override - protected void setUpBackend() throws Exception { + protected void setUpBackend() { connectionString = realMongoContainer.getConnectionString(); } @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { throw new UnsupportedOperationException(); } @Test @Override @Disabled - public void testAggregateWithGeoNear() throws Exception { + public void testAggregateWithGeoNear() { super.testAggregateWithGeoNear(); } } diff --git a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java index 459f87a45..6831f3cf3 100644 --- a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java +++ b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoBackendTest.java @@ -24,7 +24,7 @@ public class RealMongoBackendTest extends AbstractBackendTest { @Override @BeforeEach - public void setUp() throws Exception { + public void setUp() { super.setUp(); dropAllDatabases(); } @@ -35,7 +35,7 @@ protected void setUpBackend() { } @Override - protected void restart() throws Exception { + protected void restart() { tearDown(); realMongoContainer.restart(); setUp(); diff --git a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoContainer.java b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoContainer.java index 0339dd26c..95c9b7e8d 100644 --- a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoContainer.java +++ b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoContainer.java @@ -19,12 +19,12 @@ public class RealMongoContainer implements BeforeAllCallback, AfterAllCallback { private GenericContainer mongoContainer; @Override - public void beforeAll(ExtensionContext context) throws Exception { + public void beforeAll(ExtensionContext context) { mongoContainer = startIfNecessary(); } @Override - public void afterAll(ExtensionContext context) throws Exception { + public void afterAll(ExtensionContext context) { if (mongoContainer != null) { mongoContainer.stop(); } diff --git a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoPerformanceTest.java b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoPerformanceTest.java index bef0201a0..65b748a56 100644 --- a/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoPerformanceTest.java +++ b/test-common/src/test/java/de/bwaldvogel/mongo/RealMongoPerformanceTest.java @@ -16,7 +16,7 @@ public static void setUpMongoContainer() { } @Override - protected void setUpBackend() throws Exception { + protected void setUpBackend() { connectionString = RealMongoContainer.getConnectionString(mongoContainer); } @@ -27,14 +27,14 @@ public static void tearDownServer() { } @Override - protected void restart() throws Exception { + protected void restart() { tearDown(); tearDownServer(); setUp(); } @Override - protected MongoBackend createBackend() throws Exception { + protected MongoBackend createBackend() { throw new UnsupportedOperationException(); } From 073dd2403e46ed46af3ba46ccd9348cfa4a596b9 Mon Sep 17 00:00:00 2001 From: Benedikt Waldvogel Date: Sun, 15 Nov 2026 22:49:28 +0100 Subject: [PATCH 2/2] Use pattern switches for BSON type dispatch Replace suitable type-based if/else chains in expression conversion, BSON cloning, lookup configuration, query matching, wire message handling and PostgreSQL value conversion. Preserve null and Missing handling and mutable collection results. --- .../mongo/backend/DefaultQueryMatcher.java | 30 +-- .../de/bwaldvogel/mongo/backend/Utils.java | 58 ++--- .../mongo/backend/aggregation/Expression.java | 226 +++++++++--------- .../backend/aggregation/ExpressionTraits.java | 15 +- .../stage/AbstractLookupStage.java | 24 +- .../de/bwaldvogel/mongo/bson/Document.java | 28 +-- .../mongo/wire/MongoDatabaseHandler.java | 26 +- .../backend/postgresql/PostgresqlUtils.java | 37 ++- 8 files changed, 208 insertions(+), 236 deletions(-) diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java b/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java index 4d81d39b0..5ccc2ff73 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java @@ -3,7 +3,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.regex.Matcher; import java.util.stream.Collectors; @@ -514,25 +513,18 @@ private boolean checkExpressionMatch(Object value, Object expressionValue, Strin } static boolean matchTypes(Object value, Object expressionValue) { - if (Objects.equals(expressionValue, "number")) { - List types = Stream.of(BsonType.INT, BsonType.LONG, BsonType.DOUBLE, BsonType.DECIMAL128) - .map(BsonType::getAlias) - .collect(Collectors.toList()); - return matchTypes(value, types); - } else if (expressionValue instanceof String stringValue) { - return matchTypes(value, BsonType.forString(stringValue)); - } else if (expressionValue instanceof Number numberValue) { - return matchTypes(value, BsonType.forNumber(numberValue)); - } else if (expressionValue instanceof Collection values) { - for (Object type : values) { - if (matchTypes(value, type)) { - return true; - } + return switch (expressionValue) { + case String stringValue when stringValue.equals("number") -> { + List types = Stream.of(BsonType.INT, BsonType.LONG, BsonType.DOUBLE, BsonType.DECIMAL128) + .map(BsonType::getAlias) + .collect(Collectors.toList()); + yield matchTypes(value, types); } - return false; - } else { - throw new MongoServerError(ErrorCode.TypeMismatch, "type must be represented as a number or a string"); - } + case String stringValue -> matchTypes(value, BsonType.forString(stringValue)); + case Number numberValue -> matchTypes(value, BsonType.forNumber(numberValue)); + case Collection values -> values.stream().anyMatch(type -> matchTypes(value, type)); + case null, default -> throw new MongoServerError(ErrorCode.TypeMismatch, "type must be represented as a number or a string"); + }; } private static boolean matchTypes(Object value, BsonType type) { diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/Utils.java b/core/src/main/java/de/bwaldvogel/mongo/backend/Utils.java index d703afba0..b4676c5f3 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/Utils.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/Utils.java @@ -89,48 +89,42 @@ public static String getCollectionNameFromFullName(String fullName) { } public static boolean isTrue(Object value) { - if (Missing.isNullOrMissing(value)) { - return false; - } - - if (value instanceof Boolean bool) { - return bool.booleanValue(); - } - - if (value instanceof Number number) { - return number.doubleValue() != 0.0; - } - - return true; + return switch (value) { + case null -> false; + case Missing ignored -> false; + case Boolean bool -> bool.booleanValue(); + case Number number -> number.doubleValue() != 0.0; + default -> true; + }; } static Object normalizeValue(Object value) { if (Missing.isNullOrMissing(value)) { return null; } - if (value instanceof Long && cannotBeRepresentedAsDouble((Long) value)) { - return value; - } else if (value instanceof Number number) { - double doubleValue = number.doubleValue(); - if (doubleValue == -0.0) { - doubleValue = 0.0; + return switch (value) { + case Long longValue when cannotBeRepresentedAsDouble(longValue) -> longValue; + case Number number -> { + double doubleValue = number.doubleValue(); + if (doubleValue == -0.0) { + doubleValue = 0.0; + } + yield Double.valueOf(doubleValue); } - return Double.valueOf(doubleValue); - } else if (value instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) value; - Document result = new Document(); - for (Entry entry : map.entrySet()) { - result.put(entry.getKey(), normalizeValue(entry.getValue())); + case Map mapValue -> { + @SuppressWarnings("unchecked") + Map map = (Map) mapValue; + Document result = new Document(); + for (Entry entry : map.entrySet()) { + result.put(entry.getKey(), normalizeValue(entry.getValue())); + } + yield result; } - return result; - } else if (value instanceof Collection collection) { - return collection.stream() + case Collection collection -> collection.stream() .map(Utils::normalizeValue) .collect(Collectors.toList()); - } else { - return value; - } + default -> value; + }; } private static boolean cannotBeRepresentedAsDouble(Long value) { diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java index 847e50f5e..897bef173 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java @@ -369,15 +369,12 @@ Object apply(List expression, Document document) { private BsonType getBsonType(Object to) { try { - if (to instanceof String toString) { - return BsonType.forString(toString); - } else if (to instanceof Integer toNumber) { - return BsonType.forNumber(toNumber); - } else if (to instanceof Number) { - throw new IllegalArgumentException("In $convert, numeric 'to' argument is not an integer"); - } else { - throw new IllegalArgumentException("$convert's 'to' argument must be a string or number, but is " + describeType(to)); - } + return switch (to) { + case String toString -> BsonType.forString(toString); + case Integer toNumber -> BsonType.forNumber(toNumber); + case Number ignored -> throw new IllegalArgumentException("In $convert, numeric 'to' argument is not an integer"); + case null, default -> throw new IllegalArgumentException("$convert's 'to' argument must be a string or number, but is " + describeType(to)); + }; } catch (BadValueException e) { throw new FailedToOptimizePipelineError(ErrorCode.BadValue, "Unknown type name: " + to); } catch (IllegalArgumentException e) { @@ -1597,13 +1594,12 @@ Boolean apply(List expressionValue, Document document) { Object value = requireSingleValue(expressionValue); if (Missing.isNullOrMissing(value)) { return null; - } else if (value instanceof Number number) { - return number.doubleValue() != 0.0; - } else if (value instanceof Boolean) { - return (Boolean) value; - } else { - return true; } + return switch (value) { + case Number number -> number.doubleValue() != 0.0; + case Boolean booleanValue -> booleanValue; + default -> true; + }; } }, @@ -1616,35 +1612,35 @@ Instant apply(List expressionValue, Document document) { Object value = requireSingleValue(expressionValue); if (Missing.isNullOrMissing(value)) { return null; - } else if (value instanceof Long || value instanceof Double) { - Number number = (Number) value; - return Instant.ofEpochMilli(number.longValue()); - } else if (value instanceof Instant) { - return (Instant) value; - } else if (value instanceof String dateString) { - try { - return Instant.parse(dateString); - } catch (DateTimeParseException e1) { + } + return switch (value) { + case Long millis -> Instant.ofEpochMilli(millis); + case Double millis -> Instant.ofEpochMilli(millis.longValue()); + case Instant instant -> instant; + case String dateString -> { try { - return LocalDate.parse(dateString).atStartOfDay(ZoneOffset.UTC).toInstant(); - } catch (DateTimeParseException e2) { + yield Instant.parse(dateString); + } catch (DateTimeParseException e1) { try { - return ZonedDateTime.parse(dateString, OFFSET_DATE_TIME).toInstant(); - } catch (DateTimeParseException e3) { + yield LocalDate.parse(dateString).atStartOfDay(ZoneOffset.UTC).toInstant(); + } catch (DateTimeParseException e2) { try { - TemporalAccessor temporalAccessor = YEAR_MONTH.parse(dateString); - int year = temporalAccessor.get(ChronoField.YEAR); - int month = temporalAccessor.get(ChronoField.MONTH_OF_YEAR); - return LocalDate.of(year, month, 1).atStartOfDay(ZoneOffset.UTC).toInstant(); - } catch (DateTimeParseException e) { - throw new ConversionFailureException("Error parsing date string '" + dateString + "';"); + yield ZonedDateTime.parse(dateString, OFFSET_DATE_TIME).toInstant(); + } catch (DateTimeParseException e3) { + try { + TemporalAccessor temporalAccessor = YEAR_MONTH.parse(dateString); + int year = temporalAccessor.get(ChronoField.YEAR); + int month = temporalAccessor.get(ChronoField.MONTH_OF_YEAR); + yield LocalDate.of(year, month, 1).atStartOfDay(ZoneOffset.UTC).toInstant(); + } catch (DateTimeParseException e) { + throw new ConversionFailureException("Error parsing date string '" + dateString + "';"); + } } } } } - } else { - throw new UnsupportedConversionError(value, Instant.class); - } + default -> throw new UnsupportedConversionError(value, Instant.class); + }; } }, @@ -1654,22 +1650,21 @@ Double apply(List expressionValue, Document document) { Object value = requireSingleValue(expressionValue); if (Missing.isNullOrMissing(value)) { return null; - } else if (value instanceof Number number) { - return number.doubleValue(); - } else if (value instanceof Boolean booleanValue) { - return booleanValue.booleanValue() ? 1.0 : 0.0; - } else if (value instanceof Instant instant) { - return (double) instant.toEpochMilli(); - } else if (value instanceof String string) { - try { - return Double.valueOf(string); - } catch (NumberFormatException e) { - throw new ConversionFailureException("Failed to parse number '" + value - + "' in $convert with no onError value: Did not consume whole number."); - } - } else { - throw new UnsupportedConversionError(value, Double.class); } + return switch (value) { + case Number number -> number.doubleValue(); + case Boolean booleanValue -> booleanValue.booleanValue() ? 1.0 : 0.0; + case Instant instant -> (double) instant.toEpochMilli(); + case String string -> { + try { + yield Double.valueOf(string); + } catch (NumberFormatException e) { + throw new ConversionFailureException("Failed to parse number '" + value + + "' in $convert with no onError value: Did not consume whole number."); + } + } + default -> throw new UnsupportedConversionError(value, Double.class); + }; } }, @@ -1679,20 +1674,20 @@ Integer apply(List expressionValue, Document document) { Object value = requireSingleValue(expressionValue); if (Missing.isNullOrMissing(value)) { return null; - } else if (value instanceof Number number) { - return number.intValue(); - } else if (value instanceof Boolean booleanValue) { - return booleanValue.booleanValue() ? 1 : 0; - } else if (value instanceof String string) { - try { - return Integer.valueOf(string); - } catch (NumberFormatException e) { - throw new ConversionFailureException("Failed to parse number '" + value - + "' in $convert with no onError value."); - } - } else { - throw new UnsupportedConversionError(value, Integer.class); } + return switch (value) { + case Number number -> number.intValue(); + case Boolean booleanValue -> booleanValue.booleanValue() ? 1 : 0; + case String string -> { + try { + yield Integer.valueOf(string); + } catch (NumberFormatException e) { + throw new ConversionFailureException("Failed to parse number '" + value + + "' in $convert with no onError value."); + } + } + default -> throw new UnsupportedConversionError(value, Integer.class); + }; } }, @@ -1702,22 +1697,21 @@ Long apply(List expressionValue, Document document) { Object value = requireSingleValue(expressionValue); if (Missing.isNullOrMissing(value)) { return null; - } else if (value instanceof Number number) { - return number.longValue(); - } else if (value instanceof Boolean booleanValue) { - return booleanValue.booleanValue() ? 1L : 0L; - } else if (value instanceof Instant instant) { - return instant.toEpochMilli(); - } else if (value instanceof String string) { - try { - return Long.valueOf(string); - } catch (NumberFormatException e) { - throw new ConversionFailureException("Failed to parse number '" + value - + "' in $convert with no onError value."); - } - } else { - throw new UnsupportedConversionError(value, Long.class); } + return switch (value) { + case Number number -> number.longValue(); + case Boolean booleanValue -> booleanValue.booleanValue() ? 1L : 0L; + case Instant instant -> instant.toEpochMilli(); + case String string -> { + try { + yield Long.valueOf(string); + } catch (NumberFormatException e) { + throw new ConversionFailureException("Failed to parse number '" + value + + "' in $convert with no onError value."); + } + } + default -> throw new UnsupportedConversionError(value, Long.class); + }; } }, @@ -1822,49 +1816,49 @@ public static Object evaluateDocument(Object documentWithExpression, Document do } static Object evaluate(Object expression, Document document) { - if (expression instanceof String expressionString && expressionString.startsWith("$")) { - if (KEYWORD_EXPRESSIONS.contains(expression)) { - return expression; - } - String value = expressionString.substring(1); - if (value.startsWith("$")) { - final String variableName; - if (value.contains(".")) { - variableName = value.substring(0, value.indexOf('.')); - } else { - variableName = value; - } - - Object variableValue = Utils.getSubdocumentValue(document, variableName); - if (variableValue instanceof Missing) { - if (variableName.equals("$ROOT")) { - variableValue = document; - } else if (variableName.equals("$NOW")) { - variableValue = Instant.now(); + return switch (expression) { + case String expressionString when expressionString.startsWith("$") -> { + if (KEYWORD_EXPRESSIONS.contains(expression)) { + yield expression; + } + String value = expressionString.substring(1); + if (value.startsWith("$")) { + final String variableName; + if (value.contains(".")) { + variableName = value.substring(0, value.indexOf('.')); } else { - throw new MongoServerError(17276, "Use of undefined variable: " + variableName.substring(1)); + variableName = value; } - } - if (variableValue instanceof String variableValueString) { - if (variableValueString.startsWith("$")) { - variableValue = evaluate(variableValue, document); + Object variableValue = Utils.getSubdocumentValue(document, variableName); + if (variableValue instanceof Missing) { + if (variableName.equals("$ROOT")) { + variableValue = document; + } else if (variableName.equals("$NOW")) { + variableValue = Instant.now(); + } else { + throw new MongoServerError(17276, "Use of undefined variable: " + variableName.substring(1)); + } } - } - if (!value.equals(variableName)) { - String path = value.substring(variableName.length() + 1); - return Utils.getSubdocumentValue((Document) variableValue, path); - } else { - return variableValue; + if (variableValue instanceof String variableValueString) { + if (variableValueString.startsWith("$")) { + variableValue = evaluate(variableValue, document); + } + } + + if (!value.equals(variableName)) { + String path = value.substring(variableName.length() + 1); + yield Utils.getSubdocumentValue((Document) variableValue, path); + } else { + yield variableValue; + } } + yield Utils.getSubdocumentValueCollectionAware(document, value); } - return Utils.getSubdocumentValueCollectionAware(document, value); - } else if (expression instanceof Document expressionDoc) { - return evaluateDocumentExpression(expressionDoc, document); - } else { - return expression; - } + case Document expressionDoc -> evaluateDocumentExpression(expressionDoc, document); + case null, default -> expression; + }; } private static Object evaluateDocumentExpression(Document expression, Document document) { diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTraits.java b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTraits.java index 796dffa1d..b448f9840 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTraits.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/ExpressionTraits.java @@ -228,14 +228,13 @@ default String evaluateString(List expressionValue, Function default String convertToString(Object value) { if (isNullOrMissing(value)) { return null; - } else if (value instanceof String string) { - return string; - } else if (value instanceof Number) { - return value.toString(); - } else if (value instanceof ObjectId objectId) { - return objectId.getHexData(); - } - throw new MongoServerError(16007, "can't convert from BSON type " + describeType(value) + " to String"); + } + return switch (value) { + case String string -> string; + case Number number -> number.toString(); + case ObjectId objectId -> objectId.getHexData(); + default -> throw new MongoServerError(16007, "can't convert from BSON type " + describeType(value) + " to String"); + }; } } diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/stage/AbstractLookupStage.java b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/stage/AbstractLookupStage.java index 2dea52109..975d960fe 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/stage/AbstractLookupStage.java +++ b/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/stage/AbstractLookupStage.java @@ -19,24 +19,20 @@ public String name() { String readStringConfigurationProperty(Document configuration, String name) { Object value = configuration.get(name); - if (value == null) { - throw new FailedToParseException("missing '" + name + "' option to " + name() + " stage specification: " + configuration); - } - if (value instanceof String string) { - return string; - } - throw new FailedToParseException("'" + name + "' option to " + name() + " must be a string, but was type " + Utils.describeType(value)); + return switch (value) { + case null -> throw new FailedToParseException("missing '" + name + "' option to " + name() + " stage specification: " + configuration); + case String string -> string; + default -> throw new FailedToParseException("'" + name + "' option to " + name() + " must be a string, but was type " + Utils.describeType(value)); + }; } Document readOptionalDocumentArgument(Document configuration, String name) { Object value = configuration.get(name); - if (value == null) { - return new Document(); - } - if (value instanceof Document document) { - return document; - } - throw new FailedToParseException(name() + " argument '" + name + ": " + Json.toJsonValue(value) + "' must be an object, is type " + Utils.describeType(value)); + return switch (value) { + case null -> new Document(); + case Document document -> document; + default -> throw new FailedToParseException(name() + " argument '" + name + ": " + Json.toJsonValue(value) + "' must be an object, is type " + Utils.describeType(value)); + }; } void ensureAllConfigurationPropertiesAreKnown(Document configuration, Set configurationKeys) { diff --git a/core/src/main/java/de/bwaldvogel/mongo/bson/Document.java b/core/src/main/java/de/bwaldvogel/mongo/bson/Document.java index a5a632d6b..897e7158d 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/bson/Document.java +++ b/core/src/main/java/de/bwaldvogel/mongo/bson/Document.java @@ -44,27 +44,23 @@ public Document cloneDeeply() { @SuppressWarnings("unchecked") private static T cloneDeeply(T object) { - if (object == null) { - return null; - } else if (object instanceof Document document) { - Document clone = document.clone(); - for (String key : document.keySet()) { - clone.put(key, cloneDeeply(clone.get(key))); + return switch (object) { + case null -> null; + case Document document -> { + Document clone = document.clone(); + for (String key : document.keySet()) { + clone.put(key, cloneDeeply(clone.get(key))); + } + yield (T) clone; } - return (T) clone; - } else if (object instanceof List list) { - List result = list.stream() + case List list -> (T) list.stream() .map(Document::cloneDeeply) .collect(Collectors.toList()); - return (T) result; - } else if (object instanceof Set set) { - Set result = set.stream() + case Set set -> (T) set.stream() .map(Document::cloneDeeply) .collect(Collectors.toCollection(LinkedHashSet::new)); - return (T) result; - } else { - return object; - } + default -> object; + }; } public Document append(String key, Object value) { diff --git a/core/src/main/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandler.java b/core/src/main/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandler.java index f8299aff1..0645430a0 100644 --- a/core/src/main/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandler.java +++ b/core/src/main/java/de/bwaldvogel/mongo/wire/MongoDatabaseHandler.java @@ -58,19 +58,21 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { @Override protected void channelRead0(ChannelHandlerContext ctx, ClientRequest object) { - if (object instanceof MongoQuery mongoQuery) { - MongoReply mongoReply = handleQuery(mongoQuery, ctx.channel().remoteAddress()); - ctx.channel().writeAndFlush(mongoReply); - } else if (object instanceof MongoMessage mongoMessage) { - MongoMessage response = handleMessage(mongoMessage, ctx.channel().remoteAddress()); - if (mongoMessage.isMoreToCome()) { - // the client does not read a reply, so sending one would desynchronize the connection - log.debug("not replying to {} with moreToCome set", mongoMessage); - return; + switch (object) { + case MongoQuery mongoQuery -> { + MongoReply mongoReply = handleQuery(mongoQuery, ctx.channel().remoteAddress()); + ctx.channel().writeAndFlush(mongoReply); } - ctx.channel().writeAndFlush(response); - } else { - throw new MongoServerException("unknown message: " + object); + case MongoMessage mongoMessage -> { + MongoMessage response = handleMessage(mongoMessage, ctx.channel().remoteAddress()); + if (mongoMessage.isMoreToCome()) { + // the client does not read a reply, so sending one would desynchronize the connection + log.debug("not replying to {} with moreToCome set", mongoMessage); + return; + } + ctx.channel().writeAndFlush(response); + } + case null, default -> throw new MongoServerException("unknown message: " + object); } } diff --git a/postgresql-backend/src/main/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtils.java b/postgresql-backend/src/main/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtils.java index d1203a660..84bcb8fde 100644 --- a/postgresql-backend/src/main/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtils.java +++ b/postgresql-backend/src/main/java/de/bwaldvogel/mongo/backend/postgresql/PostgresqlUtils.java @@ -42,26 +42,25 @@ static String toNormalizedDataKey(String key) { public static String toQueryValue(Object queryValue) { Objects.requireNonNull(queryValue); - if (queryValue instanceof String) { - return (String) queryValue; - } else if (queryValue instanceof Number) { - if (((Number) queryValue).doubleValue() == -0.0) { - return "0"; + return switch (queryValue) { + case String string -> string; + case Number number -> { + if (number.doubleValue() == -0.0) { + yield "0"; + } + String numberString = number.toString(); + yield numberString.replaceAll("^(\\d+)\\.0+$", "$1"); } - String numberString = queryValue.toString(); - return numberString.replaceAll("^(\\d+)\\.0+$", "$1"); - } else if (queryValue instanceof Document) { - return toJsonWithClass(queryValue); - } else if (queryValue instanceof Map) { - return toJson(queryValue); - } else if (queryValue instanceof List) { - List values = ((List) queryValue).stream() - .map(value -> value instanceof Missing ? null : value) - .collect(Collectors.toList()); - return toJson(values); - } else { - return toJsonWithClass(queryValue); - } + case Document document -> toJsonWithClass(document); + case Map map -> toJson(map); + case List list -> { + List values = list.stream() + .map(value -> value instanceof Missing ? null : value) + .collect(Collectors.toList()); + yield toJson(values); + } + default -> toJsonWithClass(queryValue); + }; } private static String toJsonWithClass(Object queryValue) {