@@ -630,29 +630,30 @@ void testAggregateWithNestedInclusiveProjection() throws Exception {
630630 );
631631 }
632632
633- @ Test
634- void testAggregateWithIllegalProjection () throws Exception {
635- List <Document > pipeline = jsonList ("$project: {'x.b': 1, 'x.c': 1, 'x.d': 0, y: 0}" );
633+ private static Stream <Arguments > aggregateWithProjectionArguments () {
634+ return Stream .of (
635+ Arguments .of ("$project: {'x.b': 1, 'x.c': 1, 'x.d': 0, y: 0}" ,
636+ "Command failed with error 31254 (Location31254): 'Invalid $project :: caused by :: Cannot do exclusion on field x.d in inclusion projection'" ),
636637
637- collection .insertOne (json ("_id: 1" ));
638+ Arguments .of ("$project: {_id: 0, v: '$x.1.'}" ,
639+ "Command failed with error 40353 (Location40353): 'Invalid $project :: caused by :: FieldPath must not end with a '.'.'" ),
638640
639- assertThatExceptionOfType (MongoCommandException .class )
640- .isThrownBy (() -> collection .aggregate (pipeline ).first ())
641- .withMessageContaining ("Command failed with error 31254 (Location31254): " +
642- "'Invalid $project :: caused by :: Cannot do exclusion on field x.d in inclusion projection'" );
641+ Arguments .of ("$project: {_id: 0, v: '$x..1'}" ,
642+ "Command failed with error 15998 (Location15998): 'Invalid $project :: caused by :: FieldPath field names may not be empty strings.'" ),
643+
644+ Arguments .of ("$project: 'abc'" ,
645+ "Command failed with error 15969 (Location15969): '$project specification must be an object'" )
646+ );
643647 }
644648
645- @ Test
646- void testAggregateWithProjection_IllegalFieldPath () throws Exception {
649+ @ ParameterizedTest
650+ @ MethodSource ("aggregateWithProjectionArguments" )
651+ void testAggregateWithProjection_IllegalFieldPath (String project , String expectedMessage ) throws Exception {
647652 collection .insertOne (json ("_id: 1, x: 10" ));
648653
649654 assertThatExceptionOfType (MongoCommandException .class )
650- .isThrownBy (() -> collection .aggregate (jsonList ("$project: {_id: 0, v: '$x.1.'}" )).first ())
651- .withMessageContaining ("Command failed with error 40353 (Location40353): 'Invalid $project :: caused by :: FieldPath must not end with a '.'.'" );
652-
653- assertThatExceptionOfType (MongoCommandException .class )
654- .isThrownBy (() -> collection .aggregate (jsonList ("$project: {_id: 0, v: '$x..1'}" )).first ())
655- .withMessageContaining ("Command failed with error 15998 (Location15998): 'Invalid $project :: caused by :: FieldPath field names may not be empty strings.'" );
655+ .isThrownBy (() -> collection .aggregate (jsonList (project )).first ())
656+ .withMessageStartingWith (expectedMessage );
656657 }
657658
658659 // https://github.com/bwaldvogel/mongo-java-server/pull/189
0 commit comments